Concatenation issues

Having issues with Concatenation

This works:
Msg("Key: "…k… " Name: "… v:Nick() … "
")

This does not:
Msg(playerlist[1]…"
")

However this does:
Msg(playerlist[1])

What is wrong with the syntax here?

It doesn’t work because playerlist[1] is most likely not a string (player object presumably).
Concatenation only works with strings & numbers.

Just send the function multiple arguments and it’ll join them together internally…

Msg( playerlist[1], ’
’ )

By the way, if you use print rather than Msg it’ll automatically add a newline at the end and separate each given argument with a tab.

so…
print(“Key:”, k, “Name:”, v:Nick() )

Will probably print out neater anyway.

Oh thx, I wondered why some code is using “print” instead of “msg” since they looked like they do the same.
Btw, is it a typo or really ’ instead of " in this part:
Msg( playerlist[1], ’
’ )
Also will print broadcast to all players? Or just the user of the command?

MsgN() is the same as Msg() (as in, it prints in colour instead of white), but automatically puts a
at the end of your message.
I personally use print over Msg, even when Msg would be preferable, simply because the output from Msg doesn’t show up in the onscreen console in developer mode.

’ and " both work the same, I tend to use ’ as it’s quicker to type.

No, print only prints in the instance it was called from, IE if it were called on the server it’s response would be displayed in the server console, likewise if it were called on a client.
Msg is the same.

Use MsgAll if you want it to call it on the server and have the text also mirrored in the client consoles.

If you’re using it for debugging then I use this…

In gamemode/shared.lua…
[lua]
function db( … )
MsgAll( ( SERVER and 'SERVER: ’ or 'CLIENT: ’ ), unpack(arg) )
end
– function db() end
[/lua]

Then you can use the function db( “debug text”, debugVar, whatever ) on both the client and the server and know which is which.
You can also just uncomment the last line to disable debug text being generated.

you do realise … == unpack(arg) and is faster to type/run?

No, but I do now.