The RPG Maker Resource Kit

RMRK RPG Maker Creation => RPG Maker General => General Scripting => Topic started by: Tenraah on July 27, 2010, 07:12:21 PM

Title: RMXP Add Item by ID determined by Variable
Post by: Tenraah on July 27, 2010, 07:12:21 PM
I'm trying to add a little cheat system in a game I'm making.  What I'm having trouble with at the moment is an event that lets me add an item to the inventory by ID.  So far I've got an event that sets variable id 0152 with button input processing, then I was going to use a script to add the specified item.  I'm not so good at scripting so I just guessed this by looking at other scripts...
$game_party.gain_item ($game_variable[152], 1)
Anyone know what I'd have to change to make this work?  It works if I specify an item id, but how can I make it work to use the variable as the item id?
Title: Re: RMXP Add Item by ID determined by Variable
Post by: cozziekuns on July 27, 2010, 08:29:04 PM

var = $game_variables[152]
$game_party.gain_item(var, 1)


Should work. Just put it in a call script. Also, remember that it's $game_party.gain_weapon for weapons and $game_party.gain_armor for armours.
Title: Re: RMXP Add Item by ID determined by Variable
Post by: Tenraah on July 27, 2010, 09:33:55 PM
Copied that letter for letter, tried it with item id 001, gave an error message "NoMethodError occurred while running script.  undefined method '[]' for nil:NilClass"
:(
Title: Re: RMXP Add Item by ID determined by Variable
Post by: cozziekuns on July 27, 2010, 09:37:17 PM
That's weird. Did you remember to put an s after $game_variable? So it was $game_variables?
Otherwise, it might be something wrong with your RPG Maker XP.
Title: Re: RMXP Add Item by ID determined by Variable
Post by: Tenraah on July 27, 2010, 09:46:46 PM
No, of course I didn't remember to put the s.  -.-

Thanks a lot for the help, it's working now!  You saved me from having to make a conditional branch for every single item...  heh.