ID:1691656
 
Code:
mob
var
roomentered=0
area
teleports
roomone
Entered(var/mob/M)
Enter(0)
usr << "You've Entered"
Exited(var/mob/M)
Enter(1)
usr << "You've left"</b>


Problem description:So i'm trying to create a private section of the game limited to only 1 person at a time. What i'm going for is a room that when you enter, the spot is then not accessible for anyone else. i'm kinda new to byond coding creating from scratch so i'm not completely up to par with all the function and such byond had to offer but, you can see my code above and hopefully give me some advice on how to do this? Also i'm not sure if i'm using the Enter() function correctly.

(Edit) Cleaned up a lot of the code to make it simpler for what i want
So i totally just figured it out, i found something similar on another thread which helped a lot!
turf
roomenter
Enter(mob/M)
if(src.owner.len==0)
switch(alert(M,"Do you wish to enter this room?","NFS","Yes","No"))
if("Yes")
M<<"Goodluck!"
src.owner.Add(M.key)
return 1
if("No")
return 0
else
if(M.key in src.owner)
return 1
src.owner.Remove(M.key)
else
M<<"It is not your turn!"
return 0

turf
var
saveX = 0
saveY = 0
saveZ = 0
list
owner = list()
Nice improvement. The first snippet did use Enter wrong and also misused usr.

A problem with your new snippet, though: return stops the proc. It's keeping you from removing from the list.

A switch() for only 2 outcomes is pretty unnecessary, but it makes no difference. Same goes for "src." in front of your src variables.
i did some more imporvement and some debugging and i got this as my final result for the time being
 turf
portals
gtai1
icon = 'Doors.dmi'
icon_state = "gtai1"
density = 1
Enter(mob/M)
if(src.owner.len==0)
switch(alert(M,"Do you wish to enter this room?","NFS","Yes","No"))
if("Yes")
M<<"Goodluck!"
src.owner.Add(M.key)
M.loc=locate(23,175,2)
return 1
if("No")
return 0
else
if(M.key in src.owner)
return 1
src.owner.Remove(M.key)
else
M<<"It is not your turn!"
return 0
Exit(mob/M)
switch(alert(M,"Are you finished?","NFS","Yes","No"))
if("Yes")
M<<"Awesome!"
src.owner.Remove(M.key)
M.loc=locate(21,175,2)
return 1
if("No")
return 0


turf
var
saveX = 0
saveY = 0
saveZ = 0
list
owner = list()
In response to Sempaialexeo
Let me guess... locate(23, 175, 2) is to the right of the portal, and locate(21, 175, 2) is to the left of the portal?

As a general rule, using 3 number constants in locate() is bad because you probably mean "relocate to the tile to the left or right of this one", which is a rule that "makes sense", as opposed to "relocate to the tile at these arbitrary coordinates", which isn't always appropriate and more importantly, would never even make sense to anyone reading the code who isn't simultaneously looking at the map.
// to get the tile to the right of src you could do
locate(x + 1, y, z)

// or more legibly
get_step(src, EAST)

// and similar for the tile to the left

You could even figure out a more general rule for what direction the get_step() should use based on:
- how you're stepping on the portal (from what direction), or
- who may be in 'owner' when you try to step on the portal.
Oh thank you for that! I was actually looking for something as simple as that but in my groggy sleepless state nothing was really making sense anymore so i gave up and went with what was the most simple for me. I'll do some changing and see where that gets me ^.^

*Edit*
Problem completely resolved, thank you Kaiochao