How to set down the key contuner

Started by GameboyArda, May 16, 2016, 10:15:48 AM

Previous topic - Next topic
I have made a door that opens automatcliy when you have the key, But somehow the key conter donset go down
Please help? :-\
You know that nearly all of use strugled once
with RPG maker. But now we make with
Solarus! 8)

It would be hard to help considerating that we didn't have a look on your key counter script nor your door.

Door:
Code ( lua) Select
function s_sensor:on_activated()

if game:get_value("key_1") then
  map:open_doors("door_1")
  map:open_doors("door_2")
end
end


Key counter:
Code ( lua) Select
-- The small keys counter shown during dungeons or maps with small keys enabled.

local small_keys_builder = {}

local small_key_icon_img = sol.surface.create("hud/small_keys.png")

function small_keys_builder:new(game)

  local small_keys = {}

  local digits_text = sol.text_surface.create{
    font = "white_digits",
    horizontal_alignment = "left",
    vertical_alignment = "top",
  }
  local num_small_keys_displayed = nil
  if game:are_small_keys_enabled() then
    num_small_keys_displayed = game:get_num_small_keys()
  end

  function small_keys:set_dst_position(x, y)
    self.dst_x = x
    self.dst_y = y
  end

  function small_keys:on_draw(dst_surface)

    if not game:are_small_keys_enabled() then
      return
    end

    local x, y = self.dst_x, self.dst_y
    local width, height = dst_surface:get_size()
    if x < 0 then
      x = width + x
    end
    if y < 0 then
      y = height + y
    end

    small_key_icon_img:draw(dst_surface, x, y)
    digits_text:draw(dst_surface, x, y + 10)
  end

  local function check()

    if game:are_small_keys_enabled() then
      local num_small_keys = game:get_num_small_keys()
      if num_small_keys_displayed ~= num_small_keys then
        num_small_keys_displayed = num_small_keys
        digits_text:set_text(num_small_keys)
      end
    end

    return true  -- Repeat the timer.
  end

  -- Periodically check the number of small keys.
  check()
  sol.timer.start(game, 40, check)

  return small_keys
end

return small_keys_builder

You know that nearly all of use strugled once
with RPG maker. But now we make with
Solarus! 8)

The thing is, the key counter is never updated and the key isn't removed.

If you use ROTH SE or MOS, then add in your sensor (These functions aren't documented in the API since they are made for these projects, check equipment.lua if you wanna learn how they works)

game:remove_small_key()

But first, you need to check if the small key counter is strictly superior to 0, so add a condition like so

if game:has_small_key() then blablabla end


Thanks!
You know that nearly all of use strugled once
with RPG maker. But now we make with
Solarus! 8)