Save ground for when falling in water and lava

Started by xavius, July 26, 2014, 03:42:11 PM

Previous topic - Next topic
Hi,

I know you can save ground to reset the hero to a position when he falls but is it possible to do the same with lava and water?

Thank you!

This is apparently a bug. It works with holes, and it should also work with lava, water and prickles too.
I have just fixed the problem, it will be fixed in Solarus 1.3: https://github.com/christopho/solarus/issues/567
Thanks for the report!

Thank you Christopho. Another question on this. Is the character teleported to the saved ground or it is translated to it? I have remarked depending how far you are from the saved ground point, it will take longer to respawn. Is it possible to do a setHeroPosition(blabla)?

Thank you again!

The hero is translated to the solid-ground-position.
To teleport him directly, you can override the behavior of the "back to solid ground" state like this (untested):

function hero:on_state_changed(state)
  if state == "back to solid ground" then
    hero:set_position(x, y)
    hero:unfreeze()  -- Stop the "back to solid ground" built-in state, restore control to the player.
  end
end

Is there a way to get the position and layer of a solid ground? I did not see it a function for this in the documentation.

Thank you again!

Not yet, this is missing. I just opened an issue to implement that for 1.3: https://github.com/christopho/solarus/issues/572

In the meantime, you should be able to implement your own functions:

function hero:my_save_solid_ground(x, y, layer)
  hero:save_solid_ground(x, y, layer)
  hero.solid_ground_position = { x = x, y = y, layer = layer}
end

function hero;my_get_solid_ground_position()
  if hero.solid_ground_position == nil then
    return nil
  end
  return hero.solid_ground_position.x, hero.solid_ground_position.y, hero.solid_ground_position.layer
end