First of all, bloggers are very happy, just a long time ago, bloggers want to write a script that belongs to their own engine, even if the function is simple, as long as it can run up on the line, until today, Bo Master finally to this dream took the first step, the script engine of the prototype to do out, because this script system belongs to Nkcengine , so the blogger named Nkscript,nkscript is a command-based language with no complex function calls, no complex looping statements, and it has a simple numeric operation statement, conditional jump statements, unconditional jump statements, command statements, and so on; Nkscript The development goal is mainly used for making simple word adventure game, is that only need to click the mouse, you can play the whole game of the game;
The scripting system is divided into two important components, the compiler (Nkscript Compiler) and the player (Nkscript player), the compiler is responsible for the developer easy to read and write the text form of script files, converted into binary intermediate code form, The script player then loads the intermediate code data and interprets the commands in the script as a graphical representation, as well as the user's input to execute and schedule the script (for example, click the mouse to display the next line of dialogue);
Let's start by looking at a short script code:
Text "Welcome to Nkscriptplayer script player \ n We will show you the basic function of the script player, click the left mouse button" text "We try to load and display the background map" load bg "cgdata/title001.bmp" text "Now, Try loading a cgdata/megu111 on the left side of the screen. BMP "Text" is very good, try to load a picture on the right side of a vertical painting "load" cgdata/sino113. BMP "Text" Next, I want to delete the entire image "unload Alltext" Oh ~ ~ a dark, nothing to see!! "Text" Click the mouse to end the program Oh "
The above script code is basically self-explanatory, there are only three kinds of commands, the first is the text command to display the specified text, the second is the load command to load the specified image file, and display it in the screen specified location, the third is the Unload command, the user removes the image at the specified location from the screen, And the image resources are freed from memory;
The effect is as follows:
Next, I want to demonstrate the function of numerical computation, but, only numerical operation, does not have any effect, in the word adventure game, the value often must match the condition judgment with the jump statement, can play the real utility, for example creates a variable loopcount, initializes to 0, then for Loopcount Increase 1, if found Loopcount less than 3, then jump to the specified text instruction, display the prompt text, and then jump to the head to re-execute, if Loopcount equals 3, then the end of the script run;
To achieve this, we can write out the following script:
Set Loopcount = 0:labelstartcalc Loopcount + 1if Loopcount = = 1 Labelrunfirstif loopcount = 2 Labelrunsecondif LoopCount = = 3 Labelend:labelrunfirsttext "The game is running for the first time" Goto Labelstart:labelrunsecondtext "game run for the second time Oh" Goto Labelstart:labelendtext "Click the mouse to end the program Oh"
The code should not be difficult to understand, if you have a little bit of experience with the command line under the Windows system, or the experience of writing a bat file, then it should be easy to read the script above, first, at the beginning of the script, use the SET command to create a variable loopcount, and set its initial value to 0, used to record how many times the script has been run repeatedly, and then immediately for Loopcount plus 1, then the value of Loopcount, if 1, the Display dialog 1, if 2, the dialog 2, if 3, jump directly to the end of the script, display exit prompt text, the final program exits, The effect of the operation is as follows:
The result is nothing to be surprised about, instead, "easy to use" is the biggest feature of this scripting system, because the script is ultimately written by the Scripting people, the program developers do not interfere too much, so that the people who write the game story can test their ideas and thoughts anywhere, anytime;
Finally, release the script engine executable program files, you can download back, by editing the Main.txt file, and then compile with NkScriptCompiler.exe, if the Main.nse file is successfully generated, you can use NkScriptPlayer.exe run, write good script saved, only need to directly double-click NkScriptCompiler.exe will compile itself, and then directly double-click NkScriptPlayer.exe will automatically run the script, Click the left mouse button to interact with the script:
Http://pan.baidu.com/s/1jHL8yZc
--2016-10-17 by Nekodev Cnblogs
--Original technical articles, reproduced please specify the source, and ensure the integrity of the content
Wrote a command-based mini script compiler and script player in C and Nkcengine