GMLscripts.com

Discuss and collaborate on GML scripts
Invert

You are not logged in.

#1 2018-07-24 05:25:58

jonPS
Member
Registered: 2018-07-24
Posts: 1

help with object variable and script

hello
i have a code that repeats itself several times on the object variables
my question is it possible to change the obj variables using a script ?

example:

//--code-obj create event

move1 = 0;
move2 = 0;
//--code-script_Pos

var mv = argument0;
mv += 10;
//--code-step event

if (something)
{
     script_Pos(move1 );
}
else
{
     script_Pos(move2 );
}

I cant seem to change the obj variables with the script they always return 0... but if i change the script like this:

var mv = argument0;
move1 += 10;

move1 seems to increment +10 ?

Offline

#2 2018-07-26 11:31:11

xot
Administrator
Registered: 2007-08-18
Posts: 1,201

Re: help with object variable and script

In GML, arguments given to scripts are generally only pass-by-value, not pass-by-reference. There are some exceptions to this.

1. Data structures (which are really just global indices) always work by-reference unless you explicitly duplicate them.

2. Arrays can be written to in a script by-reference using the array accessor (eg. array[@ index] = value — notice the @ symbol). Without the @ array accessor, when you write to the array, a duplicate array will be created. For technical / performance reasons, you should only use the @ array accessor when writing (although it will still work for reading if you do use it).

Otherwise, your script will have to directly name the instance variables you want to change, as you have discovered.


Abusing forum power since 1986.

Offline

Board footer

Powered by FluxBB