Euflorium: The Eufloria Community
Eufloria => Eufloria Classic => Eufloria Classic Mods => Topic started by: Breakord on February 06, 2013, 03:59:13 PM
-
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:
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
=_=,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.
-
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?
-
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?
It returns an array of the seedlings on the asteroid. The number passed in returns the seedlings owned by that faction.
-
lua:513:exception indexing '20'(the number changes each time, '20'or'35'or'2'or...)
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
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:
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
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".
-
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.
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.
-
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".
Yes, I know, the reason I didn't is that the array is a userdata value, if put it directly in as an array like
"SeedlingsInBattle[\i][j]=a:Seedlings(j)"
I can't use function "table.getn(Array)" to get the length of SeedlingsInBattle[\i][j] ..
Back on topic, I think Pilchard is right, but I dont know how to prove it.
The error seems to be inevitable, so I am thinking about something like"on error resume next".
-
Yes, I know, the reason I didn't is that the array is a userdata value, if put it directly in as an array like
"SeedlingsInBattle[\i][j]=a:Seedlings(j)"
I can't use function "table.getn(Array)" to get the length of SeedlingsInBattle[\i][j] ..
Back on topic, I think Pilchard is right, but I dont know how to prove it.
The error seems to be inevitable, so I am thinking about something like"on error resume next".
I don't think that's the cause, but you can prove it by testing it. Just create a map with two asteroid, and one which has seedlings and you simply move your seedlings from one asteroid to the other. Try different distances between the asteroid, some factors may come in to count?
I don't this it's the cause tough,since if a seedling leaves the asteroid, it won't be counted as on it anymore and the seedling should be erased from the array.
One thing you can do, when adding them to the array, is to simply check if they are nil values, also try using the "assert" function when checking them. It MIGHT work :)
-
I don't think that's the cause, but you can prove it by testing it. Just create a map with two asteroid, and one which has seedlings and you simply move your seedlings from one asteroid to the other. Try different distances between the asteroid, some factors may come in to count?
I don't this it's the cause tough,since if a seedling leaves the asteroid, it won't be counted as on it anymore and the seedling should be erased from the array.
One thing you can do, when adding them to the array, is to simply check if they are nil values, also try using the "assert" function when checking them. It MIGHT work :)
Thanks~:)
-
I don't think that's the cause, but you can prove it by testing it. Just create a map with two asteroid, and one which has seedlings and you simply move your seedlings from one asteroid to the other. Try different distances between the asteroid, some factors may come in to count?
I don't this it's the cause tough,since if a seedling leaves the asteroid, it won't be counted as on it anymore and the seedling should be erased from the array.
One thing you can do, when adding them to the array, is to simply check if they are nil values, also try using the "assert" function when checking them. It MIGHT work :)
By the way, there is no nil value in arrays in lua...when you try to get a null element, an exception will occur "exception indexing '20'".
It is different with trying to get a undefined variable, which an error will occur "a nil value".
So it is impossible to check if it is the end of the array through checking if the value is nil..
:)