• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Issue using script with arguments [SOLVED]

S

Sam Brixey

Guest
I am using a script to add a slow effect and am trying to add an argument for the duration. So in the script i have as the first line "///scr_status_slow(dur)"
and in the script;

var duration = argument[0]

spd = 0.5

if (alarm[10] <= 0) {
alarm[10] = duration
}
if (alarm[10] <= 2) {
status = scr_status_normal
}

Then in my slow object for the collision event with a lifeform I have the following;

other.status = scr_status_slow(40)

For some reason however when I run my game and hit a lifeform with this the lifeform tries to run a script for its status which is entirely unrelated and the game crashes as it tried to use variables that havn't been set in the lifeform as it shouldn't be running that script. The only reason I can see that it would run that script is it is the first script in my resource tree but why is it calling this script and not setting scr_status_slow as the status script? (Have tested this by moving a different script to the top of the list of scripts and it also runs this script as the objects status).

Note that there is no problem at all if I just have the script with no arguments and instead set the duration in the collision event and then set the status to scr_status_slow. for example;

other.status = scr_status_slow
other.alarm[10] = 40
 

TheouAegis

Member
scr_status_slow(40) runs the script scr_status_slow, and since your script doesn't even return anything, it sets other.status to 0. If you wanted to pass the 40 to the script_execute() call, then you'd need to save the 40 to a separate variable and pass that variable with the script_execute() call.
 
S

Sam Brixey

Guest
scr_status_slow(40) runs the script scr_status_slow, and since your script doesn't even return anything, it sets other.status to 0. If you wanted to pass the 40 to the script_execute() call, then you'd need to save the 40 to a separate variable and pass that variable with the script_execute() call.
Thanks for the reply. I can't get my head around it. I thought that by setting an argument in the script (argument0 or dur ) and then when my object collides with the player and sets their status as the script with the 40 entered for the argument it would run the script with the alarm being set with that as the duration. I'm sorry I don't understand what you mean by the script doesn't return anything, can you explain this further?

just to give some more info on how I have set this up at the moment;

I have the create event set the state to scr_state_normal. This just set the speed back to original speed.

Then I have in the step event script_execute(state);
 
J

JFitch

Guest
Code:
variable=script
Without parentheses after the script, it will set the variable to the script's name, in which case you can later use script_execute(variable).

Code:
variable=script()
With parentheses after the script, it will set the variable to the value that the script returns, using whatever arguments are inside the parentheses. If you wish to save the script's name and the argument, you'll have to use one variable for the script's name and another variable for the argument.
 
S

Sam Brixey

Guest
Code:
variable=script
Without parentheses after the script, it will set the variable to the script's name, in which case you can later use script_execute(variable).

Code:
variable=script()
With parentheses after the script, it will set the variable to the value that the script returns, using whatever arguments are inside the parentheses. If you wish to save the script's name and the argument, you'll have to use one variable for the script's name and another variable for the argument.
Thankyou so much. From what you and TheouAegis have said I have made a variable in the objects create event (slowduration) and then when the slow orb collides with the player it sets a value to the variable "slowduration" and then runs the script which uses this variable and then afterwards sets "slowduration" back to 0 to be used again and it ALL WORKS! :D

Thanks again!


Now to make a Burn Status...
 
Top