Instance_exists undefined?

K

Kieran Hayns

Guest
Im creating an RTS.

The screen has a control panel.

Yoi select the unit and then when you select the options on the panel it applies to that unit (move, stop, attack move etc)

However when there isent a selected unit or the currently selected unit has been destroyed i want the buttons on the panel to be unusable until a new unit.is selected.

I kept it simple as the control panel stores the Unit_Selected variable and when the button is pushed it says

If instance_exists(Unit_Selected)
{
Do stuff
}

I have also done this as Unit_Selected.id


The problem:

When the unit exists it works however when the instance is destroyed a d i push a button it returns it as undefined rather than as false.

I swear ive done this loads of times and it has worked. What am i doing wrong?
 

curato

Member
what you want to do is when you handle destroying the instance you want to check if it is currently the Unit_Selected and if so set Unit_Selected = noone prior to destroying the instance then your instance_exists should work properly.
 

NightFrost

Member
what you want to do is when you handle destroying the instance you want to check if it is currently the Unit_Selected and if so set Unit_Selected = noone prior to destroying the instance then your instance_exists should work properly.
When done in that manner, OP could then simply check if(Unit_Selected != noone) instead of using instance_exists().
 
Top