Hello,
does anyone know of a way to define new variables in c# which can be defined via xml?
And if you know how to, can you please tell me?
I'm looking for a way to make ApplyDamageMin, ApplyDamageMax, ApplyDamageTicks of a Building accessable via xml, but so far I haven't found anything that works..
doesn't the "FertilizerPump" mod have the stuff u need?
Quote from: iame6162013 on April 14, 2014, 04:32:38 PM
doesn't the "FertilizerPump" mod have the stuff u need?
Nah, he's looking to make his own tags in the XML files, and read them in his code. Truth be told I've been looking to ask the same thing soon, just haven't got round to it :P
Quote from: Architect on April 14, 2014, 04:35:47 PM
Quote from: iame6162013 on April 14, 2014, 04:32:38 PM
doesn't the "FertilizerPump" mod have the stuff u need?
Nah, he's looking to make his own tags in the XML files, and read them in his code. Truth be told I've been looking to ask the same thing soon, just haven't got round to it :P
yea i'm intrested in .dll mods to just i don't know how to :)
I've tried to work this out as well, so far without luck.
Looking through decompiled code it seems that it may be hardcoded what properties get loaded from XML at the moment (there's classes which dictate the fields for the different types of objects), but I have no idea how it defines which class to use as the list of properties, so no way to mod it yet.
Actually, this is currently possible, and really rather easy. First, extend ThingDef with your extra desired properties, i.e.
public class MyThingDef : ThingDef
{
public string ExtraStuff;
}
Then just add a class="" to your xml, i.e.
<ThingDef Class="MyThingDef, MyAssembly">
Note, you need to have a fully referenced type in there, i.e. with the namespace AND the assembly name, in this example, the assembly is named MyAssembly.
Then just add the relevant tags, i.e.
<ExtraStuff>Ketchup</ExtraStuff>
and that thingdef will be of type MyThingDef with an .ExtraStuff == "Ketchup". RimWorld does a bunch of type conversion stuff, so you can easily have dictionaries, lists, enums, just look at what ThingDef already has!
Thank you Vendan.
Based on your definition I could read the variables. There was a part missing, as I got mostly NullRefExceptions but
I figured out what I did wrong: I tried to force the def to be the new class via:
public new ModNamespace.MyThingDef def;
But the result was always null.. Strange, isn't it? ;)
For everyone else, here is the complete guide how to could access your variables.
All thanks goes to Vendan, I only did a bit of clarification :)
First, make an extend ThingDef with your extra desired properties, i.e.
public class MyThingDef : ThingDef
{
public string myVariable;
}
Then just expand the ThingDef-definition with class="" in your xml, i.e.
<ThingDef Class="ModNamespace.MyThingDef, MyAssemblyFilenameWithoutExtension">
Note, you need to have a fully referenced type in there, i.e. with the namespace AND the assembly name, in this example, the assembly is named MyAssemblyFilenameWithoutExtension.
Then just add the relevant tags, i.e.
<myVariable>Ketchup</myVariable>
and that thingdef will be of type MyThingDef with an .myVariable == "Ketchup".
RimWorld does a bunch of type conversion stuff, so you can easily have dictionaries, lists, enums, just look at what ThingDef already has!
Access to the variables is only possible with a typecast:
((ModNamespace.MyThingDef)def).myVariable
yeah, I'm adding code inside MyThingDef, so I had access to it as type MyThingDef already. You should do some stuff like
if(thingdef is MyThingDef)
{
MyThingDef mydef = (MyThingDef)mydef;
//work with it here
}
to keep from having exceptions. Also, the AssemblyName isn't always the name of the dll without the extension, it's whatever is in the AssemblyName field in your project properties.
Oh, thanks for clarification. I didn't even notice the entry there. Just changed it with everything else when needed. Changing without thinking ;)
Wow, thank you for figuring this out!
Quote from: Tynan on April 15, 2014, 07:32:37 PM
Wow, thank you for figuring this out!
Oh, great, the actual developer is learning from the modding community :D You really ought to employ these people, Tynan!
Lol, hey is there a good place for us to post requests for mod writers? There's a lot of things that I could do way easier if there was just a little support added to the engine. Stuff like I've had to extend Pawn just to get a little extra data stored in the save game...
Quote from: Vendan on April 15, 2014, 08:52:19 PM
Lol, hey is there a good place for us to post requests for mod writers? There's a lot of things that I could do way easier if there was just a little support added to the engine. Stuff like I've had to extend Pawn just to get a little extra data stored in the save game...
Please do ask questions, I want to add stuff that's needed. Or maybe there's an easier way to do what you want to do.
has anyone tried this with enumeration? When I tried rimworld wouldn't launch and was throwing 'unable to cast' errors in the log.
*EDIT* that said, I now have it working.