Eufloria > Eufloria Classic Mods

[error]exception indexing '20'

(1/2) > >>

Breakord:
When testing my codes,an error occured and I dont know why...
So I am here again to ask for good souls' help... =_=
The error message in console is:
lua:513:exception indexing '20'(the number changes each time, '20'or'35'or'2'or...)
Codes:

--- Code: ---function LevelSetup()
...
...
SeedlingsInBattle={}
for i=0,GetNumAsteroids()-1 do
   SeedlingsInBattle[i]={}
   for j=0,11 do
      SeedlingsInBattle[i][j]={}
   end
end
end
function LevelLogic()
...
...
while GameRunning() do
   for i=0,GetNumAsteroids()-1 do--check each asteroid
      local a=GetAsteroid(i)
      if a:GetNumSeedlingsExcluding(a.Owner)>0 then--check if there are other factions' seedlings on the asteroid,which means the battle begins or continues
         for j=0,11 do--check each faction
            if a:GetNumSeedlings(j)>0 then
               for count=0,a:GetNumSeedlings(j)-1 do
                  SeedlingsInBattle[i][j][count]=a:Seedlings(j)[count]--*****Here is line 513*****
               end
            end
         end
      end
   end
...
...
   coroutine.yield()
end
...
...
end

--- End code ---
=_=,Whats wrong with "SeedlingsInBattle[\i][j][count]=a:Seedlings(j)[count-1]" ?
By the way,it's been a while since I saw Alex and Rudolf online last time...
So busy you two are, but dont forget to take a rest.

Pilchard123:
It may be that the seedling has moved away from the asteroid.

What does the Seedlings() function do? What should all of this code do?

Aino:

--- Quote from: Pilchard123 on February 07, 2013, 04:15:16 AM ---It may be that the seedling has moved away from the asteroid.

What does the Seedlings() function do? What should all of this code do?

--- End quote ---

It returns an array of the seedlings on the asteroid. The number passed in returns the seedlings owned by that faction.

Aino:

--- Quote from: Breakord on February 06, 2013, 03:59:13 PM ---lua:513:exception indexing '20'(the number changes each time, '20'or'35'or'2'or...)

--- Code: ---while GameRunning() do
   for i=0,GetNumAsteroids()-1 do--check each asteroid
      local a=GetAsteroid(i)
      if a:GetNumSeedlingsExcluding(a.Owner)>0 then--check if there are other factions' seedlings on the asteroid,which means the battle begins or continues
         for j=0,11 do--check each faction
            if a:GetNumSeedlings(j)>0 then
               for count=0,a:GetNumSeedlings(j)-1 do
                  SeedlingsInBattle[i][j][count]=a:Seedlings(j)[count]--*****Here is line 513*****
               end
            end
         end
      end
   end
...
...
   coroutine.yield()
end

--- End code ---

--- End quote ---

I think it would be good practice to reset this array per tick, I don't really think this will have any huge effect on the performance, but this will ensure that the old list is wiped, which is important!
I'm also wondering if it is possible to do a Seedlings() without any parameter, which I suspect will return the whole array of seedlings.

And:


--- Code: ---for j = 0,11 do--check each faction
if a:GetNumSeedlings(j) > 0 then
SeedlingsInBattle[i][j] = a:Seedlings(j)--*****Here is line 513*****
end
end
--- End code ---
The returned value from Seedlings() is an array, which means you can put it directly in as an array rather than picking out every single seedling "manually".

Breakord:

--- Quote from: Aino on February 07, 2013, 10:35:58 PM ---I think it would be good practice to reset this array per tick, I don't really think this will have any huge effect on the performance, but this will ensure that the old list is wiped, which is important!I'm also wondering if it is possible to do a Seedlings() without any parameter, which I suspect will return the whole array of seedlings.
--- End quote ---
Eh..Actually I have added "SeedlingsInBattle[\i][j]={}"  to reset the array just after I posted this topic..And new codes to detect enemy mines on the asteroid(to detect another kind of battle situation).Unfortunately, I have tried and it is impossible to do a Seedlings() without parameters.

Navigation

[0] Message Index

[#] Next page

Go to full version