|
Lets Start! Ok i think the best place to start with this one is the title, please read the Third word carefully, ok back thanx :) now to get back to it. Ok the first place i would go when creating a scripting language is to actually come up with the script commands, For this short article i will only use 5 commands, more than enough i think for people to get the idea. Ok the commands i have chosen are
Right now we have our command list we need to thing about what sort of data each command need to use.
Ok we now have our simple small but functional command list its time to start writing the Script Parser. To do this I'm going to create a function which takes in a line of text from your script file, So lets create the function just now.
Ok as you can see from the above I've decided to make the scripts easier for the scripter by not making them case sensitive. This will save a lot of hassle for both the scripter as they don't need to remember both commands and case and you as you don't need to coder for both case types, anyway we have our function skeleton in place now, its time to add the checks in. We'll start with the 'out' command, to do this i would first search for the first letter of the word out, then if it finds it do a check on the word and make sure it is the word 'out', after this i would locate the first " which signifies the start of the text you want to output to the screen, then after this i would locate the second " to signifies the end of the text. So to do this i need to use some of the string commands
that's the string commands I'm going to use to parse the out script line to usable data for this script engine. And ill just do a quick translation of my code plan from above to blitz code and voila
Ok from my text above you should be able to work out what the above code is doing exactly, right time to move onto the next command which would be delay, i would find the keyword delay in almost the same was as out then i would move forward one space and take the numbers in and convert them to Integers so i can actually use them, but seen as i don't know how long the user wants to delay the program for so ill get the full length of the line in characters and use that to workout how many characters i need to read in, as before I've explained what I'm going to be doing in my code and now here's the code.
As you can see i also included some calculations, this is because my delay command works with seconds and the Blitz delay command works in Milliseconds. so what I'm doing there is getting the numbers from within the string, converting them to integers then I'm multiplying that number by 1000 to satisfy the conversion from Seconds to Milliseconds. that's all there is to that section :) I wont cover the refresh and cls commands as the code is pretty straight forward for anyone to read so ill jump to the last command in my Scripting language which is Line. this one only looks slightly more complicated that the last two, but it isn't. for this one i'll show you the code first then ill explain what I'm doing with it, ok Here goes..
Ok you's should already know what the first 4 lines do as ive used the before, but with the 5 and 6 im using the location of the first , in the string to grab the starting cordinates X and Y and with count im getting the length of the line, because i wasn't sure how many characters the length would take up I'm using the length of the string and taking away the position of the second , and that will give me how many characters I've to take. I'm then using this value to draw the line to the screen with (Xcors + Length) or in other words end point as all I'm doing is adding the start point and the length together. ok not for the last two commands in my scripting language, i wont explain these as they are pretty simple.
And that's almost all the code, put all the above code inside the Function we created and that's our function completed. Now we can add a few more lines of code to the program like the code below and and with the script file below that and we should be able to run it.
Ok that should work Nicely :) But! before everyone points and laughs at the flaws in the code ill direct them to the third word of this document again, Ok back again kewl, and incase you haven't spotted the flaws yet let me point out that if you put more than one space after the word 'Delay' the delay command wont work, and if you put spaces between the numbers and the , in the line command that command wont work either, but the aim of this tutorial wasn't to go into creating a fully functional scripting language it was to implement a simple scripting language, and now that everyone knows the flaws they can go away with my code and fix these problems. then start on designing your own scripting language for any use, like AI scripts etc, Have fun and i hope this tutorial was of some use to you. Specis
|