ID:141619
 
Code:
Turn()
for(var/mob/M in world)
pl = list()
pl.Add(M.ckey)
world << pl
var/p1 = rand(1,pl.len)
painter = pl[p1]
for(var/mob/M in world)
if(M.ckey == painter)
world << "<b><big><center>It is [painter]'s turn to paint. You have 1 minute to guess what it is.</center></big></b>"
cword = wordlist[rand(1,wordlist.len)]
M << "The word is: [cword]"
M.muted = 1
M.color = "circle"
M.flood()
M.color = "black"
sleep(600)
world << "<b><big><center>Time is up! The word was: <font color=\"red\">[cword]</font>!</center></big></b>"
for(var/mob/Mm in world)
if(Mm.ckey != M.ckey)
world << "[Mm] earned [M.rps] points this round."
rrps += 1
Mm.rps = 0
Mm.muted = 0
if(rrps)
world << "[M] has earned 20 points this round."
M.points += 20
M.muted = 0
else
world << "[M] has earned 0 points this round."
M.muted = 0
turns += 1
if(turns >= 10)
world << "<b><big><center>The game has ended! Here are the scores!</center></big></b>"
for(var/mob/Mmm in world)
Mmm.scoreboard()
Mmm.points = 0
Mmm.rps = 0
gs = 0
rrps = 0
painter = null
cword = null
turns = 0
else
p1 = rand(1,pl.len)
painter = pl[p1]
Turn()


Problem description:

The problem is: the painter never randomizes. Until the game is started again.

You could pick the painter with pick()
painter = pick(pl)

Just a tip for the future when dealing with picking a random entry in a list.

And look back at your first loop:
        for(var/mob/M in world)
pl = list()
pl.Add(M.ckey)

What you are doing here is, everytime the loop is looped, pl is initialized back to null with the entry being the current looped M.ckey (not to mention this may add any NPCs you may have).

In other words, right here what you are doing is keep erasing the list entries and just placing in one value.

My recommendation is to change the above to something like this:
pl = list()
for(var/client/C)
pl += C.ckey

painter = pick(pl)
In response to GhostAnime
I've had some help from testers off the forums, and here's the new code.

Turn()
painter = pick(pl)
for(var/mob/M in world)
if(M.ckey == painter)
world << "<b><big><center>It is [painter]'s turn to paint. You have 1 minute to guess what it is.</center></big></b>"
cword = wordlist[rand(1,wordlist.len)]
M << "The word is: [cword]"
M.muted = 1
M.color = "circle"
M.flood()
M.color = "black"
sleep(600)
world << "<b><big><center>Time is up! The word was: <font color=\"red\">[cword]</font>!</center></big></b>"
for(var/mob/Mm in world)
if(Mm.ckey != M.ckey)
world << "[Mm] earned [M.rps] points this round."
rrps += 1
Mm.rps = 0
Mm.muted = 0
if(rrps)
world << "[M] has earned 20 points this round."
M.points += 20
M.muted = 0
else
world << "[M] has earned 0 points this round."
M.muted = 0
turns += 1
if(turns >= 10)
world << "<b><big><center>The game has ended! Here are the scores!</center></big></b>"
for(var/mob/Mmm in world)
Mmm.scoreboard()
Mmm.points = 0
Mmm.rps = 0
gs = 0
rrps = 0
painter = null
cword = null
turns = 0
else
Turn()


pl is now defined in Login() and Logout(). Login() adds a ckey to pl, and Logout() removes one. However, now that I've removed the first for() loop from Turn(), Turn() doesn't recognize any mob as being the painter. And no, I don't have any NPCs.
In response to Armiris
I think you'll need to typecast it since pl is just a mere text string. You can't turn a text string as far as I'm aware of.
In response to Mizukouken Ketsu
pl is a list. It's defined in var/list/pl.
In response to Armiris
Even then, typecast.

for(mob/M in pl)
In response to Mizukouken Ketsu
pl holds text strings of every players ckey. At the beginning of Turn(), the painter is chosen from pl with pick(). Then, Turn() searches the world for a mob with the same ckey as painter. However, right now Turn() won't recognize anybody as the painter.
In response to Armiris
painter = pick(pl)


for(var/mob/M)
if(M.ckey == painter)
//...


_>
In response to Mizukouken Ketsu
Still doesn't work.
In response to Armiris
Worked fine for me.
In response to Armiris
Instead of adding the mob's ckey in the pl list, why don't you add the mob reference? That way you do not need to loop through the world:
Login()
pl += src


