BullyWiiPlaza
Modder
- Messages
- 215
- Reaction score
- 174
- Points
- 818
Caution:
The scripts below are untested.
I thought about making dvar toggles easier and this is what I got. Structs are very underrated and should be used more since they are very useful in reducing redundancy in the code. As you can see, there is zero redundancy now so the code is clean:
This also automatically turns off the dvar but is not necessary for this to work properly since the starting boolean state is always determined according to the actual dvar value and not some predetermined true or false which could be wrong.
Note:
You can grab the invertAndPrint() function here.
The scripts below are untested.
I thought about making dvar toggles easier and this is what I got. Structs are very underrated and should be used more since they are very useful in reducing redundancy in the code. As you can see, there is zero redundancy now so the code is clean:
Code:
toggleSuperMeleeRange()
{
if(!isDefined(level.superMeleeRange))
{
level.superMeleeRange = createDvarStructure("player_meleeRange", 9999, 1);
}
self toggleDvarStructure("Super Melee Range", level.superMeleeRange, true);
}
Code:
createDvarStructure(name, enabled, disabled)
{
structure = spawnStruct();
structure.name = name;
structure.enabled = enabled;
structure.disabled = disabled;
structure.state = getDvarInt(name) == enabled;
level thread disableDvarStructureWhenGameEnded(structure);
return structure;
}
disableDvarStructureWhenGameEnded(structure)
{
level waitTill("game_ended");
setDvar(structure.name, structure.disabled);
}
toggleDvarStructure(modName, structure, printGlobally)
{
structure.state = self invertAndPrint(modName, structure.state, printGlobally);
setDvarStructureValue(structure);
}
setDvarStructureValue(structure)
{
value = structure.state ? structure.enabled : structure.disabled;
setDvar(structure.name, value);
}
Note:
You can grab the invertAndPrint() function here.
Last edited: