ID:148047
 
I have made buttons that when u click them, it changes icon.
you can only click 1 at a time and you have to unclick that one to select another. I want to make things that only happen if a certain button is selected

My coding to do this is like....



if(active == "attack")
stuff that happens

attack is name of button
active is var that names the selected button

I have also tried....

if(active == /obj/buttons/attack)
stuff that happens


neither seem to work but if i do a message to the usr like....

usr << "[active] is selected"

..when "attack" is clicked it says....

"the attack is selected"

so it recognized what active was but how do i make the correct "if" statement to make this work??

thank you for your time!!!!!
make a var for selected like obj/var/selected=0, then when you click the obj put this, src.selected == 1. Then you could make a proc to check if it's selected and what is selected.
mob/proc/check()
for(var/obj/blah/o in usr.client.screen)
if(o.name=="blah"&&o.selected==1)
Execute what ever you want it to.

I hope that made some sence.
In response to Zaltron
hey thanks for the speedy reply!

I did something like that earlier but it took a long time and got messed up. I'll try your way but i dont really understand it. im a 2 week rookie

mob/proc/check()
i know thats the directory and the proc name


for(var/obj/blah/o in usr.client.screen)
um i dont really understand this...

if(o.name=="blah"&&o.selected==1)
neither do i this... um... &&? what does that do?

Thanks for the advice but i really like to know what im doing so i can dont have to keep bothering the veterans here
In response to Xallius
i found another way

i made a new var called optioncode and one called code

then i gave each option's code a number

so if i want the first option, i just say if optioncode == 1


thanks for the advice ! and plz tell me your opinion of this approach!
In response to Xallius
Xallius wrote:
i found another way

i made a new var called optioncode and one called code

then i gave each option's code a number

so if i want the first option, i just say if optioncode == 1


thanks for the advice ! and plz tell me your opinion of this approach!

Sounds like a good approach to me.