You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/en/manuals/script.md
+55-55Lines changed: 55 additions & 55 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -32,76 +32,76 @@ Defold executes Lua scripts as part of the engine lifecycle and exposes the life
32
32
`self` is a userdata object that acts like a Lua table but you can't iterate over it with `pairs()` or `ipairs()` and you can't print it using `pprint()`.
33
33
:::
34
34
35
-
`init(self)`
36
-
: Called when the component is initialized.
37
-
38
-
```lua
39
-
functioninit(self)
40
-
-- These variables are available through the lifetime of the component instance
41
-
self.my_var="something"
42
-
self.age=0
43
-
end
44
-
```
35
+
#### `init(self)`
36
+
Called when the component is initialized.
37
+
38
+
```lua
39
+
functioninit(self)
40
+
-- These variables are available through the lifetime of the component instance
41
+
self.my_var="something"
42
+
self.age=0
43
+
end
44
+
```
45
45
46
-
`final(self)`
47
-
: Called when the component is deleted. This is useful for cleaning up purposes, for instance if you have spawned game objects that should be deleted when the component is deleted.
46
+
#### `final(self)`
47
+
Called when the component is deleted. This is useful for cleaning up purposes, for instance if you have spawned game objects that should be deleted when the component is deleted.
48
48
49
-
```lua
50
-
functionfinal(self)
51
-
ifself.my_var=="something" then
52
-
-- do some cleanup
53
-
end
49
+
```lua
50
+
functionfinal(self)
51
+
ifself.my_var=="something" then
52
+
-- do some cleanup
54
53
end
55
-
```
54
+
end
55
+
```
56
56
57
-
`update(self, dt)`
58
-
: Called once each frame. `dt` contains the delta time since the last frame.
57
+
#### `update(self, dt)`
58
+
Called once each frame. `dt` contains the delta time since the last frame.
59
59
60
-
```lua
61
-
functionupdate(self, dt)
62
-
self.age=self.age+dt-- increase age with the timestep
63
-
end
64
-
```
60
+
```lua
61
+
functionupdate(self, dt)
62
+
self.age=self.age+dt-- increase age with the timestep
63
+
end
64
+
```
65
65
66
-
`fixed_update(self, dt)`
67
-
: Frame-rate independent update. `dt` contains the delta time since the last update. This function is called when `engine.fixed_update_frequency` is enabled (!= 0). Useful when you wish to manipulate physics objects at regular intervals to achieve a stable physics simulation when `physics.use_fixed_timestep` is enabled in *game.project*.
66
+
#### `fixed_update(self, dt)`
67
+
Frame-rate independent update. `dt` contains the delta time since the last update. This function is called when `engine.fixed_update_frequency` is enabled (!= 0). Useful when you wish to manipulate physics objects at regular intervals to achieve a stable physics simulation when `physics.use_fixed_timestep` is enabled in *game.project*.
: When messages are sent to the script component through [`msg.post()`](/ref/msg#msg.post) the engine calls this function of the receiver component. Learn [more about message passing](/manuals/message-passing).
When messages are sent to the script component through [`msg.post()`](/ref/msg#msg.post) the engine calls this function of the receiver component. Learn [more about message passing](/manuals/message-passing).
77
77
78
-
```lua
79
-
function on_message(self, message_id, message, sender)
: If this component has acquired input focus (see [`acquire_input_focus`](/ref/go/#acquire_input_focus)) the engine calls this function when input is registered. Learn [more about input handling](/manuals/input).
86
+
#### `on_input(self, action_id, action)`
87
+
If this component has acquired input focus (see [`acquire_input_focus`](/ref/go/#acquire_input_focus)) the engine calls this function when input is registered. Learn [more about input handling](/manuals/input).
88
88
89
-
```lua
90
-
function on_input(self, action_id, action)
91
-
if action_id == hash("touch") and action.pressed then
92
-
print("Touch", action.x, action.y)
93
-
end
89
+
```lua
90
+
functionon_input(self, action_id, action)
91
+
ifaction_id==hash("touch") andaction.pressedthen
92
+
print("Touch", action.x, action.y)
94
93
end
95
-
```
94
+
end
95
+
```
96
96
97
-
`on_reload(self)`
98
-
: This function is called when the script is reloaded through the hot reload editor function (<kbd>Edit ▸ Reload Resource</kbd>). It is very useful for debugging, testing and tweaking purposes. Learn [more about hot-reload](/manuals/hot-reload).
97
+
#### `on_reload(self)`
98
+
This function is called when the script is reloaded through the hot reload editor function (<kbd>Edit ▸ Reload Resource</kbd>). It is very useful for debugging, testing and tweaking purposes. Learn [more about hot-reload](/manuals/hot-reload).
99
99
100
-
```lua
101
-
functionon_reload(self)
102
-
print(self.age) -- print the age of this game object
103
-
end
104
-
```
100
+
```lua
101
+
functionon_reload(self)
102
+
print(self.age) -- print the age of this game object
0 commit comments