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

[sorted out]walking through arrays

RODO

Member
hello guys, i have a doubt about arrays. I am making a system of skills for a wizard, he will exchange for skills using buttons on the keyboard and thus switching between his powers, and I am using an array to load each power (code below for better understanding):
GML:
//Create Event
//magic system
enum spells {
    spell_fogo,
    spell_bola_magica,
    spell_esfera_eletrica
}

qual_spell_estou = 0;

blocos_spell = [spells.spell_fogo,spells.spell_bola_magica,spells.spell_esfera_eletrica];

//Step event

//choosing magic
if(keyboard_check_pressed(vk_up))
{
    qual_spell_estou++;
}
else if(keyboard_check_pressed(vk_down))
{
    qual_spell_estou--;
}
show_debug_message(qual_spell_estou);
switch(qual_spell_estou)
{
    case 0:
    if(mouse_check_button(mb_left))
    {
        instance_create_layer(obj_player_2.x,obj_player_2.y,"disparos",obj_bola_fogo);   
    }
    break;
    case 1:
    if(mouse_check_button(mb_left))
    {
        var bola = instance_create_layer(obj_player_2.x,obj_player_2.y,"disparos",obj_bola_fogo);
        bola.image_blend = c_green;
    }
    break;   
}
well, does this system you use work? yes, and well what i wanted but i would even more like it to be through the array, walking through its information and not using any variable and a swtch case.

Here I come to ask for help, is there any way I can walk around the array and get information from it? if you can give me any tips or help me with some information I really appreciate it
 

chamaeleon

Member
You need an index variable to modify. Arrays do not maintain any kind of current position. "Walking around the array" implies you are managing an index variable one way or the other. Some if this could be hidden in as a black box implementation in a struct, of course, using up() or down() functions to modify an internal variable to struct.
 

RODO

Member
You need an index variable to modify. Arrays do not maintain any kind of current position. "Walking around the array" implies you are managing an index variable one way or the other. Some if this could be hidden in as a black box implementation in a struct, of course, using up() or down() functions to modify an internal variable to struct.
well, I tested what you said and it worked. Not exactly but the logic was on top of that, I am satisfied with the result, thank you very much
 
Top