Some bits logic for variables
viader
Member, Translator (NDA) Posts: 875
In IE we can use variables with nice range from 0 to 2^32-1, but most mod doesn't need this range, because we often need these variables only to store some events like: kill or not kill, dead or not dead, talk or not talk these all variables contain value 0 or 1, something happen or something doesn't happen. I request to one new action and one new tigger, which allow to save and read from variable 32 events. It allow to cut 1/3 variables from my mod.
Action:
SetGlobalBit("VARIABLE","GLOBAL",x) - this action should set x bit in value of VARIABLE.
Trigger:
GlobalBit("VARIABLE","GLOBAL",x) - this trigger return 1 if x bit is set in value of VARIABLE, if not then return 0
Action:
SetGlobalBit("VARIABLE","GLOBAL",x) - this action should set x bit in value of VARIABLE.
Trigger:
GlobalBit("VARIABLE","GLOBAL",x) - this trigger return 1 if x bit is set in value of VARIABLE, if not then return 0
0
Comments
variable - Kex_Talk = 1,1,0,1,0,1,0,0,...,0
Only I know what these numbers meant, but in WEIDU .tp2 I can add comment to .baf file - which describe using variable, else I must to each dialog options create new variables - which are using only to set one or zero. In some cases, using the same name for several variables is a good idea.
Kex_Talk_Subject_1, Kex_Talk_Subject_2, Kex_Talk_Subject_3, Kex_Talk_Subject_4, Kex_Talk_Subject_5, Kex_Talk_Subject_6...
We have limit to save variables in .sav file, so maximalize operations on variables would be logic. With orginal game, count of variables isn't problem, but if I install combinations of megamods, or just >10 medium mods, it becomes really problem... There is second way, add boolean variables, but I suppose that it would be hard to do.
If I use wrong script action or I use correct action in wrong way I can make some hard-to-find bugs... I don't know why you think, that new action could lead to bugs?
About the hard-to-find bugs: Let's say you do the following.
SetGlobal("A", "GLOBAL", 10)
SetGlobalBit("A", "GLOBAL", 6)
Global("A", "GLOBAL", 2548)
The row above will return 74
Perhaps a better option may be to increase the .sav global var limit in EE if it is an issue? I don't know how difficult that would be, though.
Also, the SetGlobalBit(var, "GLOBAL", bit) should maybe be accompanied by UnsetGlobalBit(var, "GLOBAL", bit), or perhaps SetGlobalBit(var, "GLOBAL", bit, bool) Where bool is false/true or 0/1.
Global("A", "GLOBAL", 2548) - it can return only true or false
SetGlobal("A", "GLOBAL", 10)
SetGlobalBit("A", "GLOBAL", 6)
Global("A", "GLOBAL", 2548) = false (because A!=2548)
Global("A", "GLOBAL", 74) = true (because A==74)
Ofc, If new action would be implement.
Sorry about that, the last row I wrote shouldn't end with 2548. It was just a typo.
I only meant Global("A", "GLOBAL"), which in that case returns 74 due to variable type mixing. If that is how global variables are used in scripts.
There would be no way of maintaining variable type (bool or int), though, as that would require a change of file format as well.
Also, the last sentence I wrote displays weird, since I used illegal symbols. I've corrected it.
UnsetGlobalBit(var, "GLOBAL", bit) - this is good idea, I forgot about clear bits.