Author Topic: Zelda Roth Reproduced Intro Help  (Read 342 times)

Tulk

  • Newbie
  • *
  • Posts: 18
    • View Profile
Zelda Roth Reproduced Intro Help
« on: June 25, 2017, 07:56:34 am »
Hello guys! I tried to reproduce the intro from Zelda Roth and got this error: line 27:31 >


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

Code: [Select]
-- 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?
« Last Edit: June 25, 2017, 07:58:35 am by Tulk »

Diarandor

  • Hero Member
  • *****
  • Posts: 816
  • Cats are cool! (ΦωΦ)
    • View Profile
Re: Zelda Roth Reproduced Intro Help
« Reply #1 on: June 25, 2017, 09:56:57 am »
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.”

Tulk

  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: Zelda Roth Reproduced Intro Help
« Reply #2 on: June 25, 2017, 10:37:44 am »
Code: [Select]
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
« Last Edit: June 25, 2017, 10:40:00 am by Tulk »

Diarandor

  • Hero Member
  • *****
  • Posts: 816
  • Cats are cool! (ΦωΦ)
    • View Profile
Re: Zelda Roth Reproduced Intro Help
« Reply #3 on: June 25, 2017, 11:09:12 am »
Thanks.

Ok, the error is exactly in line:
Code: Lua
  1. frescos[i]:set_xy(0, 16)
which means that
Code: [Select]
frescos[i] is nil, or in other words, your image has not been created in the previous line:
Code: Lua
  1. 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.”

MetalZelda

  • Hero Member
  • *****
  • Posts: 520
    • View Profile
Re: Zelda Roth Reproduced Intro Help
« Reply #4 on: June 25, 2017, 01:03:35 pm »
In most case, if frescos returns nil, this is because your surface isn't created because the file has not been found

Tulk

  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: Zelda Roth Reproduced Intro Help
« Reply #5 on: June 25, 2017, 08:26:43 pm »
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?
« Last Edit: June 25, 2017, 08:50:59 pm by Tulk »

Diarandor

  • Hero Member
  • *****
  • Posts: 816
  • Cats are cool! (ΦωΦ)
    • View Profile
Re: Zelda Roth Reproduced Intro Help
« Reply #6 on: June 26, 2017, 02:14:38 am »
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.”


Diarandor

  • Hero Member
  • *****
  • Posts: 816
  • Cats are cool! (ΦωΦ)
    • View Profile
Re: Zelda Roth Reproduced Intro Help
« Reply #8 on: June 26, 2017, 12:12:51 pm »
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.”