Author Topic: Expanding item_1 and item_2 commands  (Read 1705 times)

0 Members and 1 Guest are viewing this topic.

wizard_wizzle (aka ZeldaHistorian)
  • Sr. Member
  • ****
  • Posts: 263
    • View Profile
Expanding item_1 and item_2 commands
« on: February 09, 2016, 01:41:48 AM »
I'm thinking it should be possible, probably using metatables, to expand the item_1 and item_2 commands and include item_3 and even item_4, for when more items are needed. But I'm wondering, does modifying the metatable of existing functions expand them or overwrite them? For example, would the code below work? If not, I could create a custom function similar to each of the built-in ones for each of the item slot functions.

Code: (lua) [Select]
local game_metatable = sol.main.get_metatable("game")
function game_metatable:get_item_assigned(slot)
  if slot == 2 then
    return game:get_value("slot_2_item")
  elseif slot == 3 then
    return game:get_value("slot_3_item")
  end
end

I'm also not 100% sure how the button mapping part would work. Is game:get/set_command_keyboard_binding() expandable or configurable?

Just brainstorming and wanted others' thoughts...

Christopho

  • Administrator
  • Hero Member
  • *****
  • Posts: 1186
    • View Profile
Re: Expanding item_1 and item_2 commands
« Reply #1 on: February 09, 2016, 08:52:28 AM »
It overwrites the built-in function. But you can still access the old one if you want, for example like this:
Code: (lua) [Select]
local game_metatable = sol.main.get_metatable("game")
local engine_get_item_assigned = game_metatable.get_item_assigned
function game_metatable:get_item_assigned(slot)
  if slot <= 2 then
    return engine_get_item_assigned(game, slot)
  elseif slot == 3 then
    return game:get_value("slot_3_item")
  end
end
game:get/set_command_keyboard_binding() is not configurable. You need to store the additional commands yourself. It is not too hard, I did it in Zelda Roth SE where there are several additional commands and these commands are also configurable.

wizard_wizzle (aka ZeldaHistorian)
  • Sr. Member
  • ****
  • Posts: 263
    • View Profile
Re: Expanding item_1 and item_2 commands
« Reply #2 on: February 09, 2016, 02:09:29 PM »
That's exactly what I needed to know - thanks!