Tutorial 4: Understanding KonsolScript

This tutorial explains the sample code shown from Hello World tutorial.

function main

function main() {
  //more code to follow
}

All KonsolScript game should have this function called, main.

This main function is the first function to be executed in KonsolScript. Without function main, your code will not execute at all.

So, what is to happen given that you have the sample code above? Well, to simplify this demo, nothing else will happen for now unless the 2 other functions below will be executed.

function cleanrender

function cleanrender() {
  //?
}

This function, called cleanrender, is one of the seven Event functions of KonsolScript. An Event function is executed when the event happened. For cleanrender, it is triggered each time the game screen is to be updated, like when you need to draw a car move across the screen. (More on Event functions below.)

But as the sample code demonstrates, there’s nothing actually happening there right now. As the function’s name suggests, it cleans the screen.

function mousemove

function mousemove() {
  Screen:PrintString("hi, I'm KonsolScript!")
}

This last function from the sample code is another one of the seven Event functions. As stated above, this function is executed if the event happens. From the name alone, it means that this part of the code will be executed when the mouse is moved along the screen.

From the demo, you will see a text saying, “hi, I’m KonsolScript!“, every time the mouse is moving. This is printed on the screen via the command Screen:PrintString — you can change the text between the double quotes if you want. 🙂

The text disappears from the screen when the moving stops. The reason it disappears is because the function cleanrender is triggered — meaning, the text on the screen was cleaned up.

Event functions

function mousedown() {
  //
}

function mouseup() {
  //
}

function keydown() {
  //
}

function keyup() {
  //
}

function render() {
  //
}

Above are the 5 remaining Event functions in KonsolScript that were not included in the sample code to simplify the demo. Above functions are triggered, when the mouse or a key on the keyboard is pressed down, or unpressed. The function render is the same with function cleanrender, but it does not clean the screen. If you are trying to optimize the framerate of your game, you need to use render over cleanrender.

If you are wondering which among render and cleanrender will be executed when both functions are inside your code, it’s the render function — the cleanrender function will be ignored.

So, what else is there to know? In the next tutorial, we will explore the log file that was generated when you executed the sample code! 😉

~creek23


Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *