Author Topic: (Solved)Table?  (Read 447 times)

zutokaza

  • Full Member
  • ***
  • Posts: 146
  • Active - Making stories can take the most time.
    • View Profile
(Solved)Table?
« on: April 03, 2017, 03:23:56 am »
I have been trying to figure out the error with my table for the pixel movement.
Quote
trajectory (table): An array of all successive translations to make. Each translation should be an array of two integers (x and y).


Code: Lua
  1. local table1 = {244,270}
  2. pixel:set_trajectory(table1)
  3. pixel:start(gerf)

and I tried:

Code: Lua
  1. pixel:set_trajectory{244,270}
  2. pixel:start(gerf)


Code: [Select]
[2150] Error: In on_started: [string "maps/Map_4.lua"]:83: bad argument #3 to set_trajectory (table expected, got number)
« Last Edit: April 03, 2017, 08:23:11 am by zutokaza »

Diarandor

  • Hero Member
  • *****
  • Posts: 913
  • Cats are cool! (ΦωΦ)
    • View Profile
Re: Table?
« Reply #1 on: April 03, 2017, 06:44:17 am »
I have been trying to figure out the error with my table for the pixel movement.
Quote
trajectory (table): An array of all successive translations to make. Each translation should be an array of two integers (x and y).


Code: Lua
  1. local table1 = {244,270}
  2. pixel:set_trajectory(table1)
  3. pixel:start(gerf)

and I tried:

Code: Lua
  1. pixel:set_trajectory{244,270}
  2. pixel:start(gerf)


Code: [Select]
[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.
“If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you.”

zutokaza

  • Full Member
  • ***
  • Posts: 146
  • Active - Making stories can take the most time.
    • View Profile
Re: Table?
« Reply #2 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
  1. pixel:set_ignore_obstacles(true)

Full code:

Code: Lua
  1.  
  2. function map:on_started()
  3.  
  4. local pixel = sol.movement.create("pixel")
  5. pixel:set_trajectory{{64,80},{368,384}}
  6. pixel:set_loop(true)
  7. pixel:set_ignore_obstacles(true)
  8. pixel:start(gerf)
  9.  
  10. end
  11.  

Diarandor

  • Hero Member
  • *****
  • Posts: 913
  • Cats are cool! (ΦωΦ)
    • View Profile
Re: Table?
« Reply #3 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.
“If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you.”

zutokaza

  • Full Member
  • ***
  • Posts: 146
  • Active - Making stories can take the most time.
    • View Profile
(Solved)Table?
« Reply #4 on: April 03, 2017, 08:14:52 am »
Oh, forgot it was in pixels. All is good now. Thank you for your help Diarandor!
« Last Edit: April 03, 2017, 08:22:46 am by zutokaza »