• If you have a mod, tool or prefab, please use the Resources section. Click Mods at the top of the forums.

please explain the difference between variables

myav

New member
In the game code, I see symbols at the beginning of variable names. Are they just visual? Or these symbols mean something?

example ($ . _ and normal):
 

<triggered_effect trigger="onSelfBuffUpdate" action="ModifyCVar" cvar="$test" operation="set" value="2"/>
<triggered_effect trigger="onSelfBuffUpdate" action="ModifyCVar" cvar=".test" operation="set" value="2"/>
<triggered_effect trigger="onSelfBuffUpdate" action="ModifyCVar" cvar="_test" operation="set" value="2"/>
<triggered_effect trigger="onSelfBuffUpdate" action="ModifyCVar" cvar="test" operation="set" value="2"/>



Do these symbols ($ . _ ) have any meaning other than visual?

 
Have a look in buff.xml - towards the end of the file, about line 13000, look for the text: "### OPERATIONS AND CVARS, game variables"

There are some comments there that explain a little about what each does.

In short:

 - vars that start with an underscore are Read Only and are system variables

- vars that start with $ are not networked (this is important to know if you are coding xml for dedicated servers)

- vars that start with '.' are local. Though I only ever use those vars for visual screen output (like the countdown of a buff in the lower left corner of the screen) so may be someone can confirm that.

Cheers

 
JoeSloeMoe, thanks!

But can someone explain more about "non-network" variables?

if mod is server-side and example:

the first player will eat food that heals for $variable, or a zombie will hit the first player, dealing increased damage of $variable. Will the second player see the correct health of the first player after these actions or not?

I saw mods, where authors have used $variables and in the description of the mods was written - server side.

So, someone please explain to me the use of non-network variables in server-side mods. In what situations are they better to use than regular ones? And in which situations it is better not to use them (if the mod is server side).

 
Last edited by a moderator:
For non-networked the code comments say:

"Cvars that start with "$" are NOT networked.
You can use them locally and for math operations but they cannot be accessed between different entities.
"

The above doesn't necessarily refer to single player or multiplayer (& server or client side mods), its referring to different entities that are in the game. This includes zombies, vehicles and anything listed in entities.xml.

For example I cant do the following:

- add a buff to the player that tracks a $zombieCurse cvar, when it is 1, a zombie has cursed you and something bad happens (doesnt matter what for this example)

- add code to the Zombie entity that when they get hit they then set the $zombieCurse  of the player that hit them to 1

 <triggered_effect trigger="onOtherDamagedSelf" action="ModifyCVar" cvar="$zombieCurse" operation="set" value="1" target="other"/>

The above is an example of one entity trying to modify a cvar in another entity

I also cant do the reverse:

- if have a variable in the zombie $testValue

- push back on the player when hit:

<triggered_effect trigger="onOtherDamagedSelf" action="ModifyCVar" cvar="something" operation="set" value="@$testValue" target="other"/>

When the player's code tries to modify the local 'something' variable it has to dereference the $testValue (the @) and the cvar is not networked across the entities (player, zombie) so it cant.

Not sure if that clarifies it for you, this is my understanding, am open to anyone else commenting.

The reason I mentioned it was important to be aware of for dedicated server coding is because in singleplayer there is only one player. e.g. the game always knows who owns a turret that's sitting on the ground (and who to give xp to) because it could only possibly one player, so adding code to a turret may need to take that into account.

Edit just to add,  "NOT networked" - In programming terms Networked might be similar to Scope, where an Entity is an Object and the $cvar is a Protected property of the Object (Entity).

cheers

 
Last edited by a moderator:
Back
Top