Jump to content


Photo

script arguments


  • Please log in to reply
6 replies to this topic

#1 Mcmunchly

Mcmunchly

    GMC Member

  • New Member
  • 113 posts

Posted 15 January 2011 - 12:34 AM

how do I use arguments in a script?

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?
  • 0

#2 frankpiet

frankpiet

    ^destroyed evil chicken^

  • New Member
  • 760 posts

Posted 15 January 2011 - 12:39 AM

firstvar will be called argument0 in the script
secondvar will be called argument1 in the script

Remember you can call it as:

thescript(firstvar,secondvar)

It does the exact same thing

If you want the script to do something, use the return statment in the script. This stops the execution of the script.

For example:

WHERE YOU CALL THE SCRIPT
number=add(5,9)

THE SCRIPT CALLED "add"
return argument0+argument1;
  • 0

#3 FoxInABox

FoxInABox

    GMC Member

  • GMC Member
  • 5395 posts
  • Version:GM:Studio

Posted 15 January 2011 - 12:39 AM

for example let it sum together all the arguments?
value = scriptname(arg0,arg1, ... ,arg15)

would be like this:
return argument0 + argument1 + ... + argument15;

or as an array
var sum,i;
sum=0;
for(i=0;i<16;i+=1) sum+=argument[i];
return sum;

  • 0

#4 Mcmunchly

Mcmunchly

    GMC Member

  • New Member
  • 113 posts

Posted 15 January 2011 - 12:51 AM

can you pass objects as arguments?

not just the value but the actual object so I can change it's values?

Edited by Mcmunchly, 15 January 2011 - 12:55 AM.

  • 0

#5 GameGeisha

GameGeisha

    GameGeisha

  • GMC Member
  • 2747 posts
  • Version:GM:Studio

Posted 15 January 2011 - 01:18 AM

can you pass objects as arguments?

not just the value but the actual object so I can change it's values?

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:

Script: damage
/* damage(inst, amt) */
argument0.hp -= argument1;

Collision event of obj_bullet (with obj_enemy):
damage(other.id, 5);
instance_destroy();

GameGeisha
  • 0

#6 Mcmunchly

Mcmunchly

    GMC Member

  • New Member
  • 113 posts

Posted 15 January 2011 - 02:35 AM

can I rename the arguments?

can I go something like:
attacker = argument0;
attacker.hp -= 12;

I tried doing this but it didn't seem to work.

Edited by Mcmunchly, 15 January 2011 - 02:36 AM.

  • 0

#7 frankpiet

frankpiet

    ^destroyed evil chicken^

  • New Member
  • 760 posts

Posted 15 January 2011 - 03:46 AM

make sure you delclare it as a variable.


var attacker;
attacker=argument0;
attacker.hp-=12;



Also note that local variables are still avaliable. So you could easily use.change x and y in your script and it would change the object.

For more information look in the manual (look at Game Maker Language > GML Language overview > extra variables AND scripts)

Edited by frankpiet, 15 January 2011 - 03:48 AM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users