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

Legacy GM [Solved] Check if sprite index is equal to one of many array values

MaxLos

Member
So.. I'm working on a platformer/fighter and I have my attacks for my characters set up like this:
Code:
//Create Event
basiccombo[1,0] = spr_attack_1;  //Sprite
basiccombo[1,1] = 4; //Frame to chain into next attack

basiccombo[2,0] = spr_attack_2;
basiccombo[2,1] = 3;

basiccombo[3,0] = spr_attack_3;
basiccombo[3,1] = 4;

basiccombo[4,0] = spr_attack_4;
basiccombo[4,1] = 5;

etc...
When the attack button is pressed, I have it check if my sprite_index is any of the array values with a bunch of or statements

Code:
if sprite_index = basiccombo[1,0] or sprite_index = basiccombo[2,0] or sprite_index = basiccombo[3,0] or sprite_index = basiccombo[4,0]
{
    //Do Stuff
}
But as I add more attacks, I see that doing that is becoming less of an option...really don't feel like adding more or's. So I was wondering what would be a better way of doing this? Thank you :) Inb4 really simple solution and I'm just dumb
 

TailBit

Member
ds_map maybe? Then you can look up the attack with:
Code:
combo = basiccombo[? sprite_index]
if combo != undefined {

}
But if one sprite appears more then once it will cause problems
 

MaxLos

Member
ds_map maybe? Then you can look up the attack with:
Code:
combo = basiccombo[? sprite_index]
if combo != undefined {

}
But if one sprite appears more then once it will cause problems
Thanks for the suggestion, ill try that since I don't think I'll have repeating attacks
 

FrostyCat

Redemption Seeker
Like most things you don't want to repeat again, the solution is a script.
Code:
///sprite_in_combo(spr, combo_array, minindex, maxindex)
for (var i = argument2; i <= argument3; i++) {
  if (argument0 == argument1[i, 0]) return true;
}
return false;
Code:
if (sprite_in_combo(sprite_index, basiccombo, 1, 4)) {
  //...
}
 

Yal

šŸ§ *penguin noises*
GMC Elder
Rather than having a hardcoded list for what sprites are connected to which combos, couldn't you add this data in with the rest of the attack data? Sprite, attack power, hitboxes... all the data could be in one place, so you only need to keep track of the current attack (and how far you've progressed through it, using a counter variable) and then you can just look up any data you need using the attack index.
 

MaxLos

Member
Like most things you don't want to repeat again, the solution is a script.
Code:
///sprite_in_combo(spr, combo_array, minindex, maxindex)
for (var i = argument2; i <= argument3; i++) {
  if (argument0 == argument1[i, 0]) return true;
}
return false;
Code:
if (sprite_in_combo(sprite_index, basiccombo, 1, 4)) {
  //...
}
Aw sweet, thanks! Works perfectly!

Rather than having a hardcoded list for what sprites are connected to which combos, couldn't you add this data in with the rest of the attack data? Sprite, attack power, hitboxes... all the data could be in one place, so you only need to keep track of the current attack (and how far you've progressed through it, using a counter variable) and then you can just look up any data you need using the attack index.
Now that you mention it, I probably should have just done that, huh? Dunno why I'm making things more tedious for me..
 
Top