# The best way to economize Vars (Bit-flag) (Read 11870 times)

Started by Dr.Chapatín, November 02, 2014, 05:06:48 pm

#### Dr.Chapatín

##### The best way to economize Vars (Bit-flag)
#1  November 02, 2014, 05:06:48 pm
• Ya me dio cosa...
"Simple Megaman example"

[_1_][_2_][_3_]
[_4_][_0_][_5_]
[_6_][_7_][_8_]

States 1000-1999 -> Ringman's stuff
Code:
`...[Statedef 1999]; Get equipped withtype=S[State 1]type=Varaddtrigger1 = !Timev=1value = 2 ** 1 ;<--[_1_]...`

States 2000-2999 -> Diveman's stuff
Code:
`...[Statedef 2999]; Get equipped withtype=S[State 2]type=Varaddtrigger1 = !Timev=1value = 2 ** 2 ;<--[_2_]...`

States 3000-3999 -> Skullman's stuff
Code:
`...[Statedef 3999]; Get equipped withtype=S[State 3]type=Varaddtrigger1 = !Timev=1value = 2 ** 3 ;<--[_3_]...`

States 4000-4999 -> Pharaohman's stuff
Code:
`...[Statedef 4999]; Get equipped withtype=S[State 4]type=Varaddtrigger1 = !Timev=1value = 2 ** 4 ;<--[_4_]...`

States 5000-5999 -> Brightman's stuff
Code:
`...[Statedef 5999]; Get equipped withtype=S[State 5]type=Varaddtrigger1 = !Timev=1value = 2 ** 5 ;<--[_5_]...`

Code:
`...[Statedef 1999]; Get equipped withtype=S[State 6]type=Varaddtrigger1 = !Timev=1value = 2 ** 6 ;<--[_6_]...`

States 7000-7999 -> Drillman's stuff
Code:
`...[Statedef 7999]; Get equipped withtype=S[State 7]type=Varaddtrigger1 = !Timev=1value = 2 ** 7 ;<--[_7_]...`

States 8000-8999 -> Dustman's stuff
Code:
`...[Statedef 8999]; Get equipped withtype=S[State 8]type=Varaddtrigger1 = !Timev=1value = 2 ** 8 ;<--[_8_]...`

States 10000-10999 -> Painel
Code:
`...[Statedef 10000] ;Show the weaponstype=S[State 1]; Ringmantype=Explodtriggerall=!Timetrigger1 = ( Var(1) > = 2 ** 1 )  ;Must have this value [_1_]trigger1 = ( Var(1) % ( 2*(2 ** 1) ) >=( 2 ** 1 ) ) ;Study ;p anim=801...[State 2]; Divemantype=Explodtriggerall=!Timetrigger1 = ( Var(1) > = 2 ** 2 )  ;Must have this value [_2_]trigger1 = ( Var(1) % ( 2*(2 ** 2) ) >=( 2 ** 2 ) ) ;Study ;p anim=802...[State 3]; Skullmantype=Explodtriggerall=!Timetrigger1 = ( Var(1) > = 2 ** 3 )  ;Must have this value [_3_]trigger1 = ( Var(1) % ( 2*(2 ** 3) ) >=( 2 ** 3 ) ) ;Study ;p anim=803...[State 4]; Pharaohmantype=Explodtriggerall=!Timetrigger1 = ( Var(1) > = 2 ** 4 )  ;Must have this value [_4_]trigger1 = ( Var(1) % ( 2*(2 ** 4) ) >=( 2 ** 4 ) ) ;Study ;p anim=804...[State 5]; Brightmantype=Explodtriggerall=!Timetrigger1 = ( Var(1) > = 2 ** 5 )  ;Must have this value [_5_]trigger1 = ( Var(1) % ( 2*(2 ** 5) ) >=( 2 ** 5 ) ) ;Study ;p anim=805...[State 6]; Toadmantype=Explodtriggerall=!Timetrigger1 = ( Var(1) > = 2 ** 6 )  ;Must have this value [_6_]trigger1 = ( Var(1) % ( 2*(2 ** 6) ) >=( 2 ** 6 ) ) ;Study ;p anim=806...[State 7]; Drillmantype=Explodtriggerall=!Timetrigger1 = ( Var(1) > = 2 ** 7 )  ;Must have this value [_7_]trigger1 = ( Var(1) % ( 2*(2 ** 7) ) >=( 2 ** 7 ) ) ;Study ;p anim=807...[State 8]; Dustlmantype=Explodtriggerall=!Timetrigger1 = ( Var(1) > = 2 ** 8 )  ;Must have this value [_8_]trigger1 = ( Var(1) % ( 2*(2 ** 8) ) >=( 2 ** 8 ) ) ;Study ;p anim=808...`

Whatever the order... The values are save correctly.

Used in this projects:

cya

#### Алексей

##### Re: The best way to economize Vars (Bit-flag)
#2  November 02, 2014, 10:07:21 pm
• Target Acquired.
I'm not sure why I'd want to do this. You're still setting the same var with a static number, so it's really just over complicating the hard-coding of simple values. Vars can hold up to the maximum size of a 32-bit integer, so this seems kind of counter-intuitive.

-[Все слова это только слова.]-

#### Jesuszilla

