Scripting Basics

Scripts are pieces of code that give a behaviour to Entities.

To create a new Script, create a new file with a .h file extension in the scripts directory at the root of the project directory.

In it, copy and paste this script template:

#pragma once
#include "../Common/script/ntshengn_script.h"

using namespace NtshEngn;
struct TemplateScript : public Script {
        NTSHENGN_SCRIPT(TemplateScript);

        void init() {
        }

        void update(float dt) {
        }

        void destroy() {
        }
};

Script is a structure containing the Scripting API, allowing to call functions from NutshellEngine’s systems.

init is a function that will be executed once, when the Script is created.

update is a function that will be executed once per frame. The dt parameter corresponds to the delta time, or the time between two frames, in seconds.

destroy is a function that will be executed once, when the Script is destroyed.

The Script is then automatically added to the project the next time the CMake is re-configured and its name (for example, TemplateScript here) can be used in the Scriptable Component of an Entity, in the .ntsn - Scene file format.