• 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 virtual buttons not getting created

Y

Yvalson

Guest
so I have virtual buttons that get created at the creation of the room. these are the movement buttons as well as the talk and inventory button.

Code:
/// draw controll keys
switch (In_Inventory)
{

case 0: {   
    Talk = virtual_key_add(800, 430, 128,128, ord("S"))

    up = virtual_key_add(128, 420, 128, 128, vk_up)   

    down = virtual_key_add(128, 580, 128, 128, vk_down)
    
    left = virtual_key_add(48, 500, 128, 128, vk_left)   
    
    right = virtual_key_add(208, 500, 128, 128, vk_right)
          
    spell_button = virtual_key_add(960, 570, 128, 128, ord("M"))
  
    inventory_button = virtual_key_add(1086, 570, 128, 128, ord("N"))
    
    attack_button = virtual_key_add(1016, 430, 160, 160, vk_space)           
    } break;


case 1: {

    inventory_button = virtual_key_add(1086, 570, 128, 128, ord("N"))
} break;
}
I first create all the buttons but in the second frame some get deleted. that is done by the following code:

Code:
///Battlecheck
if(global.In_Battle || global.In_BossBattle){

    if(attack_button = 0){
        attack_button = virtual_key_add(1016, 430, 160, 160, vk_space)
    }
  
    if(spell_button = 0){
        spell_button = virtual_key_add(960, 570, 128, 128, ord("M"))
    }
    if(up != 0){     
        virtual_key_delete(up)
    }
    if(down != 0){
        virtual_key_delete(down)
    }
    if(left != 0){
        virtual_key_delete(left)
    }
    if(right != 0){     
        virtual_key_delete(right)   
    }
    if(Talk != 0){
        virtual_key_delete(Talk)
    }
}

else if(!global.In_Battle || !global.In_BossBattle){
    if(up = 0){
        up = virtual_key_add(128, 420, 128, 128, vk_up)
    }   

    if(down = 0){
        down = virtual_key_add(128, 580, 128, 128, vk_down)
    }
  
    if(left = 0){
        left = virtual_key_add(48, 500, 128, 128, vk_left)   
    }
  
    if(right = 0){   
        right = virtual_key_add(208, 500, 128, 128, vk_right)
    }
  
    if(Talk){
        Talk = virtual_key_add(800, 430, 128,128, ord("S"))
    }
  
    if(attack_button != 0){
        virtual_key_delete(attack_button)
    }
    if(spell_button != 0){
        virtual_key_delete(spell_button)
    }
}
I draw them using this code:

Code:
if(In_Inventory == 0){
  
    if(global.In_Battle || global.In_BossBattle){
        draw_sprite(Spr_Use_Attack, 0, 1016, 430)
        draw_sprite(Spr_Use_Spell, 0, 960, 570)               
    }
    else if(!global.In_Battle || !global.In_BossBattle){
        draw_sprite(Spr_Move_Up, 0, 128, 420)
        draw_sprite(Spr_Move_Down, 0, 128, 580)
        draw_sprite(Spr_Move_Left, 0, 48, 500)
        draw_sprite(Spr_Move_Right, 0, 208, 500)
        draw_sprite(Spr_Talk, 0, 800, 430)
    }
  
    draw_sprite(Spr_Use_Inventory, 0, 1086, 570)
}
but for some reason it doesn't work (the virtual buttons the drawing works fine)

I also wanted to know if I can check if a virtual button exists and only delete it if it exists (thats for entering the inventory because based on in which state the player is (battle or not) different virtual buttons are created.
 

jo-thijs

Member
so I have virtual buttons that get created at the creation of the room. these are the movement buttons as well as the talk and inventory button.

Code:
/// draw controll keys
switch (In_Inventory)
{

case 0: {  
    Talk = virtual_key_add(800, 430, 128,128, ord("S"))

    up = virtual_key_add(128, 420, 128, 128, vk_up)  

    down = virtual_key_add(128, 580, 128, 128, vk_down)
   
    left = virtual_key_add(48, 500, 128, 128, vk_left)  
   
    right = virtual_key_add(208, 500, 128, 128, vk_right)
         
    spell_button = virtual_key_add(960, 570, 128, 128, ord("M"))
 
    inventory_button = virtual_key_add(1086, 570, 128, 128, ord("N"))
   
    attack_button = virtual_key_add(1016, 430, 160, 160, vk_space)          
    } break;


case 1: {

    inventory_button = virtual_key_add(1086, 570, 128, 128, ord("N"))
} break;
}
I first create all the buttons but in the second frame some get deleted. that is done by the following code:

Code:
///Battlecheck
if(global.In_Battle || global.In_BossBattle){

    if(attack_button = 0){
        attack_button = virtual_key_add(1016, 430, 160, 160, vk_space)
    }
 
    if(spell_button = 0){
        spell_button = virtual_key_add(960, 570, 128, 128, ord("M"))
    }
    if(up != 0){    
        virtual_key_delete(up)
    }
    if(down != 0){
        virtual_key_delete(down)
    }
    if(left != 0){
        virtual_key_delete(left)
    }
    if(right != 0){    
        virtual_key_delete(right)  
    }
    if(Talk != 0){
        virtual_key_delete(Talk)
    }
}

else if(!global.In_Battle || !global.In_BossBattle){
    if(up = 0){
        up = virtual_key_add(128, 420, 128, 128, vk_up)
    }  

    if(down = 0){
        down = virtual_key_add(128, 580, 128, 128, vk_down)
    }
 
    if(left = 0){
        left = virtual_key_add(48, 500, 128, 128, vk_left)  
    }
 
    if(right = 0){  
        right = virtual_key_add(208, 500, 128, 128, vk_right)
    }
 
    if(Talk){
        Talk = virtual_key_add(800, 430, 128,128, ord("S"))
    }
 
    if(attack_button != 0){
        virtual_key_delete(attack_button)
    }
    if(spell_button != 0){
        virtual_key_delete(spell_button)
    }
}
I draw them using this code:

Code:
if(In_Inventory == 0){
 
    if(global.In_Battle || global.In_BossBattle){
        draw_sprite(Spr_Use_Attack, 0, 1016, 430)
        draw_sprite(Spr_Use_Spell, 0, 960, 570)              
    }
    else if(!global.In_Battle || !global.In_BossBattle){
        draw_sprite(Spr_Move_Up, 0, 128, 420)
        draw_sprite(Spr_Move_Down, 0, 128, 580)
        draw_sprite(Spr_Move_Left, 0, 48, 500)
        draw_sprite(Spr_Move_Right, 0, 208, 500)
        draw_sprite(Spr_Talk, 0, 800, 430)
    }
 
    draw_sprite(Spr_Use_Inventory, 0, 1086, 570)
}
but for some reason it doesn't work (the virtual buttons the drawing works fine)

I also wanted to know if I can check if a virtual button exists and only delete it if it exists (thats for entering the inventory because based on in which state the player is (battle or not) different virtual buttons are created.
I'm not sure if this is the only problem, but you don't reset variables like up to 0 when you delete the virtual keys.
I also think 0 is a possibe virtual key index, so you shouldn't use the number 0 to indicate the abscence of a virtual key.
Use something like -1 or undefined instead.
 
Top