Small keys

Started by Dragon_noir, May 19, 2015, 07:23:30 PM

Previous topic - Next topic
How do you enable small keys on a map?

This can be done in Lua.
If your map is called "my_map", you can make an item "small_key_my_map" that has an amount (the number of small keys), and set this item as required on each locked door of this map.

I don't really understand, I'm just beginning to learn how to program.

Do I need to create a new item for each key I want in a map?(I can't seem to be able to create a key without this line of code

item:set_savegame_variable("")
)

this is the code for small keys i have now (from Zelda DX)

local item = ...

function item:on_created()

  item:set_shadow("small")
  item:set_brandish_when_picked(false)
  item:set_sound_when_picked("picked_small_key")
  item:set_savegame_variable("possession_small_key")
end

function item:on_obtaining(variant, savegame_variable)

  item:get_game():add_small_key()
end


Zelda Mystery of Solarus DX has a system of small keys different from was I was suggesting. In ZSDX there is only one "small_key" item for the whole game, and the Lua scripts detects in what current dungeon we are to increment the correct savegame variable.

What you can do is a small key item for each dungeon. For example in dungeon 1, you can make several treasure chests containing the item "dungeon_1_small_key".
Your small key item script should do something like item:set_amount_savegame_variable("dungeon_1_small_key_amount") instead of item:set_savegame_variable("possession_small_key"). Because this is an item with an amount: you want to save an integer (the number of small keys), not a boolean (whether the player has an item).

(I should do a tutorial about small keys :))

Ok I tried it , but now I'm getting this error message:

Error: In create_door: bad argument #1 to ? (Bad field 'opening_condition' (equipment item 'small_key' is not saved))

, and my doors do not appear on the map.

This is my small key code now:

local item = ...

function item:on_created()

  item:set_shadow("small")
  item:set_brandish_when_picked(false)
  item:set_sound_when_picked("picked_small_key")
  item:set_amount_savegame_variable("dungeon_small_key_amount")
end

function item:on_obtaining(variant, savegame_variable)

  item:get_game():add_small_key()
end

For doors to work with an item, the possession state of the item also needs to be saved (maybe I should change that, actually). So in item:on_created(), try to also add item:set_savegame_variable("dungeon_small_key_possession").

And remove the item:on_obtaining() function, it is not needed if the door directly checks the item. (ZSDX is not a great example for small keys, it does more complicated things for historical reasons.)

May 20, 2015, 09:04:27 AM #6 Last Edit: May 20, 2015, 09:25:52 AM by Christopho
Actually I think I forgot something important here...
We need two items: one for the small key counter, and one for the obtainable small keys. Like we do for rupees: there is an rupee item and a rupee bag item.
So for dungeon 1, they would be called "dungeon_1_small_key_counter" and "dungeon_1_small_key"

dungeon_1_small_key_counter.lua:

local item = ...

function item:on_created()
  item:set_savegame_variable("dungeon_1_small_key_counter_possession")
  item:set_amount_savegame_variable("dungeon_1_small_key_counter_amount")
end


dungeon_1_small_key.lua:

function item:on_created()
  item:set_shadow("small")
  item:set_brandish_when_picked(false)
  item:set_sound_when_picked("picked_small_key")
end

function item:on_obtaining(variant, savegame_variable)

  local counter = item:get_game():get_item("dungeon_1_small_key_counter")
  counter:set_variant(1)
  counter:add_amount(1)
end


Still not tested, sorry. I will prepare a tutorial on this.

Tested it, but it doesn't work :/

I also can't get the key counter to appear on screen.

I'll just wait for a tutorial .

Is there an error message?

In the meantime you can always reproduce what is done in Zelda Mystery of Solarus DX. At least we know it works :)

No, i don't have an error message.

It works fine for 1 key.
But if I pick up 2 keys and open a door I have no keys left. It's like it doesn't save the amount of keys I have, and as I can't get the HUD to show the small keys counter, I don't really know what's happening.

Can you send us your quest data?

Sure, where do you want me to send it?

As you want, you can host it with google drive or dropbox for example.