Script not changing the values of calling instance

Bentley

Member
Hello. I have a script that receives a variable number of arguments. I want the script to reset every incoming variable to 0.
Code:
Example script call

reset(hspd, vspd, grav);

Script

///reset(var1, var2, ...)

for (var i = 0; i < argument_count; i += 1)
{
    argument[i] = 0;
}
None of the values get set to 0. Does anyone know why? Thanks reading.
 
Last edited:
T

TimothyAllen

Guest
Because the arguments are passed in as copies. (arrays are a bit different and ds_ structures are simply indices)
 

Bentley

Member
Because the arguments are passed in as copies. (arrays are a bit different and ds_ structures are simply indices)
So when I send in hspd to the script as argument0, and then I code: argument0 = 0, hspd, in the calling instance, is unchanged? And if that's the case, do you know how to work around that? Thanks for the reply.
 

Tornado

Member
Code:
///scr_resetValues()
hspeed = 0;
vspeed = 0;
gravity = 0;
Then you just call
scr_resetValues();
from the instance.

Scripts have access to all instance-variables of the calling instance.
 
Last edited:
So when I send in hspd to the script as argument0, and then I code: argument0 = 0
I'm pretty sure you can't assign values to the argument0 etc... keywords.

So when I send in hspd to the script as argument0, and then I code: argument0 = 0, hspd, in the calling instance, is unchanged? And if that's the case, do you know how to work around that? Thanks for the reply.
Don't know if this would work, but as argument[0..N] is an array, could you use the array accessor (@) to directly modify the variable?

Code:
for (var i = 0; i < argument_count; i += 1)
{
    argument[@ i] = 0;
}
 

Bentley

Member
I'm pretty sure you can't assign values to the argument0 etc... keywords.



Don't know if this would work, but as argument[0..N] is an array, could you use the array accessor (@) to directly modify the variable?

Code:
for (var i = 0; i < argument_count; i += 1)
{
    argument[@ i] = 0;
}
I like the idea, I'll give it a try now. Thanks for the reply.

Edit: dang, got an error. Oh well, thanks again. I'll tinker with it. Let me know if you think of anything : )
 
Last edited:

Bentley

Member
Code:
///scr_resetValues()
hspeed = 0;
vspeed = 0;
gravity = 0;
Then you just call
scr_resetValues();
from the instance.

Scripts have access to all instance-variables of the calling instance.
Yeah, so if the script is:
hspd = 0;
hspd in the calling instance is set to 0.
But if the script is:
argument0 = 0; //And I called the script like this: scr_reset(hspd);
hspd in the calling instance is not set to 0.

I was hoping to find a way to use the key word argument to set the incoming variables to 0. That way, the script can be used to reset any variable.
 
Last edited:
But if the script is:
argument0 = 0; //And I called the script like this: scr_reset(hspd);
hspd in the calling instance is not set to 0.

I was hoping to find a way to use the key word argument to set the incoming variables to 0. That way, the script can be used to reset any variable.
The reason it isn't set is that the argument0 is not a pointer to the variable, it is just the value of the variable. So if your hspd was 5 and you called a script where argument0 was hspd, then the script only knows that argument0 is 5 not that it is hspd.
 
Top