Discuss and collaborate on GML scripts

You are not logged in.

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

Registered: 2018-07-24
Posts: 1

help with object variable and script

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 ?


//--code-obj create event

move1 = 0;
move2 = 0;

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

if (something)
     script_Pos(move1 );
     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 ?


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

Registered: 2007-08-18
Posts: 1,195

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.


Board footer

Powered by FluxBB