ID:292501
 
There's not much point in making an online game if the players can't interact with each other.
This tutorial will show you how to make a few simple verb commands for players to chat with each other, and to see who else is online.
If you haven't already read Tutorial #1 we recommend you begin there.

Creating a verb
A verb is the most basic form of player action in a BYOND game.

Step 1.1 To get started, lets first create a new Code File in our Tutorial Environment named "Verbs.dm"

Step 1.2 Add the following code:
mob/verb
Say(t as text)
view()<<"[src] says: [t]"

What does this do?
It creates a verb called "Say" that is available to all mobs by default.
When you activate this verb you will have to input the variable "t".
The "as text" part determines which input type you will be prompted with.
The verb then outputs "<<" to everyone in view of the player "view()" a message.
You can use brackets [] to easily enclose variables inside a text string.
In this case we enclosed src (the source object of the verb) and t (the message they typed).
We also put our own text " says: " to distinguish this from other chat methods.

Step 1.3 You can now run the game to see this in action (its always nice to see what you've wrote actually doing something =P)

Step 1.4 Lets create another verb, this time for outputting your message to the entire world (game server)
mob/verb
Say(t as text)
view()<<"[src] says: [t]"

//new code below
World_Say(t as text)
world<<"<b>[src]:</b> [t]"

As you can see the World_Say() verb is almost identical to the original Say() verb.
Lets look over the changes made:
The message is now output to "world", instead of to view().
HTML has been used to enhance the message that is output.

Step 1.5 Finally we will create a "Who" verb
mob/verb
Say(t as text)
view()<<"[src] says: [t]"

World_Say(t as text)
world<<"<b>[src]:</b> [t]"

//new code below
Who()
var/counter=0
for(var/mob/Player/M in world)
counter+=1
src<<"[M]"
src<<"<b>[counter] Players Online"

What does it do? lets go line by line:
For starters, you can see this verb has no default input with it, no "t as text" type line
"var/counter=0" declares a local variable named "counter" and initializes it to the numerical value of 0
"for(var/mob/Player/M in world)" will loop through every mob/Player in the world, 1 by 1, assigning them to M
The next 2 lines are tabbed in under the for(), meaning they will happen each time the for() loop assigns a Player to M.
"counter+=1" will add 1 to the counter for each M found in world
"src<<"[M]"" will output M as text to the player, which will be whatever M's name is currently set to.
"src<<"[counter] Players Online"" will output the final count to the user of the verb. Since it is tabbed back out, it will execute only once, after the for() loop has finished.

Contine to Tutorial #3: Variables and Procedures
Lol you think you could tell me how to make my who list display the players in the world for the level? please
In response to Flysbad
The next tutorial shows you how *perfectly on time response*
cant get who to work, i honestly dont know what M is in this and what is stands for, and why it is the reason of my 2 errors and a warning
In response to JustinFoote
M in this case is a variable initialized of the type /mob/Player. The for() procedure loops through all things of the type /mob/Player in the world and then outputs them.

If you're getting runtime errors (it would be helpful to know what the errors are!) I'd have to take a guess you don't have /mob/Player defined in your source.
Im getting the same 2 errors as JustinFoote I get:
loading Verbs.dme
Verbs.dm:11:error: M: undefined type: M
Verbs.dm:13:error: M: undefined type: M
Verbs.dm:11:warning: M: variable defined but not used

any idea how to fix this?
try to see if you capitalized Player or if you wrote it player... that was my problem and thats how i fixed it :P
In response to Falacy
Falacy wrote:
The next tutorial shows you how *perfectly on time response*

Hahaha, Only took you a couple of years Falacy :P
its been a while so I thought I would refresh my memory with a tutorial I got these erors
loading Turtorial.dme
verbs.dm:7:error: counter: invalid proc definition
verbs.dm:8:error: _block: invalid proc definition
verbs.dm:11:error: <<: invalid proc definition
Turtorial.dmb - 3 errors, 0 warnings
In response to Dark sage biko
Could you post the snippet of code that is generating those errors?
I figured it out I didn't have it in the right place under Who() amazing how one can over look something when looking it over 100 times! lol