Skip to content

Some bits logic for variables

viaderviader 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

Comments

  • barbarabarbara Member Posts: 30
    How many variables are you using? Using bit fields to store boolean logic is only common when memory needs to be saved, since bit manipulation is more expensive computionally than byte and word manipulation. Using the same name for several variables is probably not a good idea, since confusion probably can occur. Also, if SetGlobalBit is used by mistake on any global variable that isn't used normally with SetGlobalBit, it could lead to some hard-to-find bugs.
  • viaderviader Member, Translator (NDA) Posts: 875
    edited October 2013
    @barbara Now, it would be many variables... On example, variable using to detect which dialog was spoken with my NPC - Kex could look like it

    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?
  • barbarabarbara Member Posts: 30
    edited October 2013
    I'm not familiar with Infinity Engine modding, so correct me if I'm wrong below.

    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.
    Post edited by barbara on
  • viaderviader Member, Translator (NDA) Posts: 875
    edited October 2013
    @barbara Increase the .sav global var limit should be difficult - http://gemrb.org/iesdp/file_formats/ie_formats/gam_v2.0.htm

    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.
  • barbarabarbara Member Posts: 30
    @viader
    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.
  • viaderviader Member, Translator (NDA) Posts: 875
    edited October 2013
    @barbara something like this "Global("A", "GLOBAL")" doesn't exist. There isn't way to get from variable value (almost), only you can compare values, or set, increase, dicrease, value of variable...

    UnsetGlobalBit(var, "GLOBAL", bit) - this is good idea, I forgot about clear bits.
Sign In or Register to comment.