[QUOTE=C;191222]i used a CVAR before in some mapscript, and it worked perfectly…
But, i must say that, it was a custom CVAR,… i just made one up because i needed one value stored…
It could be different than a regular ET CVAR… i do not know. i take Your word for it.
And if it would be so, that one can only “inc” a CVAR, then inc “-1” could possibly also work, and a toggle-function can still be made…
Test it, and You know it.[/QUOTE]
Here’s the problem code in g_script_actions.c (2.55 and 2.60) with respect to “inc” (with my comments added in CAPS)
/*
===================
G_ScriptAction_Cvar
syntax: cvar <cvarName> <operation> <value>
===================
*/
[B]//FUNCTION IS CALLED AFTER A CALLING ROUTINE SEES THE WORD "cvar"[/B]
qboolean G_ScriptAction_Cvar( gentity_t *ent, char *params )
{
char *pString, *token, lastToken[MAX_QPATH], name[MAX_QPATH], cvarName[MAX_QPATH];
int cvarValue;
qboolean terminate, found;
pString = params;
[B]//CODE STARTS HERE...[/B]
[B]//CHECK FIRST WORD AFTER "cvar" i.e get name of cvar[/B]
token = COM_ParseExt( &pString, qfalse );
if (!token[0]) {
G_Error( "G_Scripting: cvar without a cvar name
" );
}
Q_strncpyz( cvarName, token, sizeof( cvarName ) );
[B]//GET VALUE OF SPECIFIED PREEXISTING CVAR, or get 0 otherwise[/B]
cvarValue = trap_Cvar_VariableIntegerValue( cvarName );
[B]//CHECK FOR SECOND WORD AFTER "cvar" i.e. the command <operation>[/B]
token = COM_ParseExt( &pString, qfalse );
if (!token[0]) {
G_Error( "G_Scripting: cvar without a command
" );
}
Q_strncpyz( lastToken, token, sizeof(lastToken) );
[B]//AND GET THE VALUE AND PUT IT IN token[/B]
token = COM_ParseExt( &pString, qfalse );
[B]//AND IF THE COMMAND IS TO INCREMENT i.e. "inc"[/B]
if (!Q_stricmp(lastToken, "inc")) {
if (!token[0]) {
G_Error( "G_Scripting: cvar %s requires a parameter
", lastToken );
}
[B]//HERE IS THE BUG FOR "inc"[/B]
trap_Cvar_Set( cvarName, va("%i", [B]cvarValue+1[/B]) );
}
[B]//CODE CONTINUES FOR OTHER COMMANDS...[/B]
So the problem code is cvarValue+1 instead of adding the numeric value of token to cvarValue. Basically it always adds 1 ignoring the value specified.
The same function fails to use the trap_Cvar_set call for set, bitset and bitreset so it does not change the specified cvar for those commands. As I said this bug is well know so at least one of the major mods includes a fix for it.