ID:177103
 
Let me explain what im trying to do I have verb attached to an object that I want to use to animate other objects.

verb/Alert_Condition()
set src in view(1)
if(usr.tripoliclear >=1)
switch(input("Set condition alert.")in list("green","yellow","red"))
if("green")
if(tripolialert == "green")
return 0

if(tripolialert == "yellow"||"red")
//TODO: code to replace multiple obj at once

now I have a obj right now in two different locations that I want to replace with another obj in both those locations

for instace I have a obj called greenalert at (3,43,3) and (12,43,3)I want to replace this obj with yellowalert if that is selected.

how can I do this?
Treasurecat wrote:
if(tripolialert == "yellow"||"red")

I didn't read through the problem you're having, but my eyes immediately hit on this line. Totally wrong.

The || operator will make those two parts separate, so imagine this with parentheses around both:
if( (tripolialert == "yellow") || ("red") )
The problem is, "red" will be interpreted as a separate condition, and as a condition it's always true.

There are two ways to do this right:
if(tripolialert=="yellow" || tripolialert=="red")
or...
if(tripolialert in list("yellow","red"))

Lummox JR
In response to Lummox JR
thank you that will save me from having a problem with that in the future however that was not my question please read through my post when you have time.
In response to Treasurecat
Give a tag to the two objects in the map editor, or at runtime (can't be done in the code). Then, use locate("Alert 1") and locate("Alert 2"). Those will return the objects with the tags "Alert 1" and "Alert 2" (without quotes) respectively. Then, you can screw around with them however you see fit.
In response to Garthor
ok here is what ive got so far.

verb/Alert_Condition()
set src in view(1)
if(usr.tripoliclear >=1)
switch(input("Set condition alert.")in list("green","yellow","red"))
if("green")
if(tripolialert == "green")
return 0
if(tripolialert == "yellow")
locate("yellow")
del "yellow"
tripolialert = "green"
if(tripolialert == "red")
locate("red")
del "red"
tripolialert = "green"
if("yellow")
if(tripolialert == "green")
locate("green")
del "green"
tripolialert = "yellow"
if(tripolialert == "yellow")
return 0


my question is what to put after del and whats the best way I can place a new object on the map in the locations of the old obj
In response to Treasurecat
No, var/obj/O = locate("green")

Also, you should just use a single object, and adjust it's name/icon state. So...

var/obj/O = locate("ALERT")
O.icon_state = "green"
O.name = "Green alert"
In response to Treasurecat
Treasurecat wrote:
if(tripolialert == "yellow")
locate("yellow")
del "yellow"
tripolialert = "green"
...
my question is what to put after del and whats the best way I can place a new object on the map in the locations of the old obj

Well, it's not clear what you're trying to delete, so I have no idea what you're on about with the del command. But you can't delete a text string, so that usage of del is incorrect.

Also, you're not using the value from locate() for anything; you're looking up an atom with the tag "yellow", and then doing nothing about it. There's no point to calling locate() at all unless you assign it to something:
var/obj/O = locate("thing")
Contrariwise, this is useless:
locate("thing")
...because you've told the program to look up the tag "thing" and then immediately forget what it found.

Basically you need to have just one object and change its icon_state as needed, which is the gist of what Garthor said. Use a var to keep track of that object, which will be faster than using locate() every time.

Lummox JR
In response to Garthor
ok I think I used the tag incorrectly I tagged both objects on the map as green but when I used the code only one dissapeared.

verb/Alert_Condition()
set src in view(1)
if(usr.tripoliclear >=1)
switch(input("Set condition alert.")in list("green","yellow","red"))
if("green")
if(tripolialert == "green")
return 0
if(tripolialert == "yellow")
var/obj/Y = locate("yellow")
del Y
tripolialert = "green"
if(tripolialert == "red")
var/obj/R = locate("red")
del R
tripolialert = "green"
if("yellow")
if(tripolialert == "green")
var/obj/G = locate("green")
del G
tripolialert = "yellow"
if(tripolialert == "yellow")
return 0

also I did not understand what you mean by use just one obj this is the first time I have ever done anything like this.
In response to Treasurecat
They need to have different tags. Only one can be located with a single locate() proc. That's why I said to tag them "green 1" and "green 2". You also have to set their tags once they are created (putting them in the New() proc is okay, but it would be a pain to get their tags right).
In response to Garthor
my problem is with deleting both taged objects

if("yellow")
if(tripolialert == "green")
var/obj/G = locate(("green1")&&("green2"))
del G
tripolialert = "yellow"

this does not work. I dont know how to set this up so that the verb will delete both tagged objects.
In response to Treasurecat
var/obj/G1 = locate("Green1")
var/obj/G2 = locate("Green2")

if A != B, then can C = A and C = B? I didn't think so.
In response to Garthor
if("yellow")
if(tripolialert == "green")
var/obj/G1 = locate("green1")
del G1
new /obj/alert/yellow1 (3,42,3)
var/obj/G2 = locate("green2")
del G2
tripolialert = "yellow"
if(tripolialert == "yellow")
return 0

how do I add this obj its icon is alert.dmi and its icon_state is yellow1