MCPcopy Create free account
hub / github.com/JACoders/OpenJK / Cvar_Toggle_f

Function Cvar_Toggle_f

code/qcommon/cvar.cpp:855–889  ·  view source on GitHub ↗

============ Cvar_Toggle_f Toggles a cvar for easy single key binding, optionally through a list of given values ============ */

Source from the content-addressed store, hash-verified

853============
854*/
855void Cvar_Toggle_f( void ) {
856 int i, c = Cmd_Argc();
857 char *curval;
858
859 if(c < 2) {
860 Com_Printf("usage: toggle <variable> [value1, value2, ...]\n");
861 return;
862 }
863
864 if(c == 2) {
865 Cvar_Set2(Cmd_Argv(1), va("%d",
866 !Cvar_VariableValue(Cmd_Argv(1))),
867 qfalse);
868 return;
869 }
870
871 if(c == 3) {
872 Com_Printf("toggle: nothing to toggle to\n");
873 return;
874 }
875
876 curval = Cvar_VariableString(Cmd_Argv(1));
877
878 // don't bother checking the last arg for a match since the desired
879 // behaviour is the same as no match (set to the first argument)
880 for(i = 2; i + 1 < c; i++) {
881 if(strcmp(curval, Cmd_Argv(i)) == 0) {
882 Cvar_Set2(Cmd_Argv(1), Cmd_Argv(i + 1), qfalse);
883 return;
884 }
885 }
886
887 // fallback
888 Cvar_Set2(Cmd_Argv(1), Cmd_Argv(2), qfalse);
889}
890
891/*
892============

Callers

nothing calls this directly

Calls 7

Cmd_ArgcFunction · 0.70
Com_PrintfFunction · 0.70
Cvar_Set2Function · 0.70
Cmd_ArgvFunction · 0.70
vaFunction · 0.70
Cvar_VariableValueFunction · 0.70
Cvar_VariableStringFunction · 0.70

Tested by

no test coverage detected