Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - Starlock

#91
Development / Re: Problems with dialog and HUD
September 10, 2015, 03:20:54 AM
Ok the title menu and savegames are now working nicely so I got   

Error: In on_started: [string "scripts/game_manager.lua"]:18: attempt to call method 'initialize_hud' (a nil value)

(Which might have been there to begin with but I only noticed the map changed one.   :P  )
#92
Development / Re: Problems with dialog and HUD
September 08, 2015, 02:52:38 PM
I'm not entirely sure because I'll try to make small edits and the errors wont show up but the screen is still black :/ Errors keep appearing and disappearing

This is the only current error I'm getting Error: In timer callback: [string "scripts/menus/title.lua"]:27: attempt to index local 'zs_presents_img' (a nil value)

Code ( lua) Select
  local zs_presents_img =
      sol.surface.create("title_screen_initialization.png", true)
       

Isn't this the right code used to call zs_presents?
#93
Development / Re: Problems with dialog and HUD
September 08, 2015, 01:14:40 AM
I'm just not sure where to put settings :/   and now the savegame is still getting a nil value for a string even though I triple checked that it existed in strings.dat   

Code ( lua) Select
-- New file.
      local name = "- " .. sol.language.get_string("selection_menu.empty") .. " -"
      slot.player_name_text:set_text(name)
    end


Error: In on_started: [string "scripts/menus/savegames.lua"]:262: attempt to concatenate a nil value
#94
Development / Re: Problems with dialog and HUD
September 06, 2015, 10:20:37 PM
I figured I would keep this in this thread so I tried to add the save game menu using the code used in ZSDX so that I could easily just change graphics but have the same feel later on, however now I am getting several errors that prevent me from starting the game at all. Its strange because I basically just used the exact code that zsdx uses...

Error: In timer callback: [string "scripts/menus/title.lua"]:27: attempt to index local 'zs_presents_img' (a nil value)
Fatal: Cannot open file 'settings.dat' for writing: The system cannot find the path specified.
Error: In on_finished: [string "main.lua"]:55: Internal error: Cannot open file 'settings.dat' for writing: The system cannot find the path specified.
Error: In on_started: [string "scripts/menus/savegames.lua"]:262: attempt to concatenate a nil value

#95
Development / Re: Problems with dialog and HUD
September 05, 2015, 08:06:40 PM
Doesn't seem to be related since the errors are still occurring even after editing the code.

These two errors appear once the game loads   Error: In on_started: [string "scripts/hud/rupees.lua"]:12: attempt to call method 'set_transparency_color' (a nil value)
Error: In on_map_changed: [string "scripts/game_manager.lua"]:75: attempt to index upvalue 'hud' (a nil value)

and this error appears when the game ends   Error: In on_finished: [string "scripts/game_manager.lua"]:46: attempt to index upvalue 'hud' (a nil value)
#96
Development / Re: Problems with dialog and HUD
September 05, 2015, 06:36:52 PM
Error: In on_started: [string "scripts/hud/rupees.lua"]:12: attempt to call method 'set_transparency_color' (a nil value)

This is the only other error but I don't think its related since the other error has been appearing for a longer time
#97
Development / Re: Problems with dialog and HUD
September 05, 2015, 04:12:38 AM
Alright, no problem. Thanks for the help with the dialog box problem  :)
#98
Development / Re: Problems with dialog and HUD
September 05, 2015, 03:45:41 AM
Code ( lua) Select
-- Script that creates a head-up display for a game.

-- Usage:
-- local hud_manager = require("scripts/hud/hud")
-- local hud = hud_manager:create(game)

local hud_manager = {}

