Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Nickydude on Sun 04/01/2009 23:18:51

Title: What am I doing wrong? (variables and dialogue)
Post by: Nickydude on Sun 04/01/2009 23:18:51
In the GlobalScrips.asc I placed the following variable in game_start (): int metbillgates; and in a dialogue I have:

  if (metbillgates == 0)
  {
GuyBrush: Hi
BillGates: Hello.
  metbillgates = 1;
  }
  else
  {
GuyBrush: Hi, it's me again
BillGates: Hello again.
  }


Basically I want to say something different if I've talked to the guy before. But I keep getting "Dialog 0(4): Error (line 4): undefined symbol 'metbillgates'".

What's the obvious (to you guys) thing I'm missing here?  :-\
Title: Re: What am I doing wrong? (variables and dialogue)
Post by: on Sun 04/01/2009 23:36:26
The "obvious" thing is that your dialog cannot acess the int because it is "valid" only in the global script.
Since you're using the lastest AGS, you can simply create it as a "global int" and have acess to it from all other scripts, including dialogs (before that, we had to do a lot of fiddly stuff that was, well, fiddly).
Hit the Global Variables pane, create the variable there, and you should be fine ;)
Title: Re: What am I doing wrong? (variables and dialogue)
Post by: Nickydude on Sun 04/01/2009 23:42:58
I thought putting a variable in the GlobalScript would make it global.

QuoteHit the Global Variables pane, create the variable there, and you should be fine.
That worked perfectly, thanks again for your help Ghost. (http://www.comicguide.net/images/smilies/smilie_prost.gif)
Title: Re: What am I doing wrong? (variables and dialogue)
Post by: Matti on Mon 05/01/2009 00:24:49
Wow. That smiley's beer gets refilled just when it's half-way through. Very practical..   :D
Title: Re: What am I doing wrong? (variables and dialogue)
Post by: Trent R on Mon 05/01/2009 04:17:43
Well, to have variables in global script be available globally, you need to put an export statement somewhere after it is declared (some like it on the next line, some like them all at the end).

Also, you said you put it in game_start(), in which case it's be out of scope and give you the same (or similar) error if you tried to use it anywhere else other than inside the game_start() function.



~Trent
Title: Re: What am I doing wrong? (variables and dialogue)
Post by: Khris on Mon 05/01/2009 04:50:54
Exactly, game_start is used to set/change existing global variables or call functions that need to run before anything else; declaring global variables is supposed to be done outside any function.
Title: Re: What am I doing wrong? (variables and dialogue)
Post by: Nickydude on Mon 05/01/2009 12:38:28
Thanks guys.
Title: Re: What am I doing wrong? (variables and dialogue)
Post by: Dualnames on Mon 05/01/2009 18:39:55
If a variable is defined inside a function it will only be useful in that function.