Author Topic: [Solved]Array in function?  (Read 2845 times)

0 Members and 1 Guest are viewing this topic.

Zefk

  • Hero Member
  • *****
  • Posts: 535
  • Just helping Solarus
    • View Profile
    • Zefk Design
[Solved]Array in function?
« on: May 15, 2017, 06:07:00 AM »
I get the following error:
Code: [Select]
0] Error: Failed to load script 'scripts/lib/zefk_entity_lib.lua': [string "scripts/lib/zefk_entity_lib.lua"]:2093: '(' expected near '['
when trying this:

Code: ( lua) [Select]
  function sprites[index]:on_animation_finished()
    sprites[index]:set_animation(end_anime)
    sol.audio.play_sound(end_sound)
  end

The following function will only work if I convert my array to a normal variable.

Code: ( lua) [Select]
    sprites2 = sprites[2]
  function sprites2:on_animation_finished()
    sprites[index]:set_animation(end_anime)
    sol.audio.play_sound(end_sound)
  end

Is there a way around this because I'd like to on_animation_finish() without having a limit set. I do not want to do something like this:

Code: ( lua) [Select]
   
 sprites2 = sprites[2]
  function sprites2:on_animation_finished()
    sprites[index]:set_animation(end_anime)
    sol.audio.play_sound(end_sound)
  end

 sprites1 = sprites[1]
  function sprites1:on_animation_finished()
    sprites[index]:set_animation(end_anime)
    sol.audio.play_sound(end_sound)
  end

 sprites3 = sprites[3]
  function sprites3:on_animation_finished()
    sprites[index]:set_animation(end_anime)
    sol.audio.play_sound(end_sound)
  end

 sprites4 = sprites[4]
  function sprites4:on_animation_finished()
    sprites[index]:set_animation(end_anime)
    sol.audio.play_sound(end_sound)
  end

 sprites5 = sprites[5]
  function sprites5:on_animation_finished()
    sprites[index]:set_animation(end_anime)
    sol.audio.play_sound(end_sound)
  end

Zefk

  • Hero Member
  • *****
  • Posts: 535
  • Just helping Solarus
    • View Profile
    • Zefk Design
[Solved]Array in function?
« Reply #1 on: May 15, 2017, 06:20:41 AM »
Solved it.

Code: ( lua) [Select]
  local sprites = sprites[index]

  function sprites:on_animation_finished()
    sprites:set_animation(end_anime)
    sol.audio.play_sound(end_sound)
  end