-
-
Notifications
You must be signed in to change notification settings - Fork 56
Scripting : Local Events
❗️ This part of the guide will use a feature we didn't see yet ❗️
But don't worry, I'll try my best to explain the concept in a simple way.
Each GameObject Script Component does have 4 default Local Triggers which are the following ones :
Trigger | Description |
---|---|
Init | Called when the GameObject is being created |
Update | Called at every update in the Game Loop |
Delete | Called when the GameObject is deleted |
Of course you can use more Local Triggers using GameObject extensions (and we will see that later) or create your own Local Triggers !
Let's check the Triggers Parameters of these 4 Local Triggers we already saw :
Trigger | Parameters |
---|---|
Init | Dynamic Parameters |
Update | dt |
Delete |
While Save and Delete doesn't take any parameters, Update takes one parameter named "dt" which is the DeltaTime (We will learn what is DeltaTime in a future chapter don't worry).
But the most interesting one here is obviously the Init Trigger, what does Dynamic Parameters
means ?
Well, the Init trigger works like a constructor, it's up to you to choose what do you want to ask for Constructor Parameters !
Let's imagine we have a Sum
GameObject, the code could looks like that :
function Local.Init(number1, number2)
print(number1 + number2);
end
But where will we pass those parameters ?
You might have guess ! It's directly linked to this chapter of the guide : GameObject Requirements
There is actually two ways to pass those parameters :
- Using the Requirements statically (In a map file / vili file)
- Passing them dynamically by exposing the Local.Init
We will come back a bit later on those Triggers in a later chapter as it's a bit complicated, let's come back to something more simple : Accessing GameObject Components
- 🖊 My first project
- 🗺 My first map
- 📏 Project Structure
- 🖼 LevelSprites
- 📐 Colliders
- 🔳 EditorGrid
- 🤖 GameObjects
- 🖊 Scripting
- 🔫 Events
- 📜 Read the Docs
- ⌨️ Keyboard and Actions
- 👨💻 Debugging
- 🔉 Sounds and Musics
- 🗄 Vili Format
- 📽 Animations
- ✂️ Using Utils
- ⌚️ Manipulating Time
- 🎨 Using the Canvas
- ✔️ Tasks
- 🖱 Cursor and Constraints
- ⌨️ Keyboard and Actions
- 📁 Mounting and Paths
- 👨🏭 Workspaces
- 📏 Coordinates and Transform
- 📷 Camera
- 🗺 Map files
- 🏭 The ResourceManager
- 🎮 Gamepads and Joysticks