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