[Solved] ZScript global variables
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. This forum is archived - please use this set of forums to ask new questions.
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. This forum is archived - please use this set of forums to ask new questions.
-
- Lead GZDoom+Raze Developer
- Posts: 49202
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: ZScript global variables
This will need a small change to the thinker system to declare a statnum whose contents do not get deleted between maps.
-
- Posts: 8201
- Joined: Sun Jan 28, 2007 3:55 pm
- Preferred Pronouns: He/Him
- Location: QZDoom Maintenance Team
Re: ZScript global variables
That would be HIGHLY appreciated.
By the way, what are all the statnums? What do they do?
By the way, what are all the statnums? What do they do?
-
- Posts: 8201
- Joined: Sun Jan 28, 2007 3:55 pm
- Preferred Pronouns: He/Him
- Location: QZDoom Maintenance Team
Re: ZScript global variables
Is STAT_TRAVELLING strictly for hubs?
-
- Lead GZDoom+Raze Developer
- Posts: 49202
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: ZScript global variables
The statnums are for sorting, ordering and categorizing thinkers.
For example, the player must tick before its inventory, and a few other things also need to have guaranteed order, e.g. light thinkers must tick before light transfer thinkers and earthquakes before normal actors, and normal actors before anything that can alter other actors' positions, e.g. actor movers and scripts.
There's also a few special statnums for things that need to be looked for frequently.
STAT_TRAVELLING shoud be off limits to mapping. This gets used to temporarily store a player and its inventory when a map gets changed, and once the transition is complete, everything that remains in there will be cleaned out - under normal circumstances the list will be empty, and if you put in your own stuff it won't survive long.
This is also the biggest reason why there's no chance ever to make ZDoom demo compatible, because Doom never had statnums, everything got into the same list and causing all sorts of small problems with subtle effects on the gameplay and often getting into the way of frame interpolation.
For example, the player must tick before its inventory, and a few other things also need to have guaranteed order, e.g. light thinkers must tick before light transfer thinkers and earthquakes before normal actors, and normal actors before anything that can alter other actors' positions, e.g. actor movers and scripts.
There's also a few special statnums for things that need to be looked for frequently.
STAT_TRAVELLING shoud be off limits to mapping. This gets used to temporarily store a player and its inventory when a map gets changed, and once the transition is complete, everything that remains in there will be cleaned out - under normal circumstances the list will be empty, and if you put in your own stuff it won't survive long.
This is also the biggest reason why there's no chance ever to make ZDoom demo compatible, because Doom never had statnums, everything got into the same list and causing all sorts of small problems with subtle effects on the gameplay and often getting into the way of frame interpolation.
-
-
- Posts: 17478
- Joined: Mon Oct 27, 2003 12:07 am
- Location: Kuala Lumpur, Malaysia
Re: [Solved] ZScript global variables
Thank you Graf !!!!! I will shut up about global variables from now on.

To others: working example in first post viewtopic.php?f=3&t=55338#p979528



To others: working example in first post viewtopic.php?f=3&t=55338#p979528
-
- Posts: 8201
- Joined: Sun Jan 28, 2007 3:55 pm
- Preferred Pronouns: He/Him
- Location: QZDoom Maintenance Team
Re: [Solved] ZScript global variables
Graf: Should we combine STAT_STATIC with STAT_INFO or is that unnecessary?
-
- Lead GZDoom+Raze Developer
- Posts: 49202
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: [Solved] ZScript global variables
These aren't flags, these are indices which are mutually exclusive. If you combine them you get undefined behavior because the resulting statnum is not what you'd expect.
-
- Posts: 9696
- Joined: Sun Jan 04, 2004 5:37 pm
- Preferred Pronouns: They/Them
- Operating System Version (Optional): Debian Bullseye
- Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
Re: [Solved] ZScript global variables
I think this should be added to HOERS.
-
-
- Posts: 10773
- Joined: Sun Jul 20, 2003 12:15 pm
Re: [Solved] ZScript global variables
Indeed -- here's a first pass at a library version, though it's still untested (my hands are tied with other things).
-
- Posts: 5038
- Joined: Sun Nov 14, 2010 12:59 am
Re: [Solved] ZScript global variables
Sorry for the bump, but the demo file in the opening post produces errors on launch (using GZDoom 3.0):
Here is a fixed version:
Code: Select all
zscript global variables.pk3:zscript.txt, line 32: Parent class EventHandler of WorldHandler not accessible to ZScript version 2.3.0
zscript global variables.pk3:zscript.txt, line 34: Type WorldEvent not accessible to ZScript version 2.3.0
zscript global variables.pk3:zscript.txt, line 34: Invalid type Type for function parameter
zscript global variables.pk3:zscript.txt, line 34: Attempt to override non-existent virtual function WorldTick
-
-
- Posts: 17478
- Joined: Mon Oct 27, 2003 12:07 am
- Location: Kuala Lumpur, Malaysia
Re: [Solved] ZScript global variables
Ah, yeah sorry, forgot about this thread... thanks, I'll add the fixed file to the OP.
-
- Posts: 5038
- Joined: Sun Nov 14, 2010 12:59 am
Re: [Solved] ZScript global variables
I've encountered a rather serious bug with this, one that could destroy all the work that I have been doing on my mod for the past half a month or so.
With the attached file, start a new game. Fire your pistol a few times. Each time you do that, you get a message logged saying "Weapon: x", where x is the number of times you shot (this is a global variable). Now save the game and kill yourself. Load the save and check the console. You'll see two messages. The bottom one says "Weapon: 0", hinting at the fact that somehow the global variable's value got reset (or rather more accurately, the old global variable thinker is gone, so the engine is creating a new one). If you load the save a second time, the global variable thinker seems to be restored.
What's going on here?
With the attached file, start a new game. Fire your pistol a few times. Each time you do that, you get a message logged saying "Weapon: x", where x is the number of times you shot (this is a global variable). Now save the game and kill yourself. Load the save and check the console. You'll see two messages. The bottom one says "Weapon: 0", hinting at the fact that somehow the global variable's value got reset (or rather more accurately, the old global variable thinker is gone, so the engine is creating a new one). If you load the save a second time, the global variable thinker seems to be restored.
What's going on here?
You do not have the required permissions to view the files attached to this post.
-
-
- Posts: 17478
- Joined: Mon Oct 27, 2003 12:07 am
- Location: Kuala Lumpur, Malaysia
Re: [Solved] ZScript global variables
Please make a bug report. This is serious stuff.Blue Shadow wrote:I've encountered a rather serious bug with this, one that could destroy all the work that I have been doing on my mod for the past half a month or so.
With the attached file, start a new game. Fire your pistol a few times. Each time you do that, you get a message logged saying "Weapon: x", where x is the number of times you shot (this is a global variable). Now save the game and kill yourself. Load the save and check the console. You'll see two messages. The bottom one says "Weapon: 0", hinting at the fact that somehow the global variable's value got reset (or rather more accurately, the old global variable thinker is gone, so the engine is creating a new one). If you load the save a second time, the global variable thinker seems to be restored.
What's going on here?