You are not logged in.
Pages: 1
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
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
Pages: 1