ID:147473
 
obj
thing
icon = 'thing.dmi'

obj
thing2
icon = 'thing.dmi'

obj
findthing
icon = 'find.dmi'
verb
Use()
switch(input("This is where the things are") in list ("Thing 1","Thing 2"))


now wit hthat code i want the obj findthing to display the co-ordinates of thing and thing 2. so when i click Use it comes up with a message saying this is where the things are...Thing 1 [x],[y],[z] and Thing 2 [x],[y],[z]

so how would i go about doing that?

if i'm unclear then tell me
All atoms on the map have three variables that contain their x,y,z coordinates, and funnily enough, they're named x,y and z.
mob
verb
Locate()
var/list/objects = new
for(var/obj/O in world)
objects += O
var/obj/Q = input(src,"Which object do you want to locate?","Locate") as null|anything in objects
if(!Q) return
src << "Object \"[Q.name]\" is located at coordinates [Q.x],[Q.y],[Q.z]"
Take note that this relies on the fact that there is always at least one object in the world. I also used a list to add all the objects to, rather than making it a static list of objects with no reference to anything.

On the other hand, if you have a mess of objects with the same name, you can use something to this effect(be careful if there are a LOT of them, you WILL get spammed using this code to a T):
mob
verb
Locate2()
var/list/objects = new
for(var/obj/O in world)
objects += O
var/obj/Q = input(src,"Choose an object.","Locate2") as null|anything in objects
for(var/obj/X in world)
if(X.type == Q.type)
src << "Found object \"[Q.name]\" at coordinates [X.x],[X.y],[X.z]"
This also assumes that there is at least one object in the world.
In response to Enigmaster2002
thanks, i'm using the second but i dont want it to display the co-oridnates of every object. just 10 specific ones.
In response to DeathAwaitsU
bump
In response to DeathAwaitsU
So instead of looping through the entire world, make a list() of the objects that you want to be listed and loop through that instead.
In response to Crispy
not too familar with lists so i tried this:
mob
verb
Locate2()
var/list/L // list reference
L = world.contents // assign to existing list
L = new/list(2) // make a new list
L = new() // make a new list (implicit type)
L.Add(/obj/thing)
L.Add(/obj/thinga)
var/list/objects = new
for(var/obj/O in L)
objects += O
var/obj/Q = input(src,"Choose an object.","[L]") as null|anything in objects
for(var/obj/X in L)
if(X.type == Q.type)
src << "Found object \"[Q.name]\" at coordinates [X.x],[X.y],[X.z]"


when i try to compile it i get no errors and when i use in game i get no erros(you know the ones you get in red with the call stack thing) but the verb didnt do anything at all
In response to DeathAwaitsU
if there's something unclear in my question then please tell me
In response to DeathAwaitsU
DeathAwaitsU wrote:
not too familar with lists so i tried this:
> mob
> verb
> Locate2()
> var/list/L // list reference
> L = world.contents // assign to existing list
> L = new/list(2) // make a new list
> L = new() // make a new list (implicit type)
> L.Add(/obj/thing)
> L.Add(/obj/thinga)
> var/list/objects = new
> for(var/obj/O in L)
> objects += O
> var/obj/Q = input(src,"Choose an object.","[L]") as null|anything in objects
> for(var/obj/X in L)
> if(X.type == Q.type)
> src << "Found object \"[Q.name]\" at coordinates [X.x],[X.y],[X.z]"
>

when i try to compile it i get no errors and when i use in game i get no erros(you know the ones you get in red with the call stack thing) but the verb didnt do anything at all


Something like this should work aswell (It's a more simplified version of the above that should work (Can't test it).

mob
verb
Locate2()
var/T=list(/obj/type1,/obj/type2)
var/object=input(src,"Choose an object.") as null|anything in T
var/L=list()
for(var/obj/O in world)
sleep(-1) //sleep if there are other procedures waiting to execute
if(O.type==object)
src << "Found object \"[O.name]\" at coordinates [O.x],[O.y],[O.z]"


The above follows the same format you used to display the results, but if you have a large number of things that could be returned as results, you may be better off using browse() to display it in the browser...

mob
verb
Locate2()
var/T=list(/obj/type1,/obj/type2)
var/object=input(src,"Choose an object.") as null|anything in T
var/L=list()
var/html=""
for(var/obj/O in world)
sleep(-1) //sleep if there are other procedures waiting to execute
if(O.type==object)
html+="Found object \"[O.name]\" at coordinates [O.x],[O.y],[O.z]<BR>"
if(!html)
html+="No objects were found!"
usr<<browse(html)
In response to Nick231
again i cant have it to work with EVERY obj, just specific ones.

but thx a lot for trying to help, i appreciate it a lot
In response to DeathAwaitsU
nevermind i fixed it on my own. thanks a lot everyone!