Popular Post Kaya Posted October 15, 2015 Popular Post Report Posted October 15, 2015 (edited) For many people who want to make a quest coding is a big hurdle. This tutorial is made to teach all needed to make simple quests in an easily understandable way. The tutorial covers displaying text, reading out user input and saving progress using keys. The result of the tutorial can be seen at the signs at the MBP and at Willow's shop using the keyword secret pass word. In order to make a clicky quest you need to have unlocked the ability to edit clickies. This can be purchased using your third WP, but is also occasionally given out to those deemed worthy.Step 1: Displaying text You can edit a clicky by opening it and clicking on the "edit own" button. Now you will get a screen with 4 text fields: The Title field at the top, the content field at the left, the Script field on the right and the password field at the bottom. In the first step we are just going to display some text. This step is really easy. Simply paste the following text into the content field and press "save&compile". Hello cube! This is the first step. Now you should see your text appear on the screen. While you're at it feel free to add an awesome title and a secret pass word to prevent people from spying on you. Step 2: First code Now let's start coding. For security reasons you need to define from what locations you're allowed to run the script. Right above the code field is a sentence that says something like "Add location setting: (locations 1_0x2_1)" copy the final part including the brackets and paste it on the first line of the code field. Your code won't work without this, so you better don't forget to add it. If there is anything in the code field, the content is no longer automatically displayed. In order to output our text we use the print command, which outputs the following text to the user. In this case we want to output the text from the content box. This text is conveniently saved in the variable @content[0]. Finally the command should be ended with a semicolon which will give us the following code: (locations 1_0x2_1) echo @content[0]; Now save and compile to see your new page. Done? Then you might have noticed something strange; all the enters are gone! This is because your content is now seen as HTML and HTML ignores enters. Instead to add them you should surround each paragraph with <p> and </p>, which will give you the following content: <p>Hello cube!</p> <p>This is the first step.</p> For more on formatting your page take a look at W3Schools. MDScript uses only the part between <body> and </body> Step 3: Interaction Our quest is still a bit boring, so let's add some user interaction. We are going to ask if they are ready to start the quest; if they are we show them some text that will help the player move on to the next part. First I will give you the code and then I will explain what everything does. Add the following at the bottom of the content field: <p>So you want to become a code wizard?<p> <form method="post"> <input type="submit" name="wizard" value="Yes"/> </form> <!-- content separator --> <p>Then go to the sign at Willow's shop to start your training.</p> And add the following code to the bottom of your code field: if(@input["wizard"] == "Yes") { echo @content[1]; } Almost all user input is done through forms, made by surrounding part of your content with <form method='post'> and </form>. In this case the page has one input field of type "submit", which is the code for a simple button. The value of the button contains the text on the button and is send back to the server along with the button's name. The <!-- content separator --> splits up our content in multiple parts so we can display them individually. @content[0] revers to the first part, @content[1] to the second etc. In our server code we can read out the user input using the @input variable. @input[<name>] contains the contains the value of the input field. In this case we look if @input["wizard"] is equal to "Yes". Only if that's the case, the code between the curly brackets is executed and we display the second content block. There are many other types of input on this page. Step 4: Progress You might have noticed that you have the Yes button again every time you open the page. While for the hint this isn't that bad, for our next riddle we don't want to trouble our questees with having to enter their answer again every time, so we're going to save their progress using keys. Below the content for the sign at Willow's shop: <p>The road to becoming a code wizard is hard, so let me test you.</p> <form method="post"> <p>What is 1 + 1? <input type="text" name="answer"/><input type="submit" value="Answer"/></p> </form> <!-- content separator --> <p>Exactly! 1 + 1 = 10, binary! Congratulations on completing your first steps to code wizardry.</p> <!-- content separator --> <p>I'm afraid that's not quite the answer I'm looking for.</p> <form method="post"> <input type="submit" value="Try again"/> </form> And the matching code: (locations 1_1x3_1) if(mds_has_rpcq_keys("SuperDuperSecretCodeKeyAboutBinaryCounting")) { print @content[1]; } else { if(isset(@input["answer"])) { if(@input["answer"] == "10") { print @content[1]; mds_give_rpcq_keys("SuperDuperSecretCodeKeyAboutBinaryCounting"); } else { print @content[2]; } } else { print @content[0]; } } This might seem like a lot of code, but most of the code we have already seen. The only new thing in the content section is the text input field, which (as the name suggests) allows the user to input text. The code once again starts with the locations tag, followed by a check to see if the user already completed the riddle using mds_has_rpcq_keys(). If they did, we show them the 'completed' text, if not, we do some more checks. With isset() we check if there is a value in @input["answer"]. If not, that means the page was just opened and the user hasn't answered the riddle yet, so we show him the riddle. If it is set, we take a look at his answer; if it's correct, we use mds_give_rpcq_keys() to give the player a key. Some more about keys The exact value of the key doesn't matter, it could be "SuperDuperSecretCodeKeyAboutBinaryCounting" or it could be "cat". What does matter is that your key is unique, as everyone's code would be able to check or set your keys if they were able to figure them out. As such "cat" is probably not the best idea. Instead it is recommended that you add a prefix to your key that only you would be able to come up with. For more on keys (for example how to remove them) I suggest you take a look at the MDScript manual's Keys page. As an exercise I'll leave it to you to try and make it in such a way that the riddle won't be visible unless the player has pressed the Yes button in the park and to create a clicky that removes the key to allow you to start all over. And we're done! And with that you have your first quest. Sure it contains only one riddle, but with some creativity this is enough to make a full quest. Any comments, questions and suggestions are highly appreciated. If there is enough interest I might make another tutorial, either a continuation or something more advanced. Edited October 15, 2015 by samon Ungod, Myth, Azull and 9 others 12 Quote
Guest Posted October 4, 2016 Report Posted October 4, 2016 Hi, I would really like to learn coding to help with quest set up and as this topic says I am a complete beginner. This is an awesome thread and very helpful, but it is not compatible with the way I learn something practical D: Does anyone have any advice/websites/time to show me a little the very basics in a more active form? I need to do it myself, practically, and then it will be easy for me. If so, please message me on the forum. I hope I explained myself all right! (Let me say again, there is nothing wrong with samon's post at all. There is something wrong with my brain in the way it learns things!) Quote
DARK DEMON Posted October 4, 2016 Report Posted October 4, 2016 (edited) 2 hours ago, Ailith said: Hi, I would really like to learn coding to help with quest set up and as this topic says I am a complete beginner. This is an awesome thread and very helpful, but it is not compatible with the way I learn something practical D: Does anyone have any advice/websites/time to show me a little the very basics in a more active form? I need to do it myself, practically, and then it will be easy for me. If so, please message me on the forum. I hope I explained myself all right! (Let me say again, there is nothing wrong with samon's post at all. There is something wrong with my brain in the way it learns things!) For those wishing to test stuff by themselves, or try the real deal, I recommend codecademy. MD's language is PHP, so you have to go to that section: https://www.codecademy.com/learn/php Its where I learned the basics from, though it also offers advanced lessons. Edited October 4, 2016 by DARK DEMON Quote
Guest Posted October 4, 2016 Report Posted October 4, 2016 Thank you! Rophs also recommended this! Am trying it now, it is exactly what I needed Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.