Just to clear thing up for me.
On map 01, I declare a global int. It is initialised as 0. If the player carries out certain actions, the variable is changed, and it can have an influence on what happens on map03.
Maps 01, 02 and 03 are in a hub. The player starts on map01.
The player can get to map03 directly from map01, or via map02 (and go back and forth multiple times if they wish).
Like I said, the variable may be changed on map01, and will be read by a script on map03.
So, I was wondering, am I supposed to declare the global variable on each of the three maps, or is declaring it on map01 alone enough?
I was told, many, many years ago to declare it on all the maps where it might be used, but I forgot to declare it for map02 by accident.
However, the reason that I am asking is that when I went from map01, to map02 and then to map03, the variable was readable at the value set on map01 when I got to map03, even though I got there by passing through map02 which did not have the variable declared in its scripts lump. So, I guess it truly was global - the value was maintained when passing through a map that had no knowledge of it.
So, the question is, am I supposed to declare the variable on each map, or is map01 enough?
Perhaps it is good practice to always declare it?
Or is there some sort of half-way situation where I can declare it once, and it will be remembered across the maps, but if any scripts need to access it/change it on a different map, then it needs to be declared for that map too?
Quick question on global variables.
Moderator: GZDoom Developers
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.
Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.
Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
-
-
- Posts: 26879
- Joined: Tue Jul 15, 2003 4:58 pm
- Location: Scotland
-
-
- Posts: 1707
- Joined: Wed May 13, 2009 3:15 am
- Graphics Processor: nVidia with Vulkan support
Re: Quick question on global variables.
Well, obviously, if you do not declare a global variable in a certain map script, that variable isn't going to magically disappear. Since what you are doing is essentially just creating a human-readable alias for a specific index into the ACS global variables array.
However, it might be beneficial to declare global variables even in those scripts where you don't actually use them, to avoid potential bugs - this way, you can be sure you won't accidentally use a global variable index that has already been reserved for something else.
However, it might be beneficial to declare global variables even in those scripts where you don't actually use them, to avoid potential bugs - this way, you can be sure you won't accidentally use a global variable index that has already been reserved for something else.
-
-
- Posts: 26879
- Joined: Tue Jul 15, 2003 4:58 pm
- Location: Scotland
Re: Quick question on global variables.
Ah, of course, yes. The name is actually irrelevant isn't it. The index is what the game knows about.
So, basically good practice to use it on all maps to avoid me accidentally using the index for something else, but not strictly required? I do tend to use it on all maps anyway. It was just that I forgot that one time and was intrigued as to why it hadn't made any difference to how the game behaved.
Similar to what I thought. Thanks.
So, basically good practice to use it on all maps to avoid me accidentally using the index for something else, but not strictly required? I do tend to use it on all maps anyway. It was just that I forgot that one time and was intrigued as to why it hadn't made any difference to how the game behaved.
Similar to what I thought. Thanks.
