problem with doors

Started by Starlock, January 14, 2016, 04:01:49 PM

Previous topic - Next topic
I've been working on dungeon design,and have been using the door_manager code. I'm having a couple probelms, but with that code, one door will open when one auto_enemy is killed and the rest will open after the others are killed.

And in the code of one map:

Code ( lua) Select
local map = ...
local game = map:get_game()

local door_manager = require("maps/lib/door_manager")
door_manager:manage_map(map)

function map:on_started()
  function map:on_started()
  if not game:get_value("dun1keyy") then chest_key:set_enabled(false) end
end

  map:set_doors_open("auto_door_f", true)


  self.night_overlay = sol.surface.create()  -- Create an empty surface of the size of the screen.
  self.night_overlay:set_opacity(152)        -- Make it semi-transparent (0: transparent, 255: opaque).
  self.night_overlay:fill_color({195, 24, 24})  -- Fill it with dark blue to obtain a night effect.
end
function map:on_draw(destination_surface)
  self.night_overlay:draw(destination_surface)
end

function bridge_switch:on_activated()

  sol.audio.play_sound("secret")
  map:set_entities_enabled("bridge_tile", true)
end

function close_auto_door_f_sensor_1:on_activated()

  if auto_door_f:is_open()
      and map:has_entities("auto_enemy_auto_door_f") then
    map:close_doors("auto_door_f")
  end
end

for enemies in map:get_entities("auto_enemy_auto_door_f") do
  enemies.on_dead = function()
    if not map:has_entities("auto_enemy_auto_door_f") and not game:get_value("dun1keyy") then
      chest_key:set_enabled(true)
      sol.audio.play_sound("chest_appears")
    end
  end
end


the auto_door_f wont reopen after the enemies are killed and the chest_key doesn't start out false

January 14, 2016, 05:18:47 PM #1 Last Edit: January 14, 2016, 09:45:33 PM by MetalZelda
The door is closed but there is nothing that says that the door should reopened after (not in a function) so the game , except in on_started(), you shall add a condition that check if all of the ennemies are killed and store it into a value which will determine if the door shall be open.
I would prefer the set_door_open to be in the on_started()

EDIT : Why is there 2 map:on_started() ?

Same thing for the chest

Code (lua) Select

-- does enemy work here ? I didn't have tested it but the for loop check for any ennemies that have this name
if not map:has_entities(enemy) and not game:get_value("dun1keyy") then
      chest_key:set_enabled(true)
      sol.audio.play_sound("chest_appears")
    end


You should turn your value dun1keyy to true since the chest has now spawned


Code (lua) Select
local map = ...
local game = map:get_game()

local door_manager = require("maps/lib/door_manager")
door_manager:manage_map(map)

function map:on_started()
  if game:get_value("dun1keyy") then chest_key:set_enabled(true) else chest_key:set_enabled(false) end
end

  self.night_overlay = sol.surface.create()  -- Create an empty surface of the size of the screen.
  self.night_overlay:set_opacity(152)        -- Make it semi-transparent (0: transparent, 255: opaque).
  self.night_overlay:fill_color({195, 24, 24})  -- Fill it with dark blue to obtain a night effect.
end
function map:on_draw(destination_surface)
  self.night_overlay:draw(destination_surface)
end

function bridge_switch:on_activated()

  sol.audio.play_sound("secret")
  map:set_entities_enabled("bridge_tile", true)
end

function close_auto_door_f_sensor_1:on_activated()

  if auto_door_f:is_open()
      and map:has_entities("auto_enemy_auto_door_f") then
    map:close_doors("auto_door_f")
  end
end

for enemies in map:get_entities("auto_enemy_auto_door_f") do
  enemies.on_dead = function()
    if not map:has_entities("auto_enemy_auto_door_f") and not game:get_value("dun1keyy") then
     map:set_doors_open("auto_door_f", true) -- I assume that you want to have your door open after the ennemy fight ? else put it in on_started()
      chest_key:set_enabled(true)
      sol.audio.play_sound("chest_appears")
    end
  end
end

The code seems to be giving me the error

Error: Failed to load script 'maps/dungeons/dungeon1floor1': [string "maps/dunge
ons/dungeon1floor1.lua"]:14: '<eof>' expected near 'end'
Error: In maps/dungeons/dungeon1floor1: attempt to call a string value

That seems to me the typical error of wrong syntax at the given line. Be careful.
"If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you."

I didn't tested the code but what I posted is an idea of what the script should be

You can delete the "end" at line 14, I forget this one