GraphicalVariable

Started by .M.M., Mon 16/07/2007 16:23:05

Previous topic - Next topic

.M.M.

When I wrote into the script

GetGraphicalVariable ("Strenght", +1);
Display ("You learn it!");

AGS announced me error (line 243) Parse error: unexpected operator "+".
What does it mean? :-\

monkey0506

GetGraphicalVariable only takes one parameter, the name of the variable. The proper syntax would be something like:

Code: ags
if (GetGraphicalVariable("Strength") == 1) Display("You learnt it!");

Khris

And mirek, what you'll probably want:

Code: ags
  SetGraphicalVariable("Strength", GetGraphicalVariable("Strength")+1);


This will increase the variable by one.

.M.M.

Oh,thanks,I must learn how to use AGS right....
;)

Scorpiorus

Yeah, it may be a good idea to get to using the AGS scripting language, as then you can just declare a "Strength" variable in the script:

Code: ags

int strength = 10;


...and then simply do:

Code: ags

strength = strength + 1;


...or:

Code: ags

strength += 1;


...or even just:

Code: ags

strength ++;


...to increase the strength by one.

Using the graphical variables in text script makes that more unwieldy than necessary as you may see :)

Recluse

Quote from: Scorpiorus on Tue 17/07/2007 16:48:41
Yeah, it may be a good idea to get to using the AGS scripting language, as then you can just declare a "Strength" variable in the script:

Code: ags

int strength = 10;


...and then simply do:

Code: ags

strength = strength + 1;


(edited for length)

I've run into problems when I try to do the same thing. I'm trying to declare some basic booleans that will be set and accessed at the beginning of the game (in character creation) and then read later on at key points in the game. For some reason I'm having a hard time accessing these variables from room scripts (pretty much the only place they'll be used) I've got a work around set up using a Properties mod I found on the forums, but I'm wondering if there's a better way to do this that I simply don't understand because it involves an aspect of variable scope that I'm not familiar with.

Basically... if you declared these variables at the top of your global script... how would you then access the variables from room scripts?
All your verbcoin are belong to us.

Gilbert

You have to export the variable in the global script and then import it in the room script in order to access it, so:

Global Script:
Code: ags

int blah;
export blah;


Room Script (OR the script header if you want it to be accessible from every room):
Code: ags

import int blah;

Recluse

#7
Ah...

Well that's much simpler... Somehow I got the impression that when you did that it redefined the variable to null... I suppose not though...

Thanks for the tip  :D

P.S. One last question, do you need to export AFTER the variable has been set? Or will one export cause it to "live" outside the global script. Meaning its scope is outside the script yet it still needs to be imported.

Nevermind...

I've done some research... apparently you can export it right after it's declared and import it in the header file and all will be right with the world  ;D

Thanks Gilbot
All your verbcoin are belong to us.

Ashen

I know what you're thinking ... Don't think that.

SMF spam blocked by CleanTalk