Trouble making 2-variable Switch-Answered

Q

Qrowin

Guest
Question has been answered, I found something that works.
 
Last edited by a moderator:

Roderick

Member
Switch only accepts one argument. You could have it check (a + b), but not both separately.

You'll just have to use if statements:

if ((xpointer == 0) && (ypointer == 0)) {do stuff}
if ((xpointer == 0) && (ypointer == 1)) {do other stuff}

and so on.
 

FrostyCat

Redemption Seeker
Stop making up imaginary syntax with switch.

Either nest the switches:
Code:
switch (ypointer) {
  case 0:
    switch (xpointer) {
      case 0: plyact=scr_finishingblow; break;
      //...
      case 4: plyact=scr_give; break;
    }
  break;
  //...
  case 2:
    switch (xpointer) {
      case 0: plyact=scr_use; break;
      //...
      case 4: plyact=scr_escape; break;
    }
  break;
}
Or fold the values into one before comparing:
Code:
switch (xpointer+5*ypointer) {
  case 0: plyact=scr_finishingblow; break;
  case 1: plyact=scr_jump; break;
  //...
  case 14: plyact=scr_escape; break;
}
Or in this case particularly, put the scripts into a 2D array and then set plyact with it:
Code:
script_array[0,0] = scr_finishingblow;
//...
script_array[4,2] = scr_escape;
Code:
plyact = script_array[xpointer, ypointer];
 
Q

Qrowin

Guest
Switch only accepts one argument. You could have it check (a + b), but not both separately.

You'll just have to use if statements:

if ((xpointer == 0) && (ypointer == 0)) {do stuff}
if ((xpointer == 0) && (ypointer == 1)) {do other stuff}

and so on.
Well that's disappointing. Oh well, thanks. That's good to know.
 

Nux

GameMaker Staff
GameMaker Dev.
I'm pretty sure you can't have two dimensional switches going on.
Instead, you could create a 2d array, each with a unique value, and the use xpointer and ypointer to get the value at that index.
example:
Code:
# define this on create event
actions[0,0] = scr_finishing_blow;
actions[1,0] = scr_jump;
actions[2,0] = scr_parryup;
actions[3,0] = scr_block;
[...] continue
... then you can simply do:
Code:
plyact = actions[xpointer,ypointer];
(ps. it's better to define an array backwards)
 
Top