Tutorial 5: Exploring KonsolScript

From the previous tutorial, we’ve already tried understanding what’s written inside the sample code. In this tutorial, we will try to understand the files created along side our sample code “helloworld.ks” — namely, helloworld.konsl and ks.log files.

What are they for?

helloworld.konsl

The .KONSL file is basically the processed file which stores the codes you have written in the KS file. Once the KonsolScript runtime is done reading your codes from your KS file, the KonsolScript runtime starts to dump all the information it read to a new file that ends with .KONSL.

Ideally, this KONSL file is what you, as the creator of a KonsolScript-written game, should give to your friends, because the mechanics of your game is hidden inside the KONSL file — any non-technical friend of yours will find it hard to edit your game!

But if you are working with a friend to create your game, it’s better to share the KS file so he/she might be able to help finishing/fixing the game. ;)

ks.log

KS.LOG is basically a log file which logs all necessary information. It is also helpful for you to log whatever is happening to your game in the log file by using the Konsol:Log command — example:

function main() {
  Konsol:Log("logging this command")
}

When you run your code with the addition showed above, you can start looking for the line “logging this command” written on KS.LOG.

Also, to let you in on a little secret, check what’s written in the log file just below the line: Implementing Table Look-Up

You will see something like:

Implementing Numbers
	Warning: ... is unused.
	...
Implementing Strings
	Warning: ... is unused.
Implementing Booleans
	Warning: ... is unused.
	...

Basically, these are variables that KonsolScript runtime is aware of but is not currently used in your code. Let’s try using the Number variables mouseX and mouseY.

function cleanrender() {
  Screen:PrintString("x: " + mouseX + " y: " + mouseY)
}

Running your updated code will show the X and Y coordinates of the mouse in relation to the screen.

Built-in Numbers

Below are mostly read-only Number variables; the runtime is the one setting the value of these variables:

lastpress — the key code of the last pressed key on the keyboard, 0 if not applicable.
lastunpress — the key code of the last unpressed key on the keyboard, 0 if not applicable.
screenwidth — the width of the screen.
screenheight — the height of the screen.
textwidth — the width of a single letter on the screen.
textheight — the height of a single letter on the screen.
cursorX — x location of where the screen will print the text.
cursorY — y location of where the screen will print the text.
mouseX — x location of the mouse on the screen.
mouseY — y location of the mouse on the screen.

Built-in Booleans

Below are read-only Boolean variables:

B1 — short for Button 1; set to TRUE when ESCAPE key from keyboard is pressed.
B2 — short for Button 2; set to TRUE when CONTROL key from keyboard is pressed.
B3 — short for Button 3; set to TRUE when ENTER/RETURN key from keyboard is pressed.
B4 — short for Button 4; set to TRUE when SPACE key from keyboard is pressed.
BU — short for Button Up; set to TRUE when ARROW UP key from keyboard is pressed.
BD — short for Button Down; set to TRUE when ARROW DOWN key from keyboard is pressed.
BL — short for Button Left; set to TRUE when ARROW LEFT key from keyboard is pressed.
BR — short for Button Right; set to TRUE when ARROW RIGHT key from keyboard is pressed.
LMB — short for Left Mouse Button; set to TRUE when LEFT MOUSE button from mouse is pressed.
MMB — short for Middle Mouse Button; set to TRUE when MIDDLE MOUSE button from mouse is pressed.
RMB — short for Right Mouse Button; set to TRUE when RIGHT MOUSE button from mouse is pressed.

If any of the buttons above is unpressed the value is set to FALSE.

I guess, that wraps up the Basics! I’ll be drafting what’s to discuss in Intermediate Tutorial Series soon and hopefully get it done soon! Hopefully next week. Hopefully tomorrow. :)

~creek23