modular variables?

T

The Man of Many Hats

Guest
Hey guys. I was wondering if it was at all possible to create modular variables in our scripts... Which I guess are kind of like arrays?

Here's an example of what I mean:

Var mod = ””
Var [mod]dog = 0
Var breed = 1

If (breed = 1)
{
mod = ”bull”
} else mod = "lab"

[mod]dog = 1


//Therefore var bulldog = 1

It would be really useful to do it with script calling. So if you have a few similarly named scripts, you could call many of them bassed on the return value of one variable instead of creating a bunch of if statements, or cases.

script_execute(SCR_[mod]dog)
// This would execute a script named SCR_bulldog bassed on the previous example.

So... If this is in here, how do you do it? Cuz I've tried a few different ways and I always get crashes :/

And if it's not in, do you think it would be a useful addition?
 

CloseRange

Member
The way this is worded is a bit confusing.
Usually mod or modulo refuers to the math function % that returns a remainder:
Code:
var a = 10 mod 6;
// a = 4; the remainder of 10 / 6
What you described sounds like enum's:
Code:
enum dog {
     bull,
     lab
}
dogs_[dog.bull] = scr_bull_dog;
dogs_[dog.lab] = scr_lab_dog;


// somewhere else in the code
script_execute(dogs[dog.bull]);
but you might be more interested in asset_get_index(name);
Code:
var type = "bull"

var scr = asset_get_index("scr_" + type + "dog");
script_execute(scr);
 
Top