PDA

View Full Version : [Tutorial] ZScripting 'Hello, world of Hyrule!'



Asuna Yuuki Nagato
03-17-2024, 02:47 PM
Today we will making ZScript print "Hello, world of hyrule!" on the screen

1. File->New
2. ZScript->Compile ZScript...
3. Click 'Edit' button
4. Copy the following into the 'Edit ZScript' window (be careful; an #include is already there):



#include "std.zh"

global script Init
{
void run()
{
int layer = 1;
int x = 0;
int y = 0;
int font = 0;
int color = 1;
int format = 0;
int bg_color = 0;
char32 str = "Hello, world of hyrule!";
int opacity = OP_OPAQUE;
Screen->DrawString(layer, x, y, font, color, format, bg_color, str, opacity);
}
}


5. Press Esc
6. Click 'Yes' to save changes to buffer
7. Click 'Compile'; ZScript compiler should return code 0 for success
8. Click 'OK' to dismiss ZScript Parser window
9. Click 'OK' to dismiss Assign Compiled Script window
10. Click 'Close' to dismiss "Slots Assigned" msgbox (it should say "ZScripts successfully loaded into script slots")
11. Click 'OK' to dismiss "Init Script Changed" msgbox
12. Quest->Test; save quest as "zscript_hello_world_tut.qst"; click 'OK' to dismiss "ZC Editor" window
13. Click 'Test' in Test Quest window
14. Observe "Hello, world of hyrule!" briefly appears below the subscreen during iris transition

Asuna Yuuki Nagato
03-17-2024, 04:13 PM
The problem with the above example is that the text quickly disappears. Now we will be fixing that. First go back to the 'Edit ZScript' window and change the name of the script from "Init" to "HelloWorld":


global script HelloWorld

Also make sure DrawString is called in a loop:



while(true) {
Screen->DrawString(layer, x, y, font, color, format, bg_color, str, opacity);
Waitframe();
}


Now recompile. Then in the Assign Compiled Script window, in the Global tab:


Select "Active:" in the left listbox
Select "HelloWorld" in the right listbox
Click '<<'
Click 'OK' - the script should be successfully loaded into the slot
Test again; the text should stay underneath the subscreen now