Jump to content


Photo

Problem with my Shop-like menu


  • Please log in to reply
1 reply to this topic

#1 _259459

_259459

    GMC Member

  • New Member
  • 7 posts

Posted 28 April 2012 - 09:55 PM

So I have an RTS with a menu that pops up when you click on the base. You are able to select upgrades, allies etc. What I want is for it to build ONE of the item you select
if you have enough money, but for some reason it always builds 2 or 3. I use objects for buttons that are destroyed and recreated every use

BUTTON CREATE EVENT
image_alpha = 0;
over = 0;
ima = 0;
sold = 0;
x = (obj_baseMenu4.x+300)-(sprite_width/2);
y = (obj_baseMenu4.y+200);
ic = instance_number(obj_shield_minion_good);
in = ic+1;

BUTTON LEFT RELEASED EVENT
if (score>=50&&sold=0)
{
instance_create(obj_base_good.x+60,obj_base_good.y,obj_shield_minion_good);
score-=50;
sold=1;

with (obj_baseMenu4)
{
instance_destroy();
}
with (obj_baseMenu4Button1)
{
instance_destroy();
}
with (obj_baseMenu4Button3)
{
instance_destroy();
}
with (obj_baseMenu4Button4)
{
instance_destroy();
}
instance_destroy();

exit;
}

  • 0

#2 FoxInABox

FoxInABox

    GMC Member

  • GMC Member
  • 5392 posts
  • Version:GM:Studio

Posted 29 April 2012 - 01:09 AM

it doesn't seem to be any problems with theese codes you have shown, how is the creation of the menu done? because it can be that you create several identical menu objects on top of eachother, and are thereby clicking on more then one when you click in the menu..

also, you create the shield at obj_base_good.x+60,obj_base_good.y .. I don't know if you plan to have more then one obj_base_good out at the same time, but writing objectname.variable will return that variable from the earliest created instance of objectname .. if you want the one you clicked then you might want to store its id in a variable and use that instead ..

and if you give all menu objects a common parent object, then you can easily destroy them or check if a menu is open by using the parent object .. or automaticly position themself based on how many menu objects there already is in the room when they are created, in case you want to re-use some menu buttons in other menus
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users