YesNoOk
avatar

sysvar (Triggers) (Read 5799 times)

Started by ClamSlam, September 20, 2015, 01:39:25 AM
Share this topic:
sysvar (Triggers)
#1  September 20, 2015, 01:39:25 AM
  • ***
  • Drew my Icon. I know, i'm a Amateur.
  • just trying to survive in the land of MFG
    • American Samoa
    • ClamSlam@mugenguild.com
This trigger takes a mandatory variable number as an argument. It returns the value of the player's specified system int variable. This trigger is NOT to be used under normal circumstances. System variables are reserved for bookkeeping in common1.cns.

Format:
Var(exprn)
Arguments:
exprn
An expression evaluating to a variable number. Valid numbers at this time are 0-4.
Return type:
int
Error conditions:
Returns bottom if exprn evaluates to bottom, or if exprn evaluates to an invalid variable index.
Example:
trigger1 = SysVar(0) = -34
  Triggers if the value of system variable 0 is -34.

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

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

Related CNS:
IntPersistIndex & FloatPersistIndex  -  Player Variables (CNS)


What is the purpose of this?
"If you can't slam with the best then go jam with the rest."
Last Edit: December 10, 2015, 02:32:26 PM by Odb718
Re: sysvar (1)
#2  September 20, 2015, 02:04:07 AM
  • ****
  • The Barbarian
  • Most ****able 2013
    • USA
    • Skype - chronostrifeff7h@hotmail.com
sysvars are system variables that aren't REALLY intended to be messed with, atleast that is how the documentation is implied. With that said, if you know what they are doing you can use and abuse them a bit, but it might be easier to just workaround them -or- ignore them in most cases. Sysvars store integers.

Sysvars according to Elecbyte:
The common.cns itself gives you an idea of whats going on with these variables.
; System variables usage
; ----------------------
; Var name    Type   Purpose
; --------    ----   -------
; sysvar(0)   Temp   Set by state 5081 (HITL_SLIDE) to 1 to prevent showing ground hit frame in state 5110 (HIT_LIEDOWN).
;                    Used by guarding states.
; sysvar(1)   Temp   Used by state 40 (Jump Start) amd 45 (Air Jump Start) to keep track of which way to jump.
;                    Used by state 5100 and 5110 to remember downward
;                    velocity of player just before hitting the ground.
;                    Used in state 5080 for storing the anim # to display.
Note: That last line "Used in state 5080 for storing the anim # to display." is incorrect! It implies sysvar(1) stores the animation, but it is actually sysvar(2) doing the job.

There is a Sysvar trigger the Mugen Trigger Doc describes as well:
Spoiler: SysVar (click to see content)


Understanding Sysvars by through delivered use cases:
If none of that means a thing to you yet, you can get an idea of how they are used by skimming the common.cns!
The Jump States [Statedef 40-50] is probably the most common place people will care about sysvar(1):
Code:
[State 40, 1]
type = VarSet
trigger1 = Time = 0
sysvar(1) = 0

[State 40, 2]
type = VarSet
trigger1 = command = "holdfwd"
sysvar(1) = 1

[State 40, 3]
type = VarSet
trigger1 = command = "holdback"
sysvar(1) = -1

[State 40, 4]
type = VelSet
trigger1 = AnimTime = 0
x = ifelse(sysvar(1)=0, const(velocity.jump.neu.x), ifelse(sysvar(1)=1, const(velocity.jump.fwd.x), const(velocity.jump.back.x)))
y = const(velocity.jump.y)
In this jump state sysvar(1) is used to determine whether the players is jumping neutral, forward, or backwards. This applies for all jump related states, from 40-50. Basically, it's just keeping track of how the character started jumping to apply velocities and change animations later in Statedef 50.
If you're curious, the "const(velocity.jump.fwd.x)" is being pulled from the characters velocity constants, in whatever the characters base.CNS is:
Code:
[Velocity]
...
jump.neu = 0,-9.6         ;Neutral jumping velocity (x, y)
jump.back = -3.2          ;Jump back Speed (x, y)
jump.fwd = 3.2            ;Jump forward Speed (x, y)
...

Sysvar(1) is also used in fall-bounce states, which is probably the next most importantly place you'll care about. From the looks it is used to determine the fall Y-velocity so the state can determine how hard the character is going to hit the ground. In this state the Y-velocity is stored in sysvar(1), then based on the stored velocity value in sysvar(1), the state generates an Explod and Sound effect.
Code:
[State 5100, Var] ;Save fall velocity
type = VarSet
trigger1 = Time = 0
sysvar(1) = floor(vel y)

[State 5100, 8]
type = Explod
trigger1 = Time = 1
anim = F(60 + (sysvar(1) > Const720p(20)) + (sysvar(1) > Const720p(56)))
postype = none
pos = pos x + camerapos x, 0
facing = facing
sprpriority = ifelse (sysvar(1) <= Const720p(56), -10, 10)

[State 5100, 10]
type = PlaySnd
trigger1 = Time = 1
value = F7, (sysvar(1) > Const720p(20)) + (sysvar(1) > Const720p(56))



Examples of use:
You can use the sysvar trigger most commonly in the jump states if you want an after image trail for non-neutral jumps -or- in the CMD if you want a jump kick that only works when jumping neutral (straight-up) for example you could do something like this.
Code:
[State -1, Jump Kick Normal]
type = ChangeState
value = 630
triggerall = (command = "a")
trigger1 = statetype = A && ctrl && sysvar(1) != 0 ;perform while jumping forward or back
trigger2 = stateno = 600 && movecontact

[State -1, Jump Kick Upwards]
type = ChangeState
value = 635
triggerall = (command = "a")
trigger1 = statetype = A && ctrl && sysvar(1) = 0  ;perform while jumping neutral
Depending on the complexity of your air attacks and air movement you may not want to use the sysvar(1) trigger though. It might be easier and safer to just use the Vel X trigger to determine which direction your character is moving, rather than the direction they started jumping.


Additional Notes:
  • There is also a SysFvar, which functions the same as a SysVar but stores float values. However it doesn't appear to be used directly.
  • A Sysvar(2) is used in Statedef 5080 to store the next animation to change to. It isn't documented like sysvar(0-1) are.
  • A Sysvar(3) and Sysvar(4) do not appear to be used directly.
  • Using unused sysvars and sysfvars as normal variables could cause compatibility issues in future versions of Mugen.
Last Edit: September 20, 2015, 02:48:53 AM by chrono.st
Re: sysvar (Triggers)
New #3  December 13, 2016, 07:50:20 PM
  • ******
    • www.justnopoint.com/
When using these with helpers do you need to access them with root, sysvar? Do helpers have their own sysvars like regular and floats?

EDIT: It looks like you don't have to use redirects for helpers to access these. So no, helpers wouldn't have their own sysvars.
Last Edit: December 13, 2016, 09:37:11 PM by Just No Point