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

]Kinda solved[Trying to understand what's wrong here!

D

Doooooli

Guest
So I'm stuck! I'm trying to figure out how to rewrite this so it does not spam each of these objects each steps! Maybe you can help?

This is my code:
Code:
if obj_menubar_gui.shown = true
{
    instance_create(view_xview+450,view_yview+10,obj_menubar_inventory);
    instance_create(view_xview+510,view_yview+11,obj_menubar_spelllist);  
}
else if instance_exists(obj_menubar_inventory) && instance_exists(obj_menubar_spelllist)
    {
   
    }
else
{
    if obj_menubar_gui.shown = false
    {
        instance_deactivate_object(obj_menubar_inventory);
        instance_deactivate_object(obj_menubar_spelllist);
    }
}
I know that this code that I have now does not deactivate the objects if menubar is false, that's an easy fix! But the problem is when the gui's shown is set to true it's suppose to just spawn 2 objects, and it does, but it spawns those particular objects each step until the game lags out :p

How can I rewrite this so when obj_menubar_gui.shown = true it will only spawn 2 of those objects and nothing more? :)

thx
 

kamiyasi

Member
Naturally that code block will spawn two items every step because .shown is never set to false.
You would want something like this.

if obj_menubar_gui.shown == true
{
if !instance_exists(obj_menubar_inventory) && !instance_exists(obj_menubar_spelllist)
{
instance_create(view_xview+450,view_yview+10,obj_menubar_inventory);
instance_create(view_xview+510,view_yview+11,obj_menubar_spelllist);
}
instance_activate_object(obj_menubar_inventory);
instance_activate_object(obj_menubar_spelllist);
}
 
D

Doooooli

Guest
Naturally that code block will spawn two items every step because .shown is never set to false.
You would want something like this.

if obj_menubar_gui.shown == true
{
if !instance_exists(obj_menubar_inventory) && !instance_exists(obj_menubar_spelllist)
{
instance_create(view_xview+450,view_yview+10,obj_menubar_inventory);
instance_create(view_xview+510,view_yview+11,obj_menubar_spelllist);
}
instance_activate_object(obj_menubar_inventory);
instance_activate_object(obj_menubar_spelllist);
}
Thx for your reply, I forgot to add that vital part I think! .shown is set to false! you see when I start up my game it's set to true (it shows the menubar) and when I press alt the menubar dissapears and shown is set to false :)
 
B

Blakkid489

Guest
In my experience with this, I used another variable to change while my main variable is doing its thing

exp

Code:
if obj_menubar_gui.shown = true && can_show = true
{
    //do this
    can_show = false;
}
So make a variable in the create event called can_show = false and try that.

I'm sure there's an easier and more efficient way of doing this but this has always helped me
 
D

Doooooli

Guest
In my experience with this, I used another variable to change while my main variable is doing its thing

exp

Code:
if obj_menubar_gui.shown = true && can_show = true
{
    //do this
    can_show = false;
}
So make a variable in the create event called can_show = false and try that.

I'm sure there's an easier and more efficient way of doing this but this has always helped me
Thx I'll go with that for now :)
 
Top