Skip to content

Commit 2e2ec1a

Browse files
committed
Update script.md
1 parent f66956b commit 2e2ec1a

File tree

1 file changed

+55
-55
lines changed

1 file changed

+55
-55
lines changed

docs/en/manuals/script.md

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -32,76 +32,76 @@ Defold executes Lua scripts as part of the engine lifecycle and exposes the life
3232
`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()`.
3333
:::
3434

35-
`init(self)`
36-
: Called when the component is initialized.
37-
38-
```lua
39-
function init(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+
function init(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+
```
4545

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.
4848

49-
```lua
50-
function final(self)
51-
if self.my_var == "something" then
52-
-- do some cleanup
53-
end
49+
```lua
50+
function final(self)
51+
if self.my_var == "something" then
52+
-- do some cleanup
5453
end
55-
```
54+
end
55+
```
5656

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.
5959

60-
```lua
61-
function update(self, dt)
62-
self.age = self.age + dt -- increase age with the timestep
63-
end
64-
```
60+
```lua
61+
function update(self, dt)
62+
self.age = self.age + dt -- increase age with the timestep
63+
end
64+
```
6565

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*.
6868

69-
```lua
70-
function fixed_update(self, dt)
71-
msg.post("#co", "apply_force", {force = vmath.vector3(1, 0, 0), position = go.get_world_position()})
72-
end
73-
```
69+
```lua
70+
function fixed_update(self, dt)
71+
msg.post("#co", "apply_force", {force = vmath.vector3(1, 0, 0), position = go.get_world_position()})
72+
end
73+
```
7474

75-
`on_message(self, message_id, message, sender)`
76-
: 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).
75+
#### `on_message(self, message_id, message, sender)`
76+
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).
7777

78-
```lua
79-
function on_message(self, message_id, message, sender)
80-
if message_id == hash("increase_score") then
81-
self.total_score = self.total_score + message.score
82-
end
78+
```lua
79+
function on_message(self, message_id, message, sender)
80+
if message_id == hash("increase_score") then
81+
self.total_score = self.total_score + message.score
8382
end
84-
```
83+
end
84+
```
8585

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).
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).
8888

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+
function on_input(self, action_id, action)
91+
if action_id == hash("touch") and action.pressed then
92+
print("Touch", action.x, action.y)
9493
end
95-
```
94+
end
95+
```
9696

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).
9999

100-
```lua
101-
function on_reload(self)
102-
print(self.age) -- print the age of this game object
103-
end
104-
```
100+
```lua
101+
function on_reload(self)
102+
print(self.age) -- print the age of this game object
103+
end
104+
```
105105

106106

107107
## Reactive logic

0 commit comments

Comments
 (0)