Script Variable Instances/Destrution

Started by Alynn, Thu 30/10/2003 15:40:15

Previous topic - Next topic

Alynn

Out of curiosity, and before I spend hours trying to figure it out for myself...

If you have a global room variable, and you leave that room, is the script that runs that room destroyed and the variable reinitialized when the room is re-entered, or do I need to make those variables in the global script so they will not be destroyed?

Personal preference has always been to make the scope of any variable in the lowest possible block of code, but if the room object (sorry I'm mostly a java programmer) is left is that room object destroyed until the room is reentered, and so reinitializing my global room variables?

Spyros

global room variables are not destroyed.
But you can't call them from the game global script.
If you want to call it from the global script (or from other rooms ) you have to use a global int.

Alynn

#2
Quote from: Spyros on Thu 30/10/2003 16:24:53
global room variables are not destroyed.
But you can't call them from the game global script.
If you want to call it from the global script (or from other rooms ) you have to use a global int.

No.

Basicly I have a guy you have to talk to 3 times before he gives you an item, I have a room int variable that counts how many times you have talked to him (I will use the same technique for rotating messages with other characters). I just wanted to make sure I could use it as a room var int RomanTalkedTo = 0; so if the player didnt talk to him 3 times while he was in the room it would still work if he came back and talked later...

Thanks for the info...

Spyros

All character (and inventory) interactions belong to the global script. So if you raise a counter when talking to a character it's a global script counter.
You should use a Global Int , or define a global script int, at the top of the global script ( note that this way the counter will not be available in any room's interactions)

Alynn

That works for me too... Thanks

BTW I hate learning new systems... but its fun... at least this editor lets me actually CODE something I code  so much faster than I can point and click...

Pumaman

Local room scripts have their data segment saved when the room is destroyed, so all variables retain their values.

I would recommend placing variables that are only needed by one room into that room script, in order to avoid clutter in the global script.

But as Spyros says, that's not possible for Characters since their interactions are in the global script.

SMF spam blocked by CleanTalk