Hello,
I started the War Battles tutorial and I wanted to try the hot reload feature.
When I change the value for “self.speed = 50”, hot reload does not work.
I read this documentation regarding hot reloading script:
Defold is a multi-platform game engine that simplifies development of 2D games for all major platforms – HTML5, Android, iOS, Windows, Mac OS X and Linux
Defold is a multi-platform game engine that simplifies development of 2D games for all major platforms – HTML5, Android, iOS, Windows, Mac OS X and Linux
Here is the script:
function init(self) -- [1]
msg.post(".", "acquire_input_focus") -- [2]
self.moving = false -- [3]
self.input = vmath.vector3() -- [4]
self.dir = vmath.vector3(0, 1, 0) -- [5]
self.speed = 50 -- [6]
end
How can use Hot Reload to tweak a script in this tutorial ?
Thank you for you help.
Potota
October 23, 2019, 3:40pm
2
Could be wrong, but I don’t think the init
function gets reloaded, so any changes made there won’t do much.
britzl
October 23, 2019, 4:04pm
3
Correct. Hot reload will not affect an already instantiated script component. New instances would be affected though.
The on_reload()
function should still be called for the scripts that are already running.
1 Like
I used the following function:
function on_reload(self) -- [1]
msg.post(".", "acquire_input_focus") -- [2]
self.moving = false -- [3]
self.input = vmath.vector3() -- [4]
self.dir = vmath.vector3(0, 1, 0) -- [5]
self.speed = 50 -- [6]
end
Hot reload works with “on_reload()”.
Is it a good practice to replace “init()” by “on_reload()” ?
Thank you for your feedback.
britzl
October 24, 2019, 4:00am
6
Maybe not replace, but if you need to tweak values while developing your game then yes, use on_reload to modify existing instances of your script component.