Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: on Sat 15/05/2004 19:26:02

Title: Trouble With Global Variables
Post by: on Sat 15/05/2004 19:26:02
Hi. I'm trying to make a script that will basically keep track of my character's cash. For example, I want to have my character but a magazine. So, if he has the cash needed for it, He'll walk to the register and pay, then addthat magazine to his inventory. However, If he doesn'tr have enough money, He'll say, "I don't have enough money." I have everything there figured out, exept how to tell the computer how much money he has. My idea is a variable which I will increase by however much cash he recieves, and cash being his points with a coin symbol by them. But, alas, I am a newbie and do not know enough about text scripting to set this variable. Could somebody help me out?
Title: Re: Trouble With Global Variables
Post by: .. on Sat 15/05/2004 19:48:16
Well declare your money variable somewhere near the top of global script like

money = 30;

(Player starts with 30 coins)

Then when the player recieves more money, for example by picking up a coin

money += 1;

(Adds one coin)

(BTW so far this is all in the begginers script tutorial)

Then in your dialog script when the player asks for the item

run-script 1

Then add the script in dialog request... I'm sure someone else can help you do that but I have to go...
Title: Re: Trouble With Global Variables
Post by: TerranRich on Sun 16/05/2004 00:38:13
Check out the BFAQ regarding the use of variables HERE (http://www.rain-day.com/harbinger/faq/index.html#coding01).

Then, as Scuthbert recommended, use variable += 1; or variable++; to increment by one. Following the BFAQ information strictly, you can access the variable anywhere in the game, so just check the value of the variable whenever you need it.
Title: Re: Trouble With Global Variables
Post by: on Sun 16/05/2004 01:27:39
You see, I probably would've figured all that out, but I'm not sure of how to access the global script. That's all I need to know.
Title: Re: Trouble With Global Variables
Post by: Scorpiorus on Sun 16/05/2004 01:40:03
Main menu > Script > Edit global script... or simply Ctrl-G :)
Title: Re: Trouble With Global Variables
Post by: on Sun 16/05/2004 01:58:19
YAY! It works! Thanks a bunch, guys.