Spawning items into game world.

Started by EzraN, August 16, 2016, 09:24:54 PM

Previous topic - Next topic

EzraN

Right now I am trying to figure out how to use C# with items for mods and have run into a problem. What I'm trying to do is create a block that will spawn in an item (steel), but it doesn't work.
Could not convert id number from thingID=Steel, numString= Exception=System.FormatException: Input string was not in the correct format
  at System.Int32.Parse (System.String s) [0x00000] in <filename unknown>:0
  at System.Convert.ToInt32 (System.String value) [0x00000] in <filename unknown>:0
  at Verse.Thing.IDNumberFromThingID (System.String thingID) [0x00000] in <filename unknown>:0

This error message will pop up so I must not be using the ThingID property correctly, has anyone used it before?

This is the code that I am using trying to spawn the item in with:

   
Thing item = new Thing();
item.ThingID = ("Steel");
                   
GenSpawn.Spawn(item, location);



RawCode

There is no Int32 that correspond to String "Steel".

Please read MSDN article about intrinsic data types of C#, you may find article in your native language with google.

EzraN

Alright so if it needs an integer instead of a string for the item's id, how/where can I find the id's of the items in the game?

RawCode

there are no comments for methods, but, EVERY method is used internally by the game, please check how game uses provided method and all your questions will be resolved.

notfood

Nonono, that's not how you create Steel.

You use GenSpawn.Spawn( ThingDefOf.Steel , an_IntVec3_location );

EzraN

Thank you, it now works! I'm still figuring a few things out so I might be asking some dumb questions, sorry.