[Solved] ZScript global variables

Archive of the old editing forum
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.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 48597
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: ZScript global variables

Post by Graf Zahl »

This will need a small change to the thinker system to declare a statnum whose contents do not get deleted between maps.
User avatar
Major Cooke
Posts: 8109
Joined: Sun Jan 28, 2007 3:55 pm

Re: ZScript global variables

Post by Major Cooke »

That would be HIGHLY appreciated.

By the way, what are all the statnums? What do they do?
User avatar
Major Cooke
Posts: 8109
Joined: Sun Jan 28, 2007 3:55 pm

Re: ZScript global variables

Post by Major Cooke »

Is STAT_TRAVELLING strictly for hubs?
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 48597
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: ZScript global variables

Post by Graf Zahl »

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.
User avatar
Nash
 
 
Posts: 17358
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia

Re: [Solved] ZScript global variables

Post by Nash »

Thank you Graf !!!!! I will shut up about global variables from now on. :mrgreen: :mrgreen: :mrgreen:

To others: working example in first post viewtopic.php?f=3&t=55338#p979528
User avatar
Major Cooke
Posts: 8109
Joined: Sun Jan 28, 2007 3:55 pm

Re: [Solved] ZScript global variables

Post by Major Cooke »

Graf: Should we combine STAT_STATIC with STAT_INFO or is that unnecessary?
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 48597
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: [Solved] ZScript global variables

Post by Graf Zahl »

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.
User avatar
Matt
Posts: 9693
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

Post by Matt »

I think this should be added to HOERS.
User avatar
Xaser
 
 
Posts: 10771
Joined: Sun Jul 20, 2003 12:15 pm

Re: [Solved] ZScript global variables

Post by Xaser »

Indeed -- here's a first pass at a library version, though it's still untested (my hands are tied with other things).
Blue Shadow
Posts: 4929
Joined: Sun Nov 14, 2010 12:59 am
Graphics Processor: ATI/AMD (Modern GZDoom)

Re: [Solved] ZScript global variables

Post by Blue Shadow »

Sorry for the bump, but the demo file in the opening post produces errors on launch (using GZDoom 3.0):

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
Here is a fixed version:
zscript global variables.pk3
User avatar
Nash
 
 
Posts: 17358
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia

Re: [Solved] ZScript global variables

Post by Nash »

Ah, yeah sorry, forgot about this thread... thanks, I'll add the fixed file to the OP.
Blue Shadow
Posts: 4929
Joined: Sun Nov 14, 2010 12:59 am
Graphics Processor: ATI/AMD (Modern GZDoom)

Re: [Solved] ZScript global variables

Post by Blue Shadow »

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?
gvar_test.pk3
You do not have the required permissions to view the files attached to this post.
User avatar
Nash
 
 
Posts: 17358
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia

Re: [Solved] ZScript global variables

Post by Nash »

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?
gvar_test.pk3
Please make a bug report. This is serious stuff.

Return to “Editing (Archive)”