Forum

Global variables - how?

Discuss programming in the QuakeC language.

Moderator: InsideQC Admins

Global variables - how?

Postby Nash » Sun Nov 11, 2007 11:10 pm

How do I create floats or custom fields that do not get reset when the map changes?

I want to do something like, a secret triggered from the previous map can only be seen on the next map. Stuff like that.

No, I don't want to use the dummy cvars because I don't want players to freely set the cvar.

I think it's possible because the player items are saved for the next map but I don't understand how it works.

Thanks in advance.
User avatar
Nash
 
Posts: 95
Joined: Fri Oct 19, 2007 5:56 pm
Location: Kuala Lumpur, Malaysia

Postby daemon » Sun Nov 11, 2007 11:50 pm

The way the player items and stats are saved is by setting the player's parms to those values, and each player's parms are carried over through map changes, then loaded back into the variables once the map is loaded.

So, if you wanted to use parms to carry over global values, you could probably use spawnclient() to create a fake client and use it's parm values to hold the global values you want to save.

OR

You could use FRIK_FILE to save those values to a file before the map change, and then load them back into the global variables on the next map start.

I would probably use the FRIK_FILE method if I didn't want to use up a player slot, and/or I had a LOT of global variables I wanted to carry though level changes.

You could ALSO use the serverflags variable to store values like parms, but that is already used by many things in Quake, and since there is only one of them, you are limited as to how much and what kind of information you can store in it. If all you want to save is true/false flags, then serverflags might be what you want.
-daemon [ daemonforge.org ]
User avatar
daemon
 
Posts: 63
Joined: Wed Nov 07, 2007 11:10 pm

Postby Sajt » Mon Nov 12, 2007 4:44 am

What is serverflags all used by? I think the first four 'bits' were used for runes, but is the rest of it ever used? If not, you have 20-ish bits you can use for global boolean flags...
F. A. Špork, an enlightened nobleman and a great patron of art, had a stately Baroque spa complex built on the banks of the River Labe.
Sajt
 
Posts: 1215
Joined: Sat Oct 16, 2004 3:39 am

Postby daemon » Mon Nov 12, 2007 10:19 am

It looks like just the first 4 were used, but impulse11 also does this by default:

serverflags = serverflags * 2 + 1;
-daemon [ daemonforge.org ]
User avatar
daemon
 
Posts: 63
Joined: Wed Nov 07, 2007 11:10 pm

Postby Sajt » Mon Nov 12, 2007 12:59 pm

Hehe yeah, you might want to change that one so it doesn't touch beyond the first four bits...
F. A. Špork, an enlightened nobleman and a great patron of art, had a stately Baroque spa complex built on the banks of the River Labe.
Sajt
 
Posts: 1215
Joined: Sat Oct 16, 2004 3:39 am

Postby Nash » Mon Nov 12, 2007 2:20 pm

FRIK_FILE seems to be the most elegant solution. Thanks daemon!
User avatar
Nash
 
Posts: 95
Joined: Fri Oct 19, 2007 5:56 pm
Location: Kuala Lumpur, Malaysia

Postby Spike » Mon Nov 12, 2007 7:46 pm

I recommend that you still use one of the bits in serverflags to signify the presence of data from the previous map. Failure to do so might otherwise result in awkwardness when starting a new game. Just one flag.

yeah, only four bits of serverflags are normally used. and impulse 11 is a cheat. :P
Spike
 
Posts: 2892
Joined: Fri Nov 05, 2004 3:12 am
Location: UK


Return to QuakeC Programming

Who is online

Users browsing this forum: No registered users and 1 guest