Solarus Forum

Solarus => Development => Topic started by: Zefk on August 09, 2018, 11:47:50 pm

Title: [Solved]Hero state question
Post by: Zefk on August 09, 2018, 11:47:50 pm
I was wondering if there was a way to set the hero's state? All I noticed in the documentation was hero:get_state().

Sometimes the hero gets stuck on a certain state in my scripts and something like the following would be useful.

Code: Lua
  1. hero:set_state("free")
Title: Re: Hero state question
Post by: Christopho on August 09, 2018, 11:53:36 pm
There is no hero:set_state() function because depending on the state you want, there are different parameters needed. Like in the treasure state, you need to specify which treasure you want. For this reason, there are separate functions instead. The one you want is hero:unfreeze(). It unblocks the hero, that is, it restores control to the player.
Title: Re: [Solved]Hero state question
Post by: Zefk on August 10, 2018, 12:32:09 am
Ah, got it and that did fix my problem. It was quite odd because the hero would get stuck on the bow state if I pressed "b" and "down" very quickly on a ladder. Not sure if that is a bug. It could just be me.

Code: Lua
  2.           --State is a variable in hero:set_animation()
  3.           --hero:set_animation(state)
  4.           if key == "b" then
  5.             hero:start_bow()
  6.           elseif key == "down" and state == "walking" or state == "ladder" then
  7.             hero:unfreeze()
  8.           end