Beginner Question on Global Variables

Started by , Wed 25/10/2006 01:16:13

Previous topic - Next topic

SisteenStone

I am trying to set a global veriable to count the amount of cash in an inventory. At the top of my Global script I put 'int AmountOfMoney=5;' amount of money is  my variable name and the default value is 5. Is this correct?

I want to call a global message that says something like "You have $5 Cash"

So I put under message 500: "You have $" && GetGlobalInt (int AmountOfMoney)  && " Cash"

But this doesn't seem to work...
What am I doing wrong?

Thank you!

Ashen

#1
You seem to be mixing up Scripting syntax, with non-Script parts of AGS.

If you're using GlobalInts, you'd use something like:
Code: ags
Display("You have $%d Cash", GetGlobalInt(1));


If you're using a custom scripting int (i.e int AmountOfMoney) you'd use:
Code: ags
Display("You have $%d Cash", AmountOfMoney);


Possibly, you could use the @GI@ token to display a GlobalInt amount in a Global Message (i.e. message 500, which you mentioned in your original post: "You have $@GI1@ Cash")

However using 'Run Script', and learning to script is probably the best route.
I know what you're thinking ... Don't think that.

SisteenStone

Okay so I kept The code from the beginning of my global script:

// main global script file
int AmountOfMoney=5;

And placed the following in Global message 500

Display("You have $%d Cash", AmountOfMoney);

But is displays all of it. Instad of just "You have $5 Cash", it displays "Display("You have $%d Cash", AmountOfMoney);"

Am I missing something...?

Ashen

#3
Again, it looks like you've gotten confused between Scripting language and non-scripting language.

I'm not sure if you can actually use Scripting variables (like ' AmountOfMoney'), in GlobalMessages, so you might have to go back to GlobalInts.  You EITHER need to set message 500 to "You have $@GI1@ Cash" (not sure if this'll work - and make sure you reference the right GlobalInt), OR use a 'Run script' command, set to Display("You have $%d Cash", AmountOfMoney); (you could still use GlobalInts if you use scripting - see my first post).
I know what you're thinking ... Don't think that.

SMF spam blocked by CleanTalk