ID:138924
 
Code:
                                                for(var/Buildings/Bed/A in world)
spawn(20)
var/obj/B=pick(A)
src.loc=locate(B.x,B.y-1,B.z)
return


Problem description: This may possibly be a BYOND bug.

For some strange reason, the player and anyone next to him/her gets teleported to the bed(B). What should be happening is just the player gets located to the bed. I've tested just setting a specific location(e.g. 1,1,1) and that works just fine. I don't know if I'm doing something wrong or if it's a BYOND bug.

Show us the whole piece of code, it's indented as if in a larger block, and there's a lot of stuff missing.

Also, looping through every instance of one type of object is a very bad idea. Not to mention you're using pick() on a building/bed, pick only works on list.

simply using a list of all the beds and the world and picking from it would be easier; i.e:
bed
New()
.=..()
beds+=src
//... later in the code
spawn(20)
var/bed/bed = pick(beds)
src.Move(locate(bed.x,bed.y,bed.z))

That would produce the same thing.

My guess is you need to unindent the "return" one tab.

But if you want it to pick a random bed, you'd do something like this:

var/list/beds = list()
for(var/Buildings/Bed/A in world)
beds += A

var/obj/B = pick(beds)
src.loc = locate(B.x, B.y - 1, B.z)
In response to Forum_account
Ah thank you both :)
In response to AbdelJN
nevermind.. same results.. and it's strange because I have a client check to check if the player being transported is connected to a client and isn't an npc, yet the npc gets transported too.. im starting to believe its a byond bug now..
In response to AbdelJN
Give us all of the code. It is most likely not a BYOND bug.
In response to ANiChowy
ANiChowy wrote:
Give us all of the code. It is most likely not a BYOND bug.

the rest is irrelevant, trust me.
var/list/beds = list()
for(var/Buildings/Bed/A in world)
beds += A
var/obj/A = pick(beds)
src.loc = locate(A.x,A.y-1,A.z)
return


if that produces the same results the rest is very relevant
In response to AbdelJN
You'd be surprised, now hand it over! >:O