Solarus Forum

Community => Your scripts => Topic started by: Minefran12 on October 10, 2017, 06:42:38 pm

Title: A chest created when all the enemies are killed
Post by: Minefran12 on October 10, 2017, 06:42:38 pm
I'm having a problem becaose i want to do to what the title says but i'm don't know how to do it exactly, Christopho say to me that i have to use the map:has_entities(prefix) and the enemy:on_dead(), and i start to do it following the docs and solving the errors that i saw in the console but in one point, i don' see any errors but it still dont work.

Please, could somebody tell me how i must do it, thanks.



PD: Sorry if I make mistakes of spealing or something else, i dont have a very high level of English. :)
Title: Re: A chest created when all the enemies are killed
Post by: Starlock on October 10, 2017, 08:24:56 pm
Hey, could you post your current code?

You might have to make the declaration in the map:on_started() function It would be something like this

Code: Lua
  1.   if game:get_value("chestsavevalue") then yourchestname:set_enabled(true) else yourchestname:set_enabled(false) end

The functions you are talking about should look something like this:

Code: Lua
  1. for enemy in map:get_entities("yourenemy") do
  2.   enemy.on_dead = function()
  3.     if not map:has_entities("yourenemy") then
  4.       yourchestname:set_enabled(true)
  5.       sol.audio.play_sound("chest_appears")
  6.     end
  7.   end
  8. end
Title: Re: A chest created when all the enemies are killed
Post by: Minefran12 on October 10, 2017, 09:20:45 pm
Thak you a lot, the problem was i havent declared game:get_value and i have only enemy.on_dead() insted of enemy.on_dead = function(). Tahnks again.