ID:179272
 
ok, I have a pop machine object that is two icons tall. Basically, what I want it to do is, when the user clicks on the top, they are asked what flavor. They choose their flavor, then the bottom icon switches to an icon state which makes it look like a pop is in the bottom. The problem is, I don't know how to make the bottom icon state change when you click on the top icon. I will post the code I currently have which doesn't work.
obj
     Top_Pop
          icon = 'pop machine top.dmi'
          density = 1
          proc
               Purchase()
                    var/obj/Bottom_Pop/P
                    for(P in oview(1))
                    if (P.icon_state == "can")
                         usr << "There is already a can of pop waiting for you!!"
                         return
                    switch(input("Choose a flavor of pop. Cost is 50 cents + 10 cent deposit.","Coke Machine!") as null|anything in list("Pepsi","Sprite"))
                         if (null) return
                         if ("Pepsi")
                              usr << "A Pepsi drops to the bottom. Click on it to pick it up!"
                              usr.wealth -= 60
                              for(P in oview(1))
                                   P.icon_state = "can"
                         if ("Sprite")
                              usr << "A Sprite drops to the bottom. Click on it to pick it up!"
                              usr.wealth -= 60
                              for(P in oview(1))
                                   P.icon_state = "can"
          Click()
               Purchase()
     Bottom_Pop
          icon = 'pop machine bottom.dmi'
          icon_state = "no can"
          density = 1
          Click()
               if(src.icon_state == "no can")
                    usr << "There is no pop here!!"
               else
                    usr << "Drinka da pop"
                    src.icon_state = "no can"

Thanks for the help!
I didn't thuroughly read the rest of the code but I think this is the problem code:

var/obj/Bottom_Pop/P
for(P in oview(1))

All you should have to do is change it to this:
var/obj/Bottum_Pop/P
for(P in oview(1,src)) break

If it doesn't seem to work put in some test statements to track what's happening in the procs.

You also don't need those same loops in the switch statement, just use P again.
In response to English
English wrote:
I didn't thuroughly read the rest of the code but I think this is the problem code:

var/obj/Bottom_Pop/P
for(P in oview(1))

All you should have to do is change it to this:
var/obj/Bottum_Pop/P
for(P in oview(1,src)) break

If it doesn't seem to work put in some test statements to track what's happening in the procs.

You also don't need those same loops in the switch statement, just use P again.

ok, it works fine. Thank you very much!!