I,ve created these worm holes, and I have about 20 of them, now I want to make them connect, but only two at a time, so A connects to B and B connects to A not A then B then C just a two way gate.

The problem is I want it to be randomly generated, I dont wanna code out all of their X,Y,Z cords, so I created some procs but could never get the hang of it.

One of the failed procs was

if(src.GoTo == null)
for(var/obj/WormHoles/WormHole/W in world)
if(W.GoTo == null)
if(W != src)
if(W.z != src.z)
src.GoTo = W.z
W.GoTo = src.z
if(src.GoTo == null)

But for some reason many of the worm holes when entered either take you back to it, or wont work at all, one or two work but thats about it.

Any suggestions or code would be great :)
why not make 2 wormhole types, IN and OUT. In the desc, give them the same desc like "Alpha", "Beta", etc. Then when you enter a wormhole (either IN or OUT) connect it to one with the same desc.
Well, I personally wonder why you're just setting .z... are all the wormholes on different z levels of a map but in the exact same spot? If so, that'll work great. If not, you're just going to be shuffling around what level the player is on the map.

.loc would work if you want to set the player directly on the wormhole's coords regardless of where it lines up.

Anyway... the problem is you're not going through them "at random", you're going through them in order. In other words, if you step in the first wormhole, it will take you to the second... because you're excluding src... and the second one will take you to the first... and the rest will want to take you to the first, too.

[EDIT]Oh, and I just noticed... you're not breaking the for() loop, so for the first wormhole, it's going through EVERY wormhole and setting them to link up to it, then going through to the next one... that's probably what's really screwing it up. Putting a "break" in after it finds a good one will fix that, but again, it won't be random.[/EDIT]

Try doing this...

Make a list, var/list/wormholes = list(). Don't put that "under" anything, you want it to be a global list.

In the obj/WormHole/New(), put "wormholes += src"

Now when the game loads up, you have a list of all wormholes.

Instead of for(var/obj/Worm,etc.)... put
var/obj/WormHole/WormHole/W = pick(wormholes - src)

W now equals a WormHole, other than src.

Then set src.GoTo and W.GoTo, and also put wormholes -= W ... that takes W out of the list so it won't be pulled again.

Again about the Z thing... I would personally make the GoTo var refer to the loc of the WormHole, or even to the WormHole itself... like

src.GoTo = W
W.GoTo = src

And then when you want to move the player to the other WormHole, you do it via Move(src.GoTo.loc) (assuming "src" is the WormHole you entered)