Main Menu
  • Welcome to The RPG Maker Resource Kit.

Using an in game variable in a script

Started by IXFURU, September 19, 2010, 02:20:06 AM

0 Members and 1 Guest are viewing this topic.

IXFURU

I am using Deriru's/Dairu's Simple Item Storage in order to create a second option, "Vault system", at a bank.  Here's how it works.

You approach the counter and the lady greets you, asking what you wish to do.  Either 1)take out a loan, 2)use vault system or 3)hear banking explanation.   If you choose two, she will then ask you how would you like to use the vault system.  Either place or remove items from vault, or you can choose to purchase more storage space.  If you choose to purchase more space, she then explains to you how much each space will cost depending upon your bank rating which is stored in a variable. (the higher it is, the less the spaces cost).  Then she asks you how many spaces you wish to purchase.   Immediately, the "number input" opens with two digits and is linked to a variable we'll call "X".  Once the number is entered, X becomes that number, and if you can afford it and there are a still that many spaces available (the max is 30) the bank lady grants your request and you are given X amount of extra storage spaces.

That sounds like it would be simple.  And really, it should be.  I have the formula all worked out.  However, I can't get the "Simple Item Storage" script to wok properly. 

There is a call script command for adding new storage space.   This command basically just opens the TOTAL amount of spaces that will be available.  In other words, you can't just say add X amount of spaces.  Instead, you have to add the X with the amount of spaces open before the transaction (a variable we'll call "Y") to get the new total amount (which we'll call "Z").   Then we have to place that number into the command:

$game_system.unlock_storages(amount)

So, the script is asking for an integar in the "amount" position.  Something I can't really give, because in my project, that integar can be a number of different values.  For example, if I have 7 currently available (y=7), and I purchase 4 (x=4), then that makes z=11, which will not always be the case.

Earlier today I tried this:
Quote$game_system.unlock_storages($game_variable(74))

But that didn't work.  It returned an argument error.  0 for 1, or something to that effect.  I'm really just unsure as to how to use the correct syntax when calling variables with a script.  Was the way I wrote it correct?  Maybe not.

If someone could help, I'd greatly appreciate it.

cozziekuns

#1
You were on the right track. Just change the $game_variable(74) parenthesis to brackets [].

EDIT: Lol yeah, it's $game_variables.

modern algebra

and $game_variables, not $game_variable. But yeah, use square brackets as cozziekuns says.

IXFURU

Thanks for the help guys.

But it didn't work.

I'm wondering, if the script hasn't got the $game_variables included in the system itself, would that make it so it doesn't recognize the variable when used in place of an integer?  Like, I know there's differences between global, local and other type variables.  And I often see, (though I don't understand completely), how some folks begin their scripts by listing all the variables and classes and stuff that will be used in their script.  I don't know if that's the case here.  But I may just have to resort back to allowing the player to only buying 1 space at a time, or 3 spaces at a time.  That way, at least, the integer I add to the call script will be a constant one.

That sucks, though.  I hate compromising with the system.  I like to see my ideas fulfilled.


By the way, it works well with a simple integer.  I've tested it.

cozziekuns

Well, it should work, unless there's a problem with the script. Are you sure your putting $game_system.unlock_storages($game_variables[74]) in the call command?

IXFURU

Just double-checked it, cozziekuns, and that is affirmative.

$game_system.unlock_storages($game_variables[74])

That's a direct copy/paste.

However, it doesn't show up on one line in the script call.

cozziekuns

Oh, then just do:


a = $game_variables[74]
$game_system.unlock_storages(a)


IXFURU

So, it DOES have to fit on one line?

Cool. . .It works great, Cozziekuns.  Thanks for all the help.

This issue is resolved