![]() |
Scripting Tutorial for Beginners
1 Attachment(s)
Okay, i first made this tutorial in a text file, but i thougt it was much more useful to post it here :D
Graal Scripting Tutorial for Beginners v1.0 1. Introduction 2. “if” 3. timeout - *under construction* 4. setting flags and strings - *under construction* 5. triggeraction - *under construction* 1.-Introduction Well, this is the Graal Scripting Tutorial for Beginners I made! Here I will explain you certain basics of GScripting. Just check it out. If something is new/important in a example, it is italic or underlined. Okay, I hope you know how to open the editor. Open Graal, click on training, then when it’s loaded press F4. Now, create a new level. Click on the guy with the black hair and drag it in the field, then click again to place it. Just click on “close” when the window pop-ups. Double-click on a NPC to open the editor. Now, get the NPC to do something! 2.-“if” The if command is practically the most important in Gscripting. If something happens, for example the player touches the npc or says something, a certain event will occur. The script system will recognize this, and if you want the npc to do something when this happens, you need the if command, or some of the others that we won’t discuss here. These events are called “flags”. Okay, go to the empty space and type in if (playertouchsme) message Keep your hands off me!; Now, close the editor and click on “Play” or press P. Now, touch the NPC. It will say something :) As you see, the event is within brackets (). There always is one bracket. Now, off for a longer script. The NPC will push you away and take some of your health. If we have a longer script, we put that in an other type of brackets {}. if (playertouchsme){ message Keep your hands off me!; hurt 1; } Test it once again. Nice, no? Try to make some nice funny thingies with the following commands: Events/Flags: playerenters - The player enters the level playertouchsme - The player touches the NPC wa**** - The NPC was hit by the players’ sword Commands: hurt amount; - Hurt an certain amount of damage message message; - Make the NPC say something (appear above head) say2 text; - Make the npc say something. Use #b for a new alinea. hide; - Hide the npc show; - show the npc Remember that all commands need to end with ; 2.2-Two flags Had fun? Now off to something a bit harder. You can say something yourself by pressing TAB and then type something, and afterwards press Enter. Press TAB again to continue playing. if (playerchats&&strequals(#c,hello)){ Message good day!; } Go play the level and say “hello”. The NPC will say something back. Have you noticed that if you open a new bracket, you will have to close it again? About the Events: Playerchats is if the player says something && means “and” strequals(#c,hello) means if #c (the chat text of the player) is the same as what is typed after the comma. Try this with other chat texts, too. Now, we’re gonna get the player a hat! if (playerchats&&strequals(#c,hat please!)){ message here you go!; setplayerprop #P1,hat0.png; } Play and say “hat please!”. You will get a cool helmet. Now, copy this NPC, but change it a bit. The script must contain strequals(#P1,hat0.png). Make it that if the player touches this new NPC, and he has the helmet, he gets another hat, and that hat is hat19.png, and the NPC must say something. If done well, it should look like this: if (playertouchsme&&strequals(#P1,hat0.png)){ message here, a nice crown!; setplayerprop #P1,hat19.png; } That was quite hard, no? But we go on. Now with variables and sub-flags. 2.3-Variables and sub-flags if (playertouchsme){ players[index].rupees+=10; } if (playerchats&&strequals(#c,buy hat)){ if (playerrupees=>10){ message Fine.; setplayerprop #P1,hat20.png; players[index].rupees-=10; sleep 2; message ; } if (playerrupees=<10){ message You don’t have enough money!; sleep 3; message ; } } Now, because this is quite hard, let’s do it slow and clearly. players[index].rupees+=10; This will make the money (rupees) of the player go up by 10. You can also use playerrupees+=10; what is easier and shorter. Players[index].rupees is called a variable. Other useful variables are players[index].x, players[index].y, players[index].darts and players[index].bombs. players[index].rupees-=10; The same as above, except that the player loses rupees :D if (playerrupees=>10){ and if (playerrupees=<10){ if the amount of money of the player is ten or more, the commands in the event will happen. Did you notice that there can be flags IN a flag? It is, that if the player says “buy hat” and he has enough rupees (playerrupees=>10), he gets the hat but loses 10 rupees, but if he hasn’t 10 rupees, (playerrupees=<10) the shopkeeper will say that he hasn’t enough money. This is to make the script much easier etc. We will call this “sub-flags”. Remember that you can also have more sub-flags and still they both work. For example, you can have if (playertouchsme){ if (players[index].bombs=<50){ players[index].bombs=50; } if (players[index].darts=<50){ players[index].darts=50 } } and if both bombs and arrows are less then 50 you will get 50 of both, if only the arrows are less then 50 you gain 50 arrows, and if only the bombs are less then 50, you get 50 of those. If you want that if the bombs of the player are less then 50 and the arrows too, you get 50 of both, but if there are less then 50 arrows and more than 50 bombs, you won’t get anything, you should have players[index].darts=<50 and players[index].bombs=<50 linked together in one flag with &&. sleep 3; This is for the NPC to wait three seconds. In this seconds, almost nothing happens or can happen. Here it is for the NPC to say something, wait three seconds and then say nothing. That was hard, no? I hope you still understand it ;-) Now, there are many other flags and commands. You can find them in the commands next to the editor. Make one NPC that contains all the three practices, but also: A script if you press A, then you say something. A script that will say some text with say2 when you throw something against it A script like in a shop and it sells you a better sword If the NPC was shot with an arrow, hurt the player Make another NPC that goes to your weapons when you enter and when you fire it you heal some hearts and the npc gets destroyed. Make the image beer.png 3.-timeout Timeout is one of the most important commands of GScript. Here is how it works: if (playerenters){ putleaps 5,x,y; timeout = 1; } if (timeout){ putleaps 5,x,y; } As you see, if the player enters you see the water at the place of the NPC. After one second, you see the water again and from then no more. You can use timeout for a loop. if (playerenters){ putleaps 5,x,y; timeout = 1; } if (timeout){ putleaps 5,x,y; timeout = 1; } Now, the water will come back every time. As you see, timeout can be quite handy =) I also attached to file in .zip here, it looks a lot better then this. |
i wish i had something like that when i started scripting...
|
I learned almost everything from looking at other scripts...
And experimenting... |
Y'know, 'if' is not a command.
|
Did i posted somewhere it's a command? :\ It's a program execution thingy. To lazy to check up commands.rtf
|
Conditional is what I always called it.
|
Re: Scripting Tutorial for Beginners
Quote:
|
Ah crap... That's because of the text editor i used x.x
|
Quote:
for program execution |
Well I read it I still dont understand time outs, can you explain a bit more?
|
Okay...
timeout = 1; this means that after 1 second, timeout is set. then you can use if (timeout){ //whatever you want; } clear? and inside timeout you can do anoter timeout. |
Quote:
Its useful as sleep does just that, sleep! So if you want to wait a certain time and trigger something, then timeout is good as sleep wont take any extra commands until its 'woke-up'. So you can do: NPC Code: So it goes down when it reads it, asks if 'timeout' is set, and at first it is not, so it ignores all in the timeout part. It then goes down and sees that the timeout is set to 1. Then it starts at the top again, reads down, this time timeout is set (to 1), so anything inside that is executed, and it will continue as it will go down and read timeout=1; again! Prob Wrong =/ |
you put the 'if (timeout)' inside of 'if (created)'? weird...
|
Quote:
NPC Code: |
Commands outside of event blocks are bad. But if(timeout){} is an event block, and nesting event blocks is just as bad.
|
nesting event blocks in other event blocks has it's purposes though
|
Quote:
|
Wouldn't this do the same thing as sparks?
NPC Code: If the npc is created, timeout = 1, if timeout, then loop. |
GoZelda..
I did the npcs you talked about here is what i came up with
// NPC made by Synergy The (Enchida) //#CLIENTSIDE if (keydownA) { setplayerprop #c,Look at that..I clicked!; } ^this one i could'nt get... :( // NPC made by Synergy The (Enchida) if (waspelt) { say2 Look at that you hit me!; } // NPC made by Synergy The (Enchida) if (playerchats&&strequals(#c,buy sword)){ if (playerrupees=>100){ message Fine.; lay goldensword; players[index].rupees-=100; sleep 2; message ; } if (playerrupees=<100){ message You don’t have enough money!; sleep 3; message ; } } // NPC made by Synergy The (Enchida) if (wasshot) { hurt 1; } //What do you think? |
1:
if (keydown(6)){ setplayerprop #c,:o i pressed A!!!; } All the others are correct. |
6?
if (keydown(6)) {
In my commands it has up,down,left,right,a,s,d so on and so forth... |
Yes, but try using
say2 #k(6); the order isn't right. Up, down, left, right are the same as dir. and playerdir. Originally posted by konidias Quote:
Um, Spark. The NPC only gets created once =\ As Kai said, it's the best to not put a timeout inside another event. And with timeout in another timeout i mean: if (timeout){ timeout = 1; } for an infinite loop. Another way of infinite loop: while (1==1){ //stuff; sleep 1; } |
Quote:
|
Oh sorry, read it wrong if you get what i mean. But it is an infinite loop, because when it's timeout it'll always be triggering timeout =\ it won't stop
|
Quote:
|
Did i stated it was a problem?
|
Quote:
If you do a variable check and include an increment inside your timeout it will not go forever. |
Quote:
|
Quote:
|
Quote:
|
Quote:
NPC Code: ..This would pause the WHOLE script for 2 second, and then move on. With timeout, it doesnt pause the script. It continues on. NPC Code: it will do the first 2 commands (setting playerprop, because those are done within the first 2 seconds. And then it will call the timeout, and do whatevers in there.) I think I explained it right.. it might be alittle confusing though ^_^. |
I dislike reviving threads, but as this one is linked from GoZelda's signature, I felt it necessary to point this out:
In his 'tutorial', he is using => instead of >=. This is a bad thing to do, as it's wrong. The engine's too forgiving of bad code. So, don't use =>. Use >=. It's pronounced "Greater than or equal to," surprisingly exactly like you learned how to pronounce it in a basic algebra (or even basic math) class! |
Quote:
I always forget whether the > or the = goes first. So, everyone out there, the > or < comes first! |
| All times are GMT +2. The time now is 06:50 PM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.