-- Creates and runs a HUD for the specified game.
function hud_manager:create(game)

  -- Set up the HUD.
  local hud = {
    enabled = false,
    elements = {},
  }

  -- Create each element of the HUD.
  local hearts_builder = require("scripts/hud/hearts")
  local rupees_builder = require("scripts/hud/rupees")
  local bombs_builder = require("scripts/hud/bombs")
  local arrows_builder = require("scripts/hud/arrows")
  local item_builder = require("scripts/hud/item_icon")
  local magic_bar_builder = require("scripts/hud/magic_bar")
  local small_keys_builder = require("scripts/hud/small_keys")
  local boss_life_builder = require("scripts/hud/boss_life")
  local attack_icon_builder = require("scripts/hud/attack_icon")
  local action_icon_builder = require("scripts/hud/action_icon")

  local hearts = hearts_builder:new(game)
  hearts:set_dst_position(-88, 0)
  hud.elements[#hud.elements + 1] = hearts

  local rupees = rupees_builder:new(game)
  rupees:set_dst_position(121, 10)
  hud.elements[#hud.elements + 1] = rupees

  local bombs = bombs_builder:new(game)
  bombs:set_dst_position(153, 10)
  hud.elements[#hud.elements + 1] = bombs

  local arrows = arrows_builder:new(game)
  arrows:set_dst_position(178, 10)
  hud.elements[#hud.elements + 1] = arrows

  local item = item_icon_builder:new(game, 1)
  item:set_dst_position(27, 15)
  hud.elements[#hud.elements + 1] = item

  local magic_bar = magic_bar_builder:new(game, 1)
  magic_bar:set_dst_position(10, 8)
  hud.elements[#hud.elements + 1] = magic_bar

  local small_keys = small_keys_builder:new(game)
  small_keys:set_dst_position(88, 10)
  hud.elements[#hud.elements + 1] = small_keys

  local boss_life = boss_life_builder:new(game)
  boss_life:set_dst_position(110, 220)
  hud.elements[#hud.elements + 1] = boss_life

  menu = attack_icon_builder:new(self)
  menu:set_dst_position(13, 29)
  self.hud[#self.hud + 1] = menu
  self.hud.attack_icon = menu

  menu = action_icon_builder:new(self)
  menu:set_dst_position(26, 51)
  self.hud[#self.hud + 1] = menu
  self.hud.action_icon = menu

  -- Destroys the HUD.
  function hud:quit()

    if hud:is_enabled() then
      -- Stop all HUD elements.
      hud:set_enabled(false)
    end
  end

  -- Call this function to notify the HUD that the current map has changed.
  function hud:on_map_changed(map)

    if hud:is_enabled() then
      for _, menu in ipairs(hud.elements) do
        if menu.on_map_changed ~= nil then
          menu:on_map_changed(map)
        end
      end
    end
  end

  -- Call this function to notify the HUD that the game was just paused.
  function hud:on_paused()

    if hud:is_enabled() then
      for _, menu in ipairs(hud.elements) do
        if menu.on_paused ~= nil then
          menu:on_paused()
        end
      end
    end
  end

  -- Call this function to notify the HUD that the game was just unpaused.
  function hud:on_unpaused()

    if hud:is_enabled() then
      for _, menu in ipairs(hud.elements) do
        if menu.on_unpaused ~= nil then
          menu:on_unpaused()
        end
      end
    end
  end

  -- Returns whether the HUD is currently enabled.
  function hud:is_enabled()
    return hud.enabled
  end

  -- Enables or disables the HUD.
  function hud:set_enabled(enabled)

    if enabled ~= hud.enabled then
      hud.enabled = enabled

      for _, menu in ipairs(hud.elements) do
        if enabled then
          -- Start each HUD element.
          sol.menu.start(game, menu)
        else
          -- Stop each HUD element.
          sol.menu.stop(menu)
        end
      end
    end
  end

  -- Start the HUD.
  hud:set_enabled(true)

  -- Return the HUD.
  return hud
end

return hud_manager
#99
Development / Problems with dialog and HUD
September 05, 2015, 02:44:21 AM
In game manager I keep getting an error towards the hud: "Error: In on_map_changed: [string "scripts/game_manager.lua"]:75: attempt to index upvalue 'hud' (a nil value)"

and the dialog box creates the error:  Error: In on_started: "[string "scripts/dialog_box.lua"]:59: attempt to call field 'get_dialog_font' (a nil value)"

Clearly the problem is about the nil values but when I try defining either of them the error remains so I'm not quite understanding what to do....

Game_manager.lua
Code ( lua) Select
-- Script that creates a game ready to be played.

-- Usage:
-- local game_manager = require("scripts/game_manager")
-- local game = game_manager:create("savegame_file_name")
-- game:start()

local game_manager = {}

-- Creates a game ready to be played.
function game_manager:create(file)

  -- Create the game (but do not start it).
  local exists = sol.game.exists(file)
  local game = sol.game.load(file)
  if not exists then
    -- This is a new savegame file.
    game:set_starting_location("house")
    game:set_max_money(99)
    game:set_max_life(12)
    game:set_life(game:get_max_life())
    game:get_item("rupee_bag"):set_variant(1)
  end
 
  sol.main.load_file("scripts/dialog_box.lua")(game)
  sol.main.load_file("scripts/game_over.lua")(game)
  local hud_manager = require("scripts/hud/hud")
  local hud
  local pause_manager = require("scripts/menus/pause")
  local pause_menu

  -- Function called when the player runs this game.
  function game:on_started()

    -- Prepare the dialog box menu and the HUD.
    game:initialize_dialog_box()
    hud = hud_manager:create(game)
    pause_menu = pause_manager:create(game)
  end

  -- Function called when the game stops.
  function game:on_finished()

    -- Clean the dialog box and the HUD.
    game:quit_dialog_box()
    hud:quit()
    hud = nil
    pause_menu = nil
  end

  -- Function called when the game is paused.
  function game:on_paused()

    -- Tell the HUD we are paused.
    hud:on_paused()

    -- Start the pause menu.
    sol.menu.start(game, pause_menu)
  end

  -- Function called when the game is paused.
  function game:on_unpaused()

    -- Tell the HUD we are no longer paused.
    hud:on_unpaused()

    -- Stop the pause menu.
    sol.menu.stop(pause_menu)
  end

  -- Function called when the player goes to another map.
  game.on_map_changed = function(game, map)

    -- Notify the HUD (some HUD elements need to know that).
    hud:on_map_changed(map)
  end

  local custom_command_effects = {}
  -- Returns the current customized effect of the action or attack command.
  -- nil means that the built-in effect.
  function game:get_custom_command_effect(command)
    return custom_command_effects[command]
  end

  -- Overrides the effect of the action or attack command.
  -- Set the effect to nil to restore the built-in effect.
  function game:set_custom_command_effect(command, effect)
    custom_command_effects[command] = effect
  end

  -- Returns whether the HUD is currently shown.
  function game:is_hud_enabled()
    return hud:is_enabled()
  end

  -- Enables or disables the HUD.
  function game:set_hud_enabled(enable)
    return hud:set_enabled(enable)
  end

  local rupee_icon = sol.surface.create("hud/rupee_icon.png")
  local rupee_text = sol.text_surface.create()
  rupee_text:set_font("8_bit")

  function game:on_draw(dst_surface)

    rupee_icon:draw_region(0, 0, 12, 12, dst_surface, 10, 220)
    rupee_text:set_text(game:get_money())
    rupee_text:draw(dst_surface, 25, 225)
  end
 

  return game
end

return game_manager



And this is line 59 of the dialogbox script
Code ( lua) Select
local font, font_size = sol.language.get_dialog_font()
#100
Development / Diablo like health/magic?
September 02, 2015, 03:31:47 AM
Is it possible for the hearts and magic bar used in ZSDX to be instead shown as red and blue orbs like in Diablo? I tried to simply use the code and custom graphics but I'm not exactly sure how to compile the graphics to create a HUD.
#101
Development / Question about dynamic tiles
August 27, 2015, 02:26:43 AM
If you wanted to make a shovel that was able to dig at dirt to reveal treasures similar to that of the shovel in Link's Awakening would you have to turn all ground tiles into dynamic tiles? Like would you make the ground dynamic and then under it there would be patches of dirt that are revealed after the ground has been dug? I'm just checking to see if this is the basic idea before I attempt to code a shovel
#102
Development / Re: Problem w global go value
August 26, 2015, 04:11:25 AM
Ahh I see what you mean now.. I was able to get it work now thanks   :)
#103
Development / Re: Problem w global go value
August 26, 2015, 03:49:05 AM
The error is still

Error: In timer callback: [string "enemies/crab.lua"]:53: attempt to call global 'go' (a nil value)

which is what I dont understand since the go value is supposed to be based on direction as far as I know... The sprite just disappears when its supposed to shoot the rock
#104
Development / Re: Problem w global go value
August 26, 2015, 03:25:58 AM
Here is the code:

Code ( lua) Select
local enemy = ...

local can_shoot = true

function enemy:on_created()

  enemy:set_life(3)
  enemy:set_damage(2)
  enemy:create_sprite("enemies/" .. enemy:get_breed())
end

local function go_hero()

  local sprite = enemy:get_sprite()
  sprite:set_animation("walking")
  local movement = sol.movement.create("target")
  movement:set_speed(64)
  movement:start(enemy)
end

local function shoot()

  local map = enemy:get_map()
  local hero = map:get_hero()
  if not enemy:is_in_same_region(hero) then
    return true  -- Repeat the timer.
  end

  local sprite = enemy:get_sprite()
  local x, y, layer = enemy:get_position()
  local direction = sprite:get_direction()

  -- Where to create the projectile.
  local dxy = {
    {  8,  -4 },
    {  0, -13 },
    { -8,  -4 },
    {  0,   0 },
  }

  sprite:set_animation("shooting")
  enemy:stop_movement()
  sol.timer.start(enemy, 300, function()
    sol.audio.play_sound("stone")
    local stone = enemy:create_enemy({
      breed = "crab_stone",
      x = dxy[direction + 1][1],
      y = dxy[direction + 1][2],
    })

    go(direction)

    sol.timer.start(enemy, 500, go_hero)
  end)
end

function enemy:on_restarted()

  local map = enemy:get_map()
  local hero = map:get_hero()

  go_hero()

  can_shoot = true

  sol.timer.start(enemy, 100, function()

    local hero_x, hero_y = hero:get_position()
    local x, y = enemy:get_center_position()

    if can_shoot then
      local aligned = (math.abs(hero_x - x) < 16 or math.abs(hero_y - y) < 16)
      if aligned and enemy:get_distance(hero) < 200 then
        shoot()
        can_shoot = false
        sol.timer.start(enemy, 1500, function()
          can_shoot = true
        end)
      end
    end
    return true  -- Repeat the timer.
  end)
end

function enemy:on_movement_changed(movement)

  local direction4 = movement:get_direction4()
  local sprite = self:get_sprite()
  sprite:set_direction(direction4)
end
#105
Development / Problem w global go value
August 26, 2015, 03:01:44 AM
I'm trying to make a crab that throws a stone using the roth code for an octorok but everytime I run it the sprite disappears during the "shooting" animation with the error:

Error: In timer callback: [string "enemies/crab.lua"]:53: attempt to call global 'go' (a nil value)