ID:264236
 
proc
labeltext(mob/m, label_id, text, text_color="#000")
if(ismob(m))
winset(m,label_id,"text-color=[text_color]")
winset(m,label_id,"text=\"[text]\"")
else CRASH("You did not specify a mob.")
mob
verb
Who()
set category = "Main"
/*var/tmp/players
for(var/mob/M in world)
if(M.client)
players += 1
usr << "<B>\icon[M][M.key] </b>Level: [M.level]"
usr << "<B>Players online: [players]"*/

var/mob/M
for(M in world)
labeltext(usr,"default.who","Name: [M.name] Level: [M.level] Race: [M.race]")


Problem description:
I can't make the label in the default window list all the players in the world....
Can someone please help me on this.
It only displays my Name, Level and Race.
I need it to display everyones.

Gizhy Games wrote:
I can't make the label in the default window list all the players in the world....
Can someone please help me on this.
It only displays my Name, Level and Race.
I need it to display everyones.

You're calling labeltext() one at a time for each user, so each time it is replacing the text that was there before with brand new text.

If you don't want the label to display only one line of text, then you need to call labeltext() with all of the text you do want it to show.

Lummox JR
In response to Lummox JR
How can I make the labeltext multiply so it shows all the players in the label instead of just me, can you show me a coding of it?
In response to Gizhy Games
You've already been told the issue in your code and how to 'fix' it. What you're doing is constantly setting (read: replacing) the label's text to a given player's, so ultimately only one player (the last one being looped through) is displayed.
You're calling labeltext() in a loop, so it's called multiple times, once for each mob. That proc calls winset(). Let's simplify the for() loop a bit, and visualize it does this:
for(var/mob/M in world)
winset(M,"who",{"text="Name: [M.name] Level: [M.level] Race: [M.race]""})

So, for each mob in the world, it sets the label's text to a given value. Naturally, this overwrites the text previously on the label, since it sets it to a different value.
As said by Lummox, you need to set the full text you want at once; ie a text string containing info about all the players. So you'll only call winset() one time in all.

One of the ways to build such a text string would be to use the +=/+ operator.
In response to Gizhy Games
String concatenation is your friend. Concatenation is a big word that simply means "merging".

BYOND supports a few ways to concatenate strings. One of which is to treat it like a number and use the addition operators

var/string1 = "Dan"
var/string2 = "Tom"
var/string3 = string1+string2


string1 = "Dan" string2 = "Tom" string3 = "DanTom"

This is the longhand equivalent of:

var/string3 = "Dan"+"Tom"


There is another method of embedding variables into text that works much like concatenation.

var/string1 = "Dan"
var/string2 = "Tom"
var/string3 = "[string1][string2]"


This produces the same results.

The brackets are also useful for embedding numbers, etc. into text. Let's look at an example why to use brackets instead of addition concatenation.

var/string1 = "Ter"
var/string2 = 13
var/string3 = string1+string2


Now if you think that string3 is equal to Ter13, you would be wrong. This returns an error. Adding a number to a string causes a type mismatch error. In this case, the addition symbol will not work for concatenation. Let's do it right this time.

var/string1 = "Ter"
var/string2 = 13
var/string3 = "[string1][string2]"


In this case, string3 is "Ter13".

As for more uses of brackets, they allow just about anything to go inside of them, such as proc calls, variables, expressions, etc.

var/string1 = "Ter"
var/string2 = 13
var/string3 = "[uppertext(string1)][string2] [rand(1,100)] [src.level]"


This will return: "TER13 (random number between 1 and 100) (the object's level)"

Any further questions?