YesNoOk
avatar

VarSet (SCTRLs) (Read 5347 times)

Started by Odb718, September 22, 2015, 03:53:30 am
Share this topic:
VarSet (SCTRLs)
#1  September 22, 2015, 03:53:30 am
  • *****
  • Shame on you!
    • USA
Sets one of the player's working variables. Either a float variable or an int variable can be set by this controller, but not both at the same time.

Required parameters (int version):
    v = var_no (int)
        var_no specifies the number of the variable to affect. It must evaluate to an integer between 0 and 59.
    value = int_expr (int)
        int_expr specifies the value to assign to the int variable indexed by var_no.

Required parameters (float version):
    fv = var_no (int)
        var_no specifies the number of the variable to affect. It must evaluate to an integer between 0 and 39.
    value = float_expr (float)
        float_expr is the value to assign to the float variable indexed by var_no.

Optional parameters:
    none in both cases
Alternate syntax:
    var(var_no) = int_expr (int version)
    fvar(var_no) = float_expr (float version)
Notes:
    Due to historical reasons, note that the alternate variable assignment syntax listed above does not exactly match the syntax for variable assignment within an expression.

    If you have placed P2 in a custom state through a successful hit, do not use variable assignment within the custom states. Otherwise, you will overwrite P2's variables, which can cause unintended malfunction of the opponent player.
Example:
Code:
[State 0, VarSet]
type = VarSet
trigger1 = time = 1
v = 10 
value = 0
ignorehitpause = 1

Related SCTRL:
VarAdd (SCTRLs)
VarRandom (SCTRLs)
VarRangeSet (SCTRLs)

Related Triggers:
Var and FVar (Triggers)
SysVar (Triggers)
SysFVar (Triggers)
StageVar(*,***) (Triggers)

Related CNS:
IntPersistIndex & FloatPersistIndex  -  Player Variables (CNS)
vVv Wheat Stage Released vVv
Last Edit: December 10, 2015, 02:31:11 pm by Odb718
Re: VarSet (SCTRLs)
#2  December 10, 2015, 01:31:13 pm
  • *****
  • Shame on you!
    • USA
Updated with the Related Triggers and SCTRLs.
Var and FVar (triggers) is the topic you need to read if you're having trouble with Variables.

VarSet is probably the most common of the related variable controls.
Remember to reset the variable when reloading a state. If it works the first time, but not the second time, it's usually because you haven't reset it to the original value. You may not have to reset the value, but it's usually needed.
vVv Wheat Stage Released vVv
Re: VarSet (SCTRLs)
#3  January 28, 2016, 07:36:17 pm
  • *****
  • Gaps? Where we're going, we don't need gaps...
    • USA
    • ricepigeon.neocities.org
While not explicitly mentioned, helpers have their own variables that are independent of the player's. Thus, calling VarSet from within a helper's state will only change that helper's instance of that variable, not the player's. For instance, say we have a helper using the Varset controller;

Code:
;Helper State
[State 2010, Varset]
type = VarSet
trigger1 = time=0
var(10)=200

...and in the player's state 200, we try to call the value of var(10);

Code:
;Player state
[State 2000, Changestate]
type = changestate
trigger1 = var(10)=200
value = 2001

The changestate will not trigger, assuming that no other changes to Var(10) were made. This is because the player is calling its own instance of Var(10), which is initialized at 0, as opposed to the helper's instance of Var(10), which is what was set to 200 earlier. For these instances, you will want to either call the helper's instance of Var(10) using trigger redirection (eg: helper(2010),var(10)) or use ParentVarSet from within the helper's state instead of VarSet, assuming that the helper was spawned by the player and not by another helper (RootVarSet or an equivalent state controller is not supported by Mugen as of yet).
Re: VarSet (SCTRLs)
#4  January 29, 2016, 09:37:49 am
  • ******
  • Legendary XIII
  • I am the eye of the storm to come!
    • New Zealand
    • network.mugenguild.com/cyanide/
Something to remember with parentvarset is that it is a tick behind. If you have a string of helpers 15 long and the one on the end triggers a parentvarset that has to cascade down all 15 helpers, it will take 15 ticks to reach the player. Alternatives to this are spawning an explod or a projectile (projectiles are always owned by the root) and using that to set the value of a variable.


In M.U.G.E.N there is no magic button

They say a little knowledge is a dangerous thing, but it's not one half so bad as a lot of ignorance.
Re: VarSet (SCTRLs)
#5  January 31, 2016, 09:12:10 am
  • *****
  • Shame on you!
    • USA
Just to clarify Cyanide, In this example, In my 15th helper I have something happen that the root needs to know about instantly.
I should spawn a projectile in the 15th helper and the root will take charge of it.
In my root, I should put a check to see if there's a projectile with the
ProjID =
I set. And the root will activate what needs to happen instead of waiting the fifteen tics?
Will the action be 1 tic off because the helper is 1 tic slower?

Obviously I'd want to use a dummy projectile that doesnt hit P2 in any possible way.
vVv Wheat Stage Released vVv
Re: VarSet (SCTRLs)
#6  February 04, 2016, 06:27:26 am
  • ******
  • Legendary XIII
  • I am the eye of the storm to come!
    • New Zealand
    • network.mugenguild.com/cyanide/
1 tick is superior to 15 ticks. I never counted it out. The root loooks for numprojID1234 and if it exists the root does a thing.

One of the other nice things about this is projectiles are a built in timer. You can set how long a projectile lasts for so if you want something possible within a time range the projectile takes care of that too.


In M.U.G.E.N there is no magic button

They say a little knowledge is a dangerous thing, but it's not one half so bad as a lot of ignorance.
Re: VarSet (SCTRLs)
#7  February 05, 2016, 01:08:52 am
  • ****
  • Robotics Engineer
    • USA
    • altoiddealer@gmail.com
One of the other nice things about this is projectiles are a built in timer. You can set how long a projectile lasts for so if you want something possible within a time range the projectile takes care of that too.

Nice tip, I think I'll try using this instead of a VarSet / VarAdd to timer my minigun attack