This is super basic but I've looked around and not found an answer and it's really bugging me.
So I find the following to be much cleaner, neater, and easier to deal with than the alternative:
function pause()
local sprite = enemy:get_sprite()
sprite:set_animation("idle")
enemy:stop_movement()
sol.timer.start(enemy, math.random(1, 2000), jump)
end
function jump()
local sprite = enemy:get_sprite()
enemy:stop_movement()
sprite:set_animation("jumping")
local movement = sol.movement.create("jump")
movement:set_direction8(math.random(0, 7))
movement:set_distance(math.random(12, 64))
movement:start(enemy)
sol.timer.start(enemy, 800, pause)
end
Whereas if I use "function enemy:blahblahblah" I appear to accomplish the same thing, yet the syntax on things like timers is longer and more restrictive:
function enemy:pause()
local sprite = enemy:get_sprite()
sprite:set_animation("idle")
enemy:stop_movement()
sol.timer.start(enemy, math.random(1, 2000), function()
enemy:jump()
end)
end
function enemy:jump()
local sprite = enemy:get_sprite()
enemy:stop_movement()
sprite:set_animation("jumping")
local movement = sol.movement.create("jump")
movement:set_direction8(math.random(0, 7))
movement:set_distance(math.random(12, 64))
movement:start(enemy)
sol.timer.start(enemy, 800, function()
enemy:pause()
end)
end
Then if I start mixing both in the same script, it gets much worse because I'll tend to forget and mismatch the syntaxes to the wrong functions and I spend extra time correcting stupid mistakes to clean up all the error messages.
I see the latter method used in a lot of scripts in enemies by the Solaris team, so there must be some advantage to it, or some reason why it's bad to avoid it. What am I missing? Is there a reason not to use the first approach for all my enemy scripts?
Sorry to ask about such basic stuff all the time!