Solarus-Games English Forum

Solarus => Development => Topic started by: zutokaza on April 03, 2017, 03:23:56 AM

Title: (Solved)Table?
Post by: zutokaza on April 03, 2017, 03:23:56 AM
I have been trying to figure out the error with my table for the pixel movement.
Quotetrajectory (table): An array of all successive translations to make. Each translation should be an array of two integers (x and y).


Code ( lua) Select
local table1 = {244,270}
pixel:set_trajectory(table1)
pixel:start(gerf)


and I tried:

Code ( lua) Select
pixel:set_trajectory{244,270}
pixel:start(gerf)



[2150] Error: In on_started: [string "maps/Map_4.lua"]:83: bad argument #3 to set_trajectory (table expected, got number)

Title: Re: Table?
Post by: Diarandor on April 03, 2017, 06:44:17 AM
Quote from: zutokaza on April 03, 2017, 03:23:56 AM
I have been trying to figure out the error with my table for the pixel movement.
Quotetrajectory (table): An array of all successive translations to make. Each translation should be an array of two integers (x and y).


Code ( lua) Select
local table1 = {244,270}
pixel:set_trajectory(table1)
pixel:start(gerf)


and I tried:

Code ( lua) Select
pixel:set_trajectory{244,270}
pixel:start(gerf)



[2150] Error: In on_started: [string "maps/Map_4.lua"]:83: bad argument #3 to set_trajectory (table expected, got number)

Your array is not an array of translations, but an array of integers.
You need an array of translations. Examples:
For 1 translation: table1 = {{244,270}}
For 2 translations: table1 = {{244,270}, {244,270}}
Etc.
Title: Re: Table?
Post by: zutokaza on April 03, 2017, 07:39:50 AM
Thank you Diarandor! That solved my first problem.

Now the problem is that the NPC does not move at all. I tried multiple different coordinates of x,y. Strangly, the sprite vanishes with:

Code ( lua) Select
pixel:set_ignore_obstacles(true)

Full code:

Code ( lua) Select

function map:on_started()

local pixel = sol.movement.create("pixel")
pixel:set_trajectory{{64,80},{368,384}}
pixel:set_loop(true)
pixel:set_ignore_obstacles(true)
pixel:start(gerf)

end
Title: Re: Table?
Post by: Diarandor on April 03, 2017, 07:54:18 AM
It is normal. The coordinates of the translations are given in pixels and yours are too big. Try with small translations.
Title: (Solved)Table?
Post by: zutokaza on April 03, 2017, 08:14:52 AM
Oh, forgot it was in pixels. All is good now. Thank you for your help Diarandor!