Hello everyone!
I'm making a game which has a float called 'health' but I've got a problem really difficult to explain.
Let's see:
//Script header
float health= 100.00;
//In global script, at repatedly execute
lblhealth.Text=String.Format("Health=%.0f",health);
This code doesnt work very well, because if I call a function like this in the globel script:
//E.g.:At dialog request
health=health+10.00;
It works, but if I call it from room repeatedly executed. E.g.:
//script for Room: Repeatedly execute
//At attack time
health=health- 10.00;
This one isnt shown in the 'lblhealth'.
Hope you understand.
Thankyou.
Dunno if it's related, but you should never initialize a variable in the script header
Put this at the top of your global script:
float health= 100.00;
export health;
And then, in script header, replace what you had with:
import float health;
See if that helps.
Yeah, thanks a lot, it works perfectly.
I had tried that before, but i had fogotten 'export health;'
Thanks again.
Seems to be the same problem then:
Quote from: strazer on Tue 29/08/2006 15:35:58If you define variables in the script header, separate variables are created for the global script and each room script. Changing the variable's value from within a room script thus doesn't affect any of the others.
To create a global variable that you can use outside the global script, you have to define it in the global script, export it and then import it into the script header:
// global script
int catStat;
export catStat;
// main script header
import int catStat;
Hmm...perhaps (and I don't know if this is even reasonable), but maybe AGS could generate a warning if you try to compile with variables defined in script headers that a new copy will be created for each room?
It just seems that this causes a lot of confusion.
Oh, I can't think of an instance where variables defined in script headers might be useful... but it might. Hey, you never know.
Yes, but some kind of warning wouldn't be amiss.