Skip to main content

How to use our script template

This will provide you additional information of how you can use our Script Template.

When you load up our Script Template example or use the Main.lua.template file of the Computer Template. You will see something like this:

-- Any variables outside the main functions are global! (As programmer perspective) The code only gets ran once!

-- Gets called when the computer starts up
function onLoad()

end

-- Gets called every tick
function onUpdate()

end

-- Gets called when the computer error's out.
function onError(err)

end

-- Gets called when the computer shuts down.
function onDestroy()

end

What the functions do

We will tell you what these functions do

  • onLoad() This function gets called when the computer starts up
  • onUpdate( deltaTime ) This function gets called every tick when the computer is running. deltaTime is ofcourse, deltaTime!
  • onError( err ) This gets called when the computer error's. The err parameter is the error message itself.
  • onDestroy Called when the computer turns off

Code outside the functions

You might need global variables or functions. You can define them outside the functions.

Let's say you want to access the display globaly. You can add this at the top of your code!

local display = sc.getDisplays()[1]

What about a function?

local function PrintHelloWorld()
print("Hello world!")
end