Code: Select all
if(getcvar("<cvar>") == "")
setcvar("<cvar>", "<default>");
"If cvar <cvar> is equal to nothing (if it doesn't exist)...
...create cvar with default value"
Thats the bare basics.
Next you can create minimum and maximum values (if the cvar is numeric...
Code: Select all
if(getCvar("<cvar>") == "")
setCvar("<cvar>", "<default>");
else if(getCvarInt("<cvar>") > 10)
setCvar("<cvar>", 10);
else if(getCvarInt("<cvar>") < 0)
setCvar("<cvar>", 0);
...else, if the cvar is greater than 10, set the cvar to 10, or
...if the cvar is less than 0, set it to 0.
Make sure you get you note the usage of getCvar and getCvarInt (also, you can use getCvarFloat, to retrieve decimal values).
And finally, using the cvar in your script...
Now, there are many ways to use the cvar, but the main way is to use it as a variable...
Code: Select all
if(getCvar("<cvar>") == "")
setCvar("<cvar>", "<default>");
else if(getCvarInt("<cvar>") > 10)
setCvar("<cvar>", 10);
else if(getCvarInt("<cvar>") < 0)
setCvar("<cvar>", 0);
<variable> = getCvarInt("<cvar>");
getCvar for TEXT based cvars (example: getCvar("g_gametype"); )
getCvarInt for INTEGERS (whole number, example: getCvarInt("scr_forcerespawn"); )
getCvarInt for FLOATS (decimals, example: getCvarFloat("scr_hq_timelimit"); )
Another good use, is to use the cvar as a wait command...
For example,
Code: Select all
main()
{
while(getCvar("wait") != 0)
{
wait 1;
}
iprintln("Wait cvar is equal to 0");
}
Now you know cvars
