Author Topic: [Solved]Hero state question  (Read 58 times)

Zefk

  • Hero Member
  • *****
  • Posts: 536
  • Just helping Solarus
    • View Profile
    • Zelzec
[Solved]Hero state question
« 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")

Christopho

  • Administrator
  • Hero Member
  • *****
  • Posts: 1123
    • View Profile
Re: Hero state question
« Reply #1 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.

Zefk

  • Hero Member
  • *****
  • Posts: 536
  • Just helping Solarus
    • View Profile
    • Zelzec
Re: [Solved]Hero state question
« Reply #2 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
  1.          
  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
  9.