// ...
var/mob/painter = pick(pl)
world << "It is [painter.key]'s turn!"


// Looping through the mobs when the round is over:
for(var/mob/M in pl-painter) // Goes through all mobs in the list excluding the person chosen.

// Here's a second hint: If you have the same thing happening in an if...else if...else (such as M.muted = 0 in your snippet), you can keep them out of the if..else and they'll happen

if(rrps)
world << "[M] has earned 20 points this round."
M.points += 20
else
world << "[M] has earned 0 points this round."
M.muted = 0 // Less typing involved if you look ahead in life.

In response to GhostAnime
I tried what you said, but it gave me an error:

runtime error: list index out of bounds
proc name: Turn (/proc/Turn)
usr: Armiris (/mob)
src: null
call stack:
Turn()
game start()
Armiris (/mob): gamestart()

Here is the new code:

Turn()
var/p1 = rand(1,pls) // pls is a var containing the number of players currently logged in
var/mob/painter = pl[p1]
world << "<b><big><center>It is [painter.key]'s turn to paint. You have 1 minute to guess what it is.</center></big></b>"
cword = wordlist[rand(1,wordlist.len)]
painter << "The word is: [cword]"
painter.muted = 1
painter.color = "circle"
painter.flood()
painter.color = "black"
sleep(600)
world << "<b><big><center>Time is up! The word was: <font color=\"red\">[cword]</font>!</center></big></b>"
for(var/mob/Mm)
if(Mm.ckey != painter.ckey)
world << "[Mm] earned [Mm.rps] points this round."
rrps += 1
Mm.rps = 0
Mm.muted = 0
if(rrps)
world << "[painter.key] has earned 20 points this round."
painter.points += 20
painter.muted = 0
else
world << "[painter.key] has earned 0 points this round."
painter.muted = 0
turns += 1
if(turns >= 10)
world << "<b><big><center>The game has ended! Here are the scores!</center></big></b>"
for(var/mob/Mmm)
Mmm.scoreboard()
Mmm.points = 0
Mmm.rps = 0
gs = 0
rrps = 0
painter = null
cword = null
turns = 0
else
Turn()
In response to Armiris
There are a few different lists here, which makes it difficult to see which one is causing the problem. What is causing that error is you are trying to access a part of a list that doesn't exist usually because the list isn't that long.

What you need to do is this:
Go into dream maker, go to Build, go to Preferences For... and check 'Generate Debugging Information'. That will give you an actual line number of the cause of the error and we can help you further once you post the new error.
In response to AJX
var/mob/painter = pl[p1]


Here's the problem line.
In response to Armiris
The error should be pretty self-explanatory, but I'll explain it in more depth: you're trying to access an index number that is outside of the list's bounds, or limits. This number could either be too low (0 or below) or too high (higher than the amount of items in the list - in other words, its length). So in your case, it could only be too high, since the index used is randomly picked between 1 and a bigger number. You need to limit this higher cap, so the number would never go over the number of elements in the list pl.
In response to Kaioken
pls never goes higher than pl.len. I made sure of that. However, I only testing this code locally, so pls would equal 1. Could this cause a problem?
In response to Armiris
It'd cause a problem if the list contains less than 1 element for some reason. But really, the pls var is very extraneous, when pl.len should already supply its job better, as its guaranteed to be synced with the list and not cause such access problems. So you could use pl.len for the cap, or just switch to using pick() (which is more specialized for this case) instead of rand().
In response to Kaioken
I got Turn() fixed, but now I have a different problem.

obj
circle
icon = 'icons.dmi'; icon_state = "circle"
Click()
if(gs)
if(usr == painter.ckey)
src.icon_state = usr.color
MouseDrag(atom/D)
if(gs)
if(usr.ckey == painter.ckey)
D.icon_state = usr.color


This gives me an error:

DMTest.dm:215:error:painter.ckey:undefined var
DMTest.dm:219:error:painter.ckey:undefined var

When I use if(usr == painter), it won't let me draw. It draws all right if I remove that, but then anybody could paint on the screen.
In response to Armiris
Wherever painter is declared, it's not appropriately defined as of /mob type. Basic stuff.
Also, you should use the && operator when needing multiple conditions, rather than consecutive if()s.
In response to Kaioken
It gives me an undefined type path error when I use if(usr == /mob/painter.ckey).
Page: 1 2