ID:1499016
 
(See the best response by LordAndrew.)
Code:
mob/Login()
usr.icon='player.dmi'
usr<<'Under Siege.ogg'
src.addname("[src.key]")
usr.icon_state="default"
usr.loc=locate(7,8,1)
maxplayers += 1
if(maxplayers > 8)
alert("Enjoy the game.")
world <<"[usr] has joined the game!"
else
if(maxplayers == 8)
alert("This server is full. Go find another homie.")
del usr

mob/Logout()
world <<"[usr] has left the game."
maxplayers -= 1
del src


Problem description:

I'm trying to make a competitive take on the floor is lava which is a pretty common game for children. Wondering if this player limit code is correct. Haven't actually gotten around to testing out 8 people at once though.

Best response
Your snippet won't work I'm afraid. In pseudo-code, you're saying:

if there are more than eight players:
let another person in!

otherwise if there are exactly eight players:
sorry you can't play


Which is... entirely opposite of what you're wanting to do.

I would also advise against using src and usr in the same context, as they won't always be the same thing. usr in Login() is in itself not a very good practice.
Hi!! :D how are u?

Well, your code doesn't make much sense sorry ( you probably were just distracted)... Try to replace it with the code above:
    if(maxplayers < 8)//IF the number of players is less than 8
alert("Enjoy the game.")
world <<"[usr] has joined the game!"
else
if(maxplayers => 8)//IF the number of players is higher or equal to 8
alert("This server is full. Go find another homie.")
del usr



I hope that i helped

,MistY,
Thanks guys!
In response to Misticone
Misticone wrote:
         if(maxplayers => 8)//IF the number of players is higher or equal to 8


I think you're wanting the >= operator there. => means nothing in DM.
In response to LordAndrew
That fixed the code. Thanks.
In response to LordAndrew
Oh yeah XD i want the >= operator thanks ;)
Also, the line if(maxplayers => 8) is redundant. Else covers it completely. It adds no value being there.

:)

Including an alert statement allows a user to stay connected until the alert is passed. It may be more desirable to use an interface element for this reason.
In response to Pirion
Yeah, i know that u could replace it with else but if i did that then manio wouldn't know very well what and where was his mistake.
,MistY
Not simplifying logic introduces bugs when you modify code down the road. Maybe he wants to allow 6 people in...now he has to update two places opening a hole for bugs.

Simplify everything.
In response to Misticone
I think we can safely assume that programmers know what "else" does, even if you don't.
I got it all sorted now. Thanks.
In response to Kaiochao
:( sorry...I know what "else" does, if i didn't use it in the right way then you should give me advices...not criticise (""even if you don't."").

Notice that i copied the code that manio posted and i replaced bits of code, so it would work as he wanted.

Of course i could just put "else" and not an "else if" statement. But I thought that it would be better to explain manio's mistakes in his own code... i dindn't want to make big changes, I just wanted him to understand where he did the mistakes....

obviously i could just do this:
  if(maxplayers < 8)//IF the number of players is less than 8
alert("Enjoy the game.")
world <<"[usr] has joined the game!"
else
alert("This server is full. Go find another homie.")
del usr

Sorry, I was just trying to help :(
Misticone, let's fix you up.

  if(maxplayers <= 8)
src<<"Enjoy the game!"
world <<"[src] has joined the game!"
else
src<<"This server is full. Go find another, homie!"
del src


src is singular in the BYOND language. Usr isn't. In-fact, usr should be only used if interacts another mob.

Like, for my game Shoumetsu, if I wanted them to see the other player without all that if there this mob crap...I'll do this!
mob
Click()
if(roundstart==0)return
if(usr.inround==1)return
usr.client.eye = src
usr.client.perspective = EYE_PERSPECTIVE
usr.watching=src


usr would be you interacting with src. So it says, when this mob clicks on 'ME' (but not you) he or she will view me. src means yourself, always. However, usr means the other person doing this to you or other things. Does that make sense?
Here is some well written info on validity of usr:
http://www.byond.com/forum/?post=35932

Yeah, indeed. I completly forgot that. src is the source and usr like u said should be only used if interacts another mob.

Thanks Audio freak and Pirion :D

MistY,