Author Topic: LUA problem  (Read 4588 times)

njursten

  • Seedling
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 31
LUA problem
« on: November 17, 2009, 06:11:16 AM »
I wanted to try making a level for this great game, but ran into some problems. To see what happened in the level from the very start I wanted to make all the asteroids visible. After creating the asteroids I tried running the following code.
Code: [Select]
   id = 0
   while GetAsteroid(id) ~= nil do
      GetAsteroid(id):Reveal(1)
      id = id + 1
   end

However, the not equal to nil check doesn't seem to work. The id reaches a value not used and I get a "index was out of range" error. I also tried adding "if GetAsteroid(id) == nil then break end" inside the loop, but that didn't help either. An explicit loop from 0 up to the last index works without problems.

Alex

  • Administrator
  • Ent
  • *****
  • Thank You
  • -Given: 3
  • -Receive: 14
  • Posts: 1,035
Re: LUA problem
« Reply #1 on: November 17, 2009, 08:20:23 PM »
I can fix it to return nil if the id is out of range, yeah. Will add it to the list :)

njursten

  • Seedling
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 31
Re: LUA problem
« Reply #2 on: November 18, 2009, 05:08:59 AM »
Thanks! Either that or a function that returns the current number of existing asteroids.

Hm, I just now saw the Globals.G.Asteroids variable. Doesn't seem to be the number of added asteroids, though. What's it for?
« Last Edit: November 18, 2009, 06:02:27 AM by njursten »

Alex

  • Administrator
  • Ent
  • *****
  • Thank You
  • -Given: 3
  • -Receive: 14
  • Posts: 1,035
Re: LUA problem
« Reply #3 on: November 18, 2009, 08:11:53 PM »
I think it used to, but it was for the XML stuff.

njursten

  • Seedling
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 31
Re: LUA problem
« Reply #4 on: November 20, 2009, 06:07:26 AM »
I had some trouble with an asteroid ring being added with some preset values unless I added one myself. Setting Globals.G.Asteroids to 0 prevented this from happening, so apparently it still has some function. :)