• 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!

GameMaker scripts and parentheses

B

Bladebss

Guest
ok, so, im a bit confused about the use of parentheses at the end of scripts. some times if I don't have the parentheses the script wont run and some times if I do have them the script wont run?

if the script has arguments and I put them in the parentheses, as is necessary, the script runs fine if its written like that in say, the step event. but if I have a data structure with the script as one of the values in the structure, if I use parentheses at the end the script doesn't work, and if there are arguments I need in the parentheses, it just reads 0 in the show_debug_messsage(), if I add the arguments and parentheses it runs the first script in the list of scripts in the resource list and not the script in the grid? (all other entries in the grid are present and correct though the debug message for sprites in the grid return a number?)

im using execute_script(ds_grid_get,id,x,y), to call the script in the grid and the script in the grid is set using
ds_grid_set(id,x,y,myscript(arguments)) is this wrong? am I trying to do something that's not possible or using the wrong tools for the job?

I cant find the rules for parentheses and scripts any where, or when to use them and when not to.

whats going on here and how can I fix it so I can run the script in the grid using the argument defined in the grid?
 
T

Timothy

Guest
As it is now, if you are not calling the script directly, ie script_name(args), but instead are using a variable with the index you must use script_execute(). For example:
Code:
var script_var = some_script_asset
script_execute(script_var, args);
 
B

Bladebss

Guest
Im sorry but i don't understand, how do i have different arguments for the same script in a data structure so i can call the arguments i want for the script depending on conditions?
I cant see how to do this using the above code.
It most definitely me being thick here lol
 

FrostyCat

Redemption Seeker
im using execute_script(ds_grid_get,id,x,y), to call the script in the grid and the script in the grid is set using
ds_grid_set(id,x,y,myscript(arguments)) is this wrong? am I trying to do something that's not possible or using the wrong tools for the job?
That's wrong on two counts.

First, ds_grid_get() is a built-in function, not a script. It won't work with script_execute().

Second, when you did this:
Code:
ds_grid_set(gridid,x,y,myscript(arguments))
You are actually running myscript with the given arguments and saving the result of that into the grid, not some sort of "to-do item" into the grid.

You will need to modify scripts used this way to accommodate being stored as to-do items. Make them take a single array argument instead of several distinct arguments. Then add to the grid like this:
Code:
mygrid[# x, y] = [myscript, [arguments]];
And run them from the grid like this:
Code:
var todo = mygrid[# x, y];
script_execute(todo[0], todo[1]);
 

TheouAegis

Member
script_name with no parentheses is the script's ID. script_name with parentheses is a jump-to command, running the acriot right then and there, returning a value of 0 if no return value is actually received from the script.

And as Frosty said, don't call built-in functions with script_execute().
 
B

Bladebss

Guest
Ok. I dont think this will work for what i want it for but it was realy helpful to now known how parentheses work with scripts and have clarified alot of thing for me so thanx for that!

I was expecting the ds_grid get(id,x,y) to point to my script in the grid and that the script_execute() would run after it found the script at the grid referance, as with out the parentheses in the script in the grid, it works with this method as long as i had no argument inputs in the script. I wasnt expecting it to run the function ds_grid_get but the script it pointed to. I see now there were a number of wrong asumption's in this lol

I have come up with a different way to do what i want and so far its all working out! And may in fact be much more usefull and dynamic, Yay! Some times ya just got to go back to the drawing bord lol

Thanx evey one for the info esp frostycat as thats twice now you have come to my rescue :D
 
Last edited by a moderator:
Top