• Hey! Guest! The 40th (!!!) GMC Jam will take place between February 25th, 12:00 UTC to March 1st 12:00 UTC. Why not join in this very special anniversary jam! Click here to find out more!

GMS 2.3+ Storing repeating code as command

ohWhatta

Member
Hello there!

It was a long time I've had fun with gamemaker, and it seems I've lost some vital parts of knowledge. Can't even compose a correct search query to google or gml docs.

I'm writing down some non complex stuff and got many repeating code parts like:
GML:
if something_x <= N then something_x += Z else Z = 0
And it repeats literally a tons of times for some specific objects.

However, I remember that there was a way to place just by specifying it as command. Like
GML:
if event_n = 1 then command_1
which must imply the code mentioned above.

So question is: how do I do that?
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Moderator
You'll want to create a function (previously known as a script, but with 2.3.1 that all changed). This can be in-line (local to the object) as a method variable or global, in a script. See here:
and here:

In your example you'd do something like:
GML:
check_x = function(_input, _check, _add)
{
if _input <= _check
    {
    _input += _add;
    }
return _input;
}
Which would then be used like:
GML:
something_x = check_x(something_x, N, Z);
 

ohWhatta

Member
You'll want to create a function (previously known as a script, but with 2.3.1 that all changed). This can be in-line (local to the object) as a method variable or global, in a script. See here:
and here:

In your example you'd do something like:
GML:
check_x = function(_input, _check, _add)
{
if _input <= _check
    {
    _input += _add;
    }
return _input;
}
Which would then be used like:
GML:
something_x = check_x(something_x, N, Z);
I was struggling yesterday with script as I did really remember writing something like "script" and was quite sure that I did something like this before, but it just didn't work. I'll try that one today.

Thanks a lot!
 
Top