Zelda Roth Reproduced Intro Help

Started by Tulk, June 25, 2017, 07:56:34 AM

Previous topic - Next topic
June 25, 2017, 07:56:34 AM Last Edit: June 25, 2017, 07:58:35 AM by Tulk
Hello guys! I tried to reproduce the intro from Zelda Roth and got this error: line 27:31 >



Error: In maps/intro: [string:"maps/intro.lua"]:33: attempt to index a nil value


The code:

-- Frescos.
local frescos = {}
for i = 1, 5 do
  frescos[i] = sol.surface.create("menus/intro/intro" .. i .. ".png")
  frescos[i]:set_xy(0, 16)
end


It's the same code maked by Christopho's, Just change quantitis on for. What's wrong with it?

The error is in line 33 of your script (could you post the code of all the script?).
It says that you are trying to index (access an attribute) of a nil variable (the variable has nothing attached so you cannot access the attribute and hence you get an error; you need a list to access an attribute).
"If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you."

June 25, 2017, 10:37:44 AM #2 Last Edit: June 25, 2017, 10:40:00 AM by Tulk
local map = ...
local game = map:get_game()

-- Intro.

local map_width, map_height = map:get_size()

game:set_hud_enabled(false)
hero:set_enabled(false)

-- Scrolling backgrounds.
local bg1_img = sol.surface.create("menus/intro/bg1.png")
local bg1_width, bg1_height = bg1_img:get_size()
local bg1_xy = {}
local bg1_movement = sol.movement.create("straight")
bg1_movement:set_angle(3 * math.pi / 4)
bg1_movement:set_speed(32)
bg1_movement:start(bg1_xy)

local bg2_img = sol.surface.create("menus/intro/bg2.png")
local bg2_width, bg2_height = bg2_img:get_size()
local bg2_xy = {}
local bg2_movement = sol.movement.create("straight")
bg2_movement:set_angle(math.pi / 4)
bg2_movement:set_speed(32)
bg2_movement:start(bg2_xy)

-- Frescos.

local frescos = {}
for i = 1, 4 do
  frescos[i] = sol.surface.create("menus/intro/intro" .. i .. ".png")
  frescos[i]:set_xy(0, 16)
end
local fresco_index = 0  -- Index of the current fresco.

-- Dialog.
local dialog_background_img = sol.surface.create(256, 64)
dialog_background_img:set_xy(32, 160)
dialog_background_img:fill_color({255, 255, 128, 128})

function bg1_movement:on_position_changed(x, y)

  if y <= -bg1_height then
    bg1_movement:set_xy(0, 0)
  end

end

function bg2_movement:on_position_changed(x, y)

  if y <= -bg2_height then
    bg2_movement:set_xy(0, 0)
  end

end

local function next_fresco()


  if fresco_index < #frescos then
    fresco_index = fresco_index + 1
    game:start_dialog("intro.fresco_" .. fresco_index, next_fresco)
  else
    -- Restore usual settings.
    game:get_dialog_box():set_style("box")
    game:get_dialog_box():set_position("bottom")
    hero:unfreeze()

    -- Go to the first map.
   -- hero:teleport("houses/link_house", "from_intro")
  end
end

function map:on_started()

  game:get_dialog_box():set_style("empty")
  game:get_dialog_box():set_position({ x = 32, y = 160})
  next_fresco()
end

function map:on_opening_transition_finished()

  hero:freeze()
end

function map:on_draw(dst_surface)

  -- Scrolling backgrounds.
  for y = -bg2_height, map_height + bg2_height, bg2_height do
    for x = -bg2_width, map_width + bg2_width, bg2_width do
      bg2_img:draw(dst_surface, bg2_xy.x + x, bg2_xy.y + y)
    end
  end

  for y = -bg1_height, map_height + bg1_height, bg1_height do
    for x = -bg1_width, map_width + bg1_width, bg1_width do
      bg1_img:draw(dst_surface, bg1_xy.x + x, bg1_xy.y + y)
    end
  end

  -- Fresco.
  if fresco_index > 0 and fresco_index <= #frescos then
    frescos[fresco_index]:draw(dst_surface)
  end

  -- Dialog box background.
  dialog_background_img:draw(dst_surface)
end

Thanks.

Ok, the error is exactly in line:
Code (Lua) Select

frescos[i]:set_xy(0, 16)

which means that frescos[i] is nil, or in other words, your image has not been created in the previous line:
Code (Lua) Select

frescos[i] = sol.surface.create("menus/intro/intro" .. i .. ".png")

which in turn means that the id of the image (this one: "menus/intro/intro" .. i .. ".png") is not correct.
(The image has not been created by the engine since that file does not exist; there is something wrong in that string.)
"If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you."

In most case, if frescos returns nil, this is because your surface isn't created because the file has not been found

June 25, 2017, 08:26:43 PM #5 Last Edit: June 25, 2017, 08:50:59 PM by Tulk
Thank you guys! xD


--------- @Edit:

How can I reproduce something like in this video: 1:34 - 1:38

https://www.youtube.com/watch?v=3Jm8_1zoZtw&list=PLaT85v0g5RS6Lshz4RUNGF8bpNqZHsmuM

The camera approaches on point of image on the screen in game intro. How to make it?

To do that zoom with that camera angle we may need something like this: https://en.wikipedia.org/wiki/Mode_7
Or maybe just a normal zoom (maybe this can already be done).

I don't remember if there are already requests for these features in github.
"If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you."


Probably, but I am not sure if that is the same thing, and also I don't know which license has that code (it could be incompatible with GPL).

Anyway, you cannot directly add a library without coding something in the engine (the C++ part).
"If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you."