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

SOLVED I cant get the choose function to work?

C

Coffeli

Guest
When i press the mouse button it uses both of my choose values and not just one. I am trying to call scripts

step event:
if mouse_check_button_pressed(mb_left)
{
choose(scrattack1(),scrattack2());
}
 

chamaeleon

Member
When i press the mouse button it uses both of my choose values and not just one. I am trying to call scripts

step event:
if mouse_check_button_pressed(mb_left)
{
choose(scrattack1(),scrattack2());
}
choose takes values and returns a value from them. It does not take actions and then only invokes one of the actions. In your code choose is being given the return values of the two functions which will have been both called before choose returns one of those two return values.

Assuming GMS 2.3 functions you could do
GML:
var f = choose(scrattack1, scrattack2);
f();
 
C

Coffeli

Guest
choose takes values and returns a value from them. It does not take actions and then only invokes one of the actions. In your code choose is being given the return values of the two functions which will have been both called before choose returns one of those two return values.

Assuming GMS 2.3 functions you could do
GML:
var f = choose(scrattack1, scrattack2);
f();
it worked but would does the f mean in that?
 

chamaeleon

Member
it worked but would does the f mean in that?
var f is just a local variable whose name you could make whatever you want (perhaps something more representative of the nature of your scripts).
GML:
var chosen_attack = choose(scrattack1, scrattack2);
chosen_attack();
If you want to take the action right there and then it is also possible to write
GML:
choose(scrattack1, scrattack2)();
and avoid the use of an temporary variable. But the concept remains the same, don't call the functions you want to choose between, rather invoke the function returned by choose().
 
C

Coffeli

Guest
var f is just a local variable whose name you could make whatever you want (perhaps something more representative of the nature of your scripts).
GML:
var chosen_attack = choose(scrattack1, scrattack2);
chosen_attack();
If you want to take the action right there and then it is also possible to write
GML:
choose(scrattack1, scrattack2)();
and avoid the use of an temporary variable. But the concept remains the same, don't call the functions you want to choose between, rather invoke the function returned by choose().
ohhhh okay, thank you for your help!
 
Top