Euflorium: The Eufloria Community
Eufloria => Eufloria Classic => Eufloria Classic Mods => Topic started by: elideb on May 17, 2011, 07:51:00 AM
-
Hi, I recently bought Eufloria, just to make some levels and learn a bit of Lua.
In my first complex level I have stumbled onto the RemoveSeedlings bug (http://www.dyson-game.com/smf/index.php?topic=1338.0) and it is driving me crazy. Does anyone know of some way to achieve the same behaviour while avoiding the crash?
So far I've tested things like
local i = 0
for i = 0, numToRemove do
asteroid:RemoveSeedlings (faction, 1)
end
but it still crashes in the loop, if numToRemove is big enough.
What I am trying to do is change some seedling's faction, so I remove them from the planet and add them with the new faction and stats. If there is another way to do that, I'll be pleased as peaches =)
Thanks!
-
RemoveSeedlings() crashes, I gave up at once I figurd it out...
-
Hi, welcome. :>
Is it the case that the for loop crashes because it's trying to remove too many seedlings?
Ie it loops 10 times, removing one seedling each time, but there were only 5 seedlings to begin with so it crashes when it tries to remove the 6th?
If that's the case, try something like this:
local i = 0
for i = 0, numToRemove do
if asteroid:GetNumSeedlings(1) ~= 0 then
asteroid:RemoveSeedlings(1, 1)
end
end
You're saying "ok Mr Loop, I only want you to remove seedlings IF the number of Player 1 seedlings present at the asteroid is not 0."
So in the example above, after all 5 seedlings have been removed, the number of seedlings would be 0, so the remove command would not be triggered again. The rest of the loop iterations would finish harmlessly.
-
yuo don't need to the line local i = 0. I think.
-
It's not needed, but making your variables local can speed things up. It's just a performance thing though.
-
RemoveSeedlings() crashes, I gave up at once I figurd it out...
I'm about to, as well. I'm rethinking my level so that it does not depend on rebelling troops...
Hi, welcome. :>
Is it the case that the for loop crashes because it's trying to remove too many seedlings?
As a matter of fact, removing seedlings from an empty asteroid has never crashed in my tests =)
I'm afraid that's not the problem. In my level I remove a percentage of the asteroid's population belonging to a given faction. And in my tests I verified that I did not remove more seedlings than available in the asteroid.
The closest I've got to pinpointing the crash is that it occurrs when a sufficiently high percentage (30%-50%) of the existing population is removed. So, removing 1 from a population of 20 is alright, but removing one out of 4 is (usually) not.
Thanks for trying!
yuo don't need to the line local i = 0. I think.
I use the local so that it does not overwrite any global variable named the same declared somewhere else. It's a good practice when using names that typical in languages defaulting variables to global.
-
Oh, okay.
Would it be okay to remove the same percentage of the seedlings from an increaingly smaller number of them? So like:
N = Number of seedlings to leave remaining
X = Asteroid ID
E = Empire number
math.huge is the Lua equvalent of +- infinite
for i=0, math.huge()
if GetAsteroid(X):GetNumSeedlings(E) >= N
GetAsteroid(X):RemoveSeedlings(math.floor(GetAsteroid(X):GetNumSeedlings(E)*SafeProportion))
else
break
end
end
I think that's all usable, but I haven't Lua'd for a while. You could probably do it in a while loop, but I can't be bothered to rewrite it.