YesNoOk
avatar

Variables Tutorial (Read 2012 times)

Started by DM, October 19, 2009, 06:17:27 am
Share this topic:

DM

Variables Tutorial
#1  October 19, 2009, 06:17:27 am
  • ****
  • Madvillain
    • Brazil
    • www.rickiecreations.paodemugen.com.br
Hi, this is a simple tutorial I made some time ago about how to use the variables properly. I rarely write tutorials, so if I did some confusion or made a mistake, sorry. In this case, I ask you to help me and point the errors.

Also, keep in mind that this tutorial was done to help beginners.


_________________________________________________ _______________________________
1 - What is a var?

A var is a variable value (lol capitain obvious). And this value may be what you want. There are 2 types of var: var(x) (int values: 1,2,3,10,50, etc) and fvar(x) (fractions: 1.2, 2.45, 6.78787. etc).
60 vars [var(0) ~ var(59)] and 40 fvars [fvar(0) ~ fvar(39)] can be used.

An  important thing: by 'default', MUGEN identifies the last 10 vars, [var(50) ~ var(59)], as vars that do not change his values between the rounds. This can be modified in the parameters of chars. So be careful using these vars.

Then a var is always an integer value and a fvar is always a fraction. Example:

Quote
correct
[state 15, var]
type = varset
trigger1 = 1
var(5) = 2

wrong
[state 90 var]
type = varset
trigger1 = time = 50
var(40) = 2.0

correct
[state 2000, var]
type = varset
trigger1 = 1
fvar(12) = 3.56

wrong
[state 1500 var]
type = varset
trigger1 = time = 50
fvar(10) = 6

There is still a third type of var, the sysvars (literally, system variables), which can be sysvars or sysfvars. These are specifically for issues of common1. CNS - to the 'standards' of the engine.


_________________________________________________ ________________________________
2 - Specific Sctrls
*this can be found in the mugendocs, though.

a) varadd
As the name says, this sctrl add a value to the var.
"Actual value + Varadd's value = New Value"

Example:

[mcode][state 100, var]
type = varadd
trigger1 = time = 0
var(10) = 1[/mcode]

Using a fvar:

[mcode][state 100, var]
type = varadd
trigger1 = animelem = 3
fvar(25) = -5.35[/mcode]


b) varset

This sctrl will set a new value, instead of add a value (like varadd sctrl).

Example:

[mcode]
[state 305, var]
type = varset
trigger1 = time = 50
var(5) = 2
[/mcode]

Now using a fvar:

[mcode][state 305, var]
type = varset
trigger1 = statetype = A
fvar(8) = 1.256[/mcode]

c) varrandon
This sctrl stipulates a random value to the var. Only integers, so, don't works with fvars.

Example:

[mcode][state 200, var]
type = varset
trigger1 = statetype = C
v = 8
range = 0,10[/mcode]
*range = minor value, major value

d) varrangeset
Finally, this sctrl stipulates a certain valor in multiple vars.

Example:

[mcode][State 1000, 3]
type = VarRangeSet
trigger1 = time = 0
value = 0
first = 0
last = 59[/mcode]
*first = first var, last = last var

_________________________________________________ ________________________________
3 - How can I use it?

Basically, the var will stocking a value. Example:

[mcode]
[state 1000, var]
type = varset
trigger1 = time = 0
var(0) = 10
[/mcode]

In this example, the var(0) received the value 10 (the var is equals 10). It does not seem very amazing... but look the next example:

[mcode][state 1001, var]
type = varset
trigger1 = time = 0
var(1) = (10 + var(0)*time/3) + (25*time/2 + (var(10)/3))[/mcode]

Now, the var(1) is equals "(10 + var(0)*time/3) + (25*time/2 + (var(10)/3))". If I need to write a sctrl using this value, I can only write var (1) in its place, because it is the same thing. This is the magic about vars. :D

Another example:

[mcode][state 1000, var]
type = varset
trigger1 = stateno = 300
trigger1 = Anim = 200
trigger1 = animelem = 3
var(1) = 2


[state 1000, var]
type = changestate
trigger1 = stateno = 300
trigger1 = Anim = 200
trigger1 = animelem = 3
value = 301

or

[state 1000, var]
type = changestate
trigger1 = var(1) = 2
value = 301[/mcode]

_________________________________________________ ________________________________

Sorry, my english is not the best. But I tried to do everything as clearly as possible.
If anyone has any complement or correction, please feel free to post.

:)
Re: Variables Tutorial
#2  May 21, 2011, 05:47:52 am
  • **
  • "GrayCircle will once be the greatest warrior"
    • i.imgur.com/MdGQY.gif
I do not fully understand ...
"GrayCircle will surpass ever hero one day!"

My Local Name: Fighting Toys Freak.
Re: Variables Tutorial
#3  May 21, 2011, 06:30:25 am
  • ******
  • Legendary XIII
  • I am the eye of the storm to come!
    • New Zealand
    • network.mugenguild.com/cyanide/
And i wouldn't. This is not the best tutorial written. It doesn't explain what it should and glosses over things it shouldn't as well as getting bits and pieces wrong altogether.

DM i'm sure has improved and may want to re-write this. If you actually have a coding related question please direct it to the dev help section.


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.