So let say I use
script_execute(thescript, firstvar, secondvar);
how do I identify and use firstvar and secondvar in the script? Is there a special 'argument' keyword or something?
Posted 15 January 2011 - 12:48 AM
script_execute(thescript, firstvar, secondvar);
Posted 15 January 2011 - 12:53 AM
Posted 15 January 2011 - 12:53 AM
value = scriptname(arg0,arg1, ... ,arg15)
return argument0 + argument1 + ... + argument15;
var sum,i; sum=0; for(i=0;i<16;i+=1) sum+=argument[i]; return sum;
Posted 15 January 2011 - 01:05 AM
Edited by Mcmunchly, 15 January 2011 - 01:09 AM.
Posted 15 January 2011 - 01:32 AM
Yes, you can pass object instance IDs as arguments. Then you can change variables that are local to them. Here's an example of how this can be applied:can you pass objects as arguments?
not just the value but the actual object so I can change it's values?
/* damage(inst, amt) */ argument0.hp -= argument1;
damage(other.id, 5); instance_destroy();
Posted 15 January 2011 - 02:49 AM
attacker = argument0; attacker.hp -= 12;
Edited by Mcmunchly, 15 January 2011 - 02:50 AM.
Posted 15 January 2011 - 04:00 AM
var attacker; attacker=argument0; attacker.hp-=12;
Edited by frankpiet, 15 January 2011 - 04:02 AM.
Posted 03 January 2014 - 05:16 PM
is there a loop that allows me to know exactly how many arguments were passed to a script, like:
var args; for(args=0 args<16 args+=1) { if (is_real(argument[args])) { break; } } return args;
but instead of is_real, i need the right function, the one that can know whetever the argument is void. in game maker studio, there is argument_count, but for gm80, i need a equivalent function.
Posted 03 January 2014 - 06:45 PM
I think in Studio, but don't think there is in legacy versions. In legacy versions, all undefined arguments are set to 0.
"The problem with object-oriented languages is that they've got all this implicit environment that they carry around with them. You wanted a banana but what you've got is a gorilla holding the banana and the entire jungle." -Joe Armstrong
"It goes against the grain of modern education to teach children to program. What fun is there in making plans, acquiring discipline in organizing thoughts, devoting attention to detail and learning to be self-critical?" -Alan Perlis
"Do not think about where you want to be and how to get there; think about what you want to do and how to do it." -Theou Aegis
Posted 03 January 2014 - 06:52 PM
With GM8.0 and earlier, there is no reliable way to detect how many arguments are passed in. Unused arguments are set to 0, and that makes them indistinguishable from used arguments that have 0 passed into them. Finding the last non-zero argument is the best you can do.
That's why argument_count was introduced in GM8.1.
GameGeisha
Posted 03 January 2014 - 07:49 PM
well i'm thinking about a loop but i still can't finish it. i'll just post a lnk the the finished script that will return the argument count in 30-45 minutes with some others i made
edit: no link posted, just the raw code
var i, args_number, max_args; /* add here the maximum number of arguments your script * can handle (set it into the variable max_args). For * my example, i'll use at most 16 arguments (max index: argument[15]) */ max_args=16 for(i=0 i<max_args i+=1) { if(argument[i]=0) { args_number=i } }
Edited by idenii, 03 January 2014 - 10:45 PM.