##### Re: The best way to economize Vars (Bit-flag)
#3  November 03, 2014, 12:43:28 am
• Loyal to the Game
No it's not. It's basically making one var hold a lot of booleans because all you need is 1 bit for a boolean, so there's no need to waste an entire variable on it.

This is the exact same thing as bitwise variables, so this is old news.

#### Bastard Mami

##### Re: The best way to economize Vars (Bit-flag)
#4  November 03, 2014, 01:36:47 am
• [E]
op also needs to memorize the powers of 2. any programmer worth it's salt knows them by memory.

#### Алексей

##### Re: The best way to economize Vars (Bit-flag)
#5  November 03, 2014, 01:38:47 pm
• Target Acquired.
No it's not. It's basically making one var hold a lot of booleans because all you need is 1 bit for a boolean, so there's no need to waste an entire variable on it.
Yes, but that's for booleans. Just set one variables to a bunch of different numbers and you have exactly the same result without the mess.

Code:
`var(1):=1var(1):=2var(1):=3var(1) = 1 ; Do somethingvar(1) = 2 ; Do something elsevar(1) = 3 ; Do something entirely different.`

He's still hard-coding values regardless of being boolean or not. It's easier on the engine to do less calculations, so just go down the traditional route above and you'll be fine. There's no need to try bringing extra programming concepts like this into mugen. It's not actually any faster. In terms of convenience, I've done bitwise operations as well, but it was actually used in a way that couldn't be replicated in any other way with the same simplicity. This over-complicates things.

-[Все слова это только слова.]-

#### Dr.Chapatín

##### Re: The best way to economize Vars (Bit-flag)
#6  November 05, 2014, 10:10:41 pm
• Ya me dio cosa...

##### Re: The best way to economize Vars (Bit-flag)
#7  November 05, 2014, 10:25:08 pm
• it's me
• Maybe something different
It's easier on the engine to do less calculations

which is why the bitwise operators &, | and ^ exist, they simplify their triggers, for example if I wanted to check toadman's ability I'd just use "trigger1 = var(1)&64" instead of what was indicated by OP and to set that same flag I'd use var(1):=(var(1)|64) and to turn it off I'd use var(1):=(var(1)^64)

#### Sheng Long

##### Re: The best way to economize Vars (Bit-flag)
#8  November 06, 2014, 12:32:02 am
• Video Game Veteran
• Can you do it? SUREYOUCAN!
Why are you using states that are used for more common states like getting hit (5000-5999) and so forth?

Some of this doesn't make sense to me. But I haven't messed with Mugen in months. So I donno. XP

"You must defeat my flaming
dragon punch to stand a chance."

#### Алексей

##### Re: The best way to economize Vars (Bit-flag)
#9  November 06, 2014, 01:21:13 pm
• Target Acquired.
In this case you set only one value each time.
But you are doing the same thing as well. Setting one value each time. You might be using the bits of an int, but you're not really doing it quicker. It's not saving any time or speeding up the engine's processing using your method. Please explain to me how you think your method is any different than setting one value each time? By nature, vars can only hold one value.

which is why the bitwise operators &, | and ^ exist, they simplify their triggers, for example if I wanted to check toadman's ability I'd just use "trigger1 = var(1)&64" instead of what was indicated by OP and to set that same flag I'd use var(1):=(var(1)|64) and to turn it off I'd use var(1):=(var(1)^64)
Exactly.

-[Все слова это только слова.]-

#### Jesuszilla

##### Re: The best way to economize Vars (Bit-flag)
#10  November 09, 2014, 06:54:01 am
• Loyal to the Game
This has nothing to do with speed. It has to do with getting around MUGEN's variable limit because if you move all your booleans into one variable, then you have more room in other variables to do other calculations.

And again, this is nothing new. Winane outlined it and I did a more in-depth explanation to help people understand what's going on.

#### XGargoyle

##### Re: The best way to economize Vars (Bit-flag)
#11  November 12, 2014, 10:10:26 pm
• Hedgehog Whisperer
Helpers have their own set of variables, so if you run out of variables, just spawn a helper and you'll instantly get an additional 60 ints and 40 floats.

Also, you can use other methods as a substitute to variables, especially for those ON/OFF stuff. Create an Explod or a Helper and use it's ID as a boolean flag. You can even use Animation numbers on a Helper to trigger specific conditions, instead of a variable.

 XGargoyle: Battle posing since 1979http://xgargoyle.mgbr.nethttp://www.pandorabots.com/pandora/talk?botid=e71c0d43fe35093a  <-- Please click that linkhttp://paypal.me/XGargoyle  <-- Donations welcome!

#### Jesuszilla

##### Re: The best way to economize Vars (Bit-flag)
#12  November 12, 2014, 10:28:59 pm
• Loyal to the Game
Use projectiles before you resort to helpers for flags. Much less memory consumption.

#### Bastard Mami

##### Re: The best way to economize Vars (Bit-flag)
#13  November 12, 2014, 10:34:45 pm
• [E]
Helpers have their own set of variables, so if you run out of variables, just spawn a helper and you'll instantly get an additional 60 ints and 40 floats.

Also, you can use other methods as a substitute to variables, especially for those ON/OFF stuff. Create an Explod or a Helper and use it's ID as a boolean flag. You can even use Animation numbers on a Helper to trigger specific conditions, instead of a variable.
agreed, those methods should be used after the bitflag one, tho.