ID:68432
 
Keywords: article, proc, topic, tutorial
Welcome to my first installment of Noob teaches Noob, where I teach fellow DM coding newbies some interesting tricks even though I'm not that good at DM programming myself.

What's this Topic proc? I wish I knew a long time ago. Here's a screenshot of it:



It's not a link to a website, it's something that causes whatever you want to happen in your game when it's clicked. Like there, clicking "New Game" would start a new game if you coded it in, and clicking "Continue" would let you load a saved game if you coded that in.

Just think of the uses! You could make a verb that let's a user create a poll to the world, and the other users could just click what they want to vote for. You could have your players pick a theme song and have your "Who" verb have a link that plays that person's theme song to the user. Those two options are the two ways I've used topic so far in my projects, they're the first uses I thought of.

Question: OMG!!!!!!!!! THATS KEWL ITS LIKE BYOND CODE TURNED HOLLOW ICHIGO SSJ 3 - BUT NOW HOW CAN I DO THAT PLZ!?!??

Well, here's that exact example in DM code.

usr << "WELL CUMMED 2 NOOB WORLD.  Would you like to start a <a href=?New>New Game</a> or <a href=?Con>Continue</a>?"


Question: WTF I PASTED THAT CODE IN MY GAME AND SAID I CODED IT MYSELF BUT NOTHIN HAPPENED WHEN I CLICKED THE WORDS, HELP PLZ :(???

Yes, now that you created those topic links, the next part is creating what they link to.

What links from clicking the text to the coding that happens from it is the "keyword." Well, that's not the official term (if there even is one,) but that's what I'll call it in this article.

Understanding what the keywords are is important in the link from the text to the code, so I'll show you what the keywords I speak of are for the example I gave above:



Now, using the keywords for the part of the code that checks what Topic text was clicked, let's put together the code that happens when the text is clicked. ...Well, I will, anyways.

client/Topic(href) //This is how Topic goes when used this simply.  Required to the max!
if(href == "New") // This checks what keyword was used when a Topic text was clicked by a user. This checks if the keyword was the New keyword and does the following if so.
// Since this is for a new game, just pretend there's some code here that sets up a new game. I didn't put in any so that I don't confuse you.
usr << "Welcome to the game, new timer!" //Outputs this text to the user if the clicked Topic text's keyword was New

if(href == "Con") // This time it checks if the Topic text that was clicked's keyword was Con and does the following if so.
// Let's just pretend once more that there's a bunch of code here that loads the game. It's pointless for this article, so yeah.
usr << "Game loaded!"
return ..() // Remember to put this at the end of Client/Topic(href) or else you may run into conflicting problems in the future.


Now it's complete.

Except that technically it isn't. As it is there, the user could "start a new game" or "continue" over and over and over again at any time by clicking the text again.

You'd have to prevent that is all. I didn't include it at first to make it more simple, but here's what the href == "New" part would look like with this new checking progress:

client/Topic(href)
if(href == "New")
if(usr.Check != 1)
usr.Check = 1
usr << "Welcome to the game, new timer!"
else
usr << "You already started a new game. Reset the game first if you wish to start over."


I could end this here, but me and you are flippin' floppin' NOOBZ probably, so I'll run through this once more.

usr << "Which job would you like to play as?<br><br>1. <a href=?Cop>Officer</a><br>2. <a href=?Killer>Killer</a><br>3. <a href=?Healer>Medic</a><br><br>Choose wisely!"


That looks like this in the game, if you'd like to see:



But anyways, now to question you!

Look at the coding for that again. What's the format like for linking text to code?

This:

<a href=?INSERT-KEYWORD-HERE>Linked text</a>


Okay okay, this time you really will have to look at that one code above for this question. What were the 3 keywords in it?

...*Jeopardy music plays*

Gawd, you lazy noob, I bet you didn't really try, but the answers are "Cop," "Killer," and "Healer."

Question: "Well then, good sir, I now type intelligent thanks to your article. Now then, remember when you showed the code for when New Game or Continue were clicked? Well, what would it look like if you also had the Officer/Killer/Medic code, too?"

My my, young chap. Here it is,

WAIT, MY FELLOW NOOB, BE WARNED! Once again it only checks if the user should be allowed to click over and over for only "New Game," simply to make this code more simple to you. If this were to actually be in a project, one would have to have more checking for each Topic thingy! Alas, here is what it would look like in a game without the checking:

client/Topic(href)
if(href == "New")
if(usr.Check != 1)
usr.Check = 1
usr << "Welcome to the game, new timer!"
else
usr << "You already started a new game. Reset the game first if you wish to start over."

if(href == "Con")
usr << "Game loaded!"

if(href == "Cop")
usr.icon = 'Police Ham.dmi'
usr << "Go bust some criminals, man!"

if(href == "Killer")
usr.icon = 'Murder Guy.dmi'
usr << "Go kill some people, it's fun!"

if(href == "Healer")
usr.icon = 'Medic.dmi'
usr << "Go heal some people, it's submissive."
usr.verbs += /mob/commands/verb/Heal

return ..() // Remember to put this at the end of Client/Topic(href) or else you may run into conflicting problems in the future.


That is all.

Random BYOND guy that isn't a noob: "Uhm... What about the whole

mob/Topic(href,href_list[])


and all of the other uses of Topic? Seriously... There's way way more to Topic than you just explained, you know."


My answer: OMG I DUNNO IM A NOOB 2 LOL, I literally just learned about the "Topic" proc the day before this day that I wrote this article. Apparently, that way of using Topic that I just mentioned is very, very useful and lots of libaries like the HTML form libary and lots of games use it. But I'm a gigantic noob myself, that use of Topic sounds too complicated to me and I don't understand it at all right now.


Anyways, that is all for now. The first in my series of articles of nifty DM tips and tricks that are "for noobs, by a noob."

COMING SOON: A link to a libary/demo/whatever that I'm going to put on here that uses Topic in the two ways I mentioned at the very beginning here (making a Poll in your game that other users vote in, and having a theme song in Who.)
Good introductory article. Even though this is an article for beginners, I think it's important to point out that redefining client/Topic isn't generally a good idea. Instead, you can send the topic to any object you want. How do we do that? Instead of just putting our 'keyword' after the question mark, we're going to also tell the game what object we want to send the keyword to:

Instead of this:
?keyword

we'll do this:
?src=\ref[character_creation];keyword

Notice where it says \ref[]? Anything that we put between those [] will be the object that will get the keyword in its own topic proc. So, you could create a special object to deal with character creation, redefine it's own Topic() proc to check for "new" and "con" keywords, and then handle everything right there.

Even better, now you don't need a check var for every mob. Give the check variable to the character_creation object. Then, when the player selects new or con, set the character_creation's check variable to TRUE, or just delete the object.
The object to call Topic() on must actually be designated by the 'src' parameter, otherwise any random object reference you tried to pass would be treated as the hsrc. But it doesn't look like this guy actually learned about parameter format yet, so I'll quickly go over it.
It basically boils down to:
name=value&name2=value2&name3=value3
The parameter 'name' is given the value of 'value', etc. Giving parameter's values is optional, as you've seen yourself. You can also use semicolons (;) as the separator instead of ampersands (&). You can read more about that in params2list()'s ref entry.
So to pass the topic call to another object like IainPeregrine said, you'll use a topic link like so:
'?src=\ref[Object]&MyParameter=MyValue&anotherparam'
When the link is clicked, Topic() will be called on "Object" with the parameters.
EDIT: Damn, the comments template has quirks with posting HTML code. >.<
I don't understand any of that or (especially, more specifically) the purpose of doing any of that, cuz I am a noob =(.
Nice Job!