Hot reloading with War Battles tutorial

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:


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.

Could be wrong, but I don’t think the init function gets reloaded, so any changes made there won’t do much.

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.

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.