[SOLVED] How to use: chest:on_opened() ?

Started by dpro_games, July 11, 2017, 12:16:00 PM

Previous topic - Next topic
July 11, 2017, 12:16:00 PM Last Edit: July 14, 2017, 07:07:57 PM by dpro_games
Hello, I create this code to increment a value when this chest is open but I have this error :
Error: Failed to load script 'maps/dungeons/tuto/place_holder': [string "maps/dungeons/tuto/place_holder.lua"]:5: <name> or '...' expected near '"sword"'

function sword_chest:on_opened("sword", 1, "sword_chest_save")
  hero:unfreeze()
  chest_open = chest_open + 1
  test()
end


Thank for the answere
With this code
function sword_chest:on_opened(sword, 1, "sword_chest_save")
  hero:unfreeze()
  chest_open = chest_open + 1
  test()
end


I have another error
Error: Failed to load script 'maps/dungeons/tuto/place_holder': [string "maps/dungeons/tuto/place_holder.lua"]:5: <name> or '...' expected near '1'

I don't understand why...

Your first line is not valid Lua syntax. Are you trying to define a function or to call a function?

I just want to detect when the chest is open to open a door.

July 11, 2017, 06:40:12 PM #5 Last Edit: July 11, 2017, 06:43:43 PM by MetalZelda
Quote from: dpro_games on July 11, 2017, 04:55:15 PM
Thank for the answere
With this code
function sword_chest:on_opened(sword, 1, "sword_chest_save")
  hero:unfreeze()
  chest_open = chest_open + 1
  test()
end


I have another error
Error: Failed to load script 'maps/dungeons/tuto/place_holder': [string "maps/dungeons/tuto/place_holder.lua"]:5: <name> or '...' expected near '1'

I don't understand why...

Do like this
Don't know if this will work because I never use chest:on_opened() but that's the way to go


Code (lua) Select
function sword_chest:on_opened(item, variant, savegame)
 
  if item:get_name() == "sword" then

  end
end

It work but there is still a problem... When I open the chest, the value is increase but the hero don't get the sword in the chest. May I need to give the sword by the code but I don't know the line which give the item like if the player open a chest...
Thank to help me.

I found by myself, that's work !  :D
I use this line:
hero:start_treasure(treasure_item, [treasure_variant, [treasure_savegame_variable, [callback]]])
To give the treasure to the hero when he open the chest.

Thanks you for helped me !  :D :D