Euflorium: The Eufloria Community

Eufloria => Eufloria Classic => Eufloria Classic Mods => Topic started by: Aino on February 03, 2011, 12:48:50 AM

Title: two whiles at once?
Post by: Aino on February 03, 2011, 12:48:50 AM
Ok, so I got another obstacle just before releasing my map, I got the warning system working as it uses a while lop like this:
Code: [Select]
function CheckAttacks() --Warns the player when asteroids are attacked

for i = 0,99 do

local warnasteroid = GetAsteroid(i)
local b = warnasteroid.Owner
local c = warnasteroid.ID

if b == 1 then

while warnasteroid:GetNumSeedlings(0) > 0 or warnasteroid:GetNumSeedlings(2) > 0 or warnasteroid:GetNumSeedlings(3) > 0 do

if b > 0 then
b=b-2
end
if g > 0 then
g=g-2
end
if r > 99 then
redcolor = -2
end
if r < 33 then
redcolor = 2
end
r=r+redcolor
SetBackdropColor(r,g,b)
coroutine.yield()

end
while warnasteroid:GetNumSeedlings(0) == 0 and warnasteroid:GetNumSeedlings(2) == 0 and warnasteroid:GetNumSeedlings(3) == 0 do

if b < bb then
b=b+1
end
if g < bg then
g=g+1
end
if r < br then
r=r+1
end
SetBackdropColor(r,g,b)
coroutine.yield()

end

end

end

end

Any help, because all the other functions stopped working after this was made D:
Title: Re: two whiles at once?
Post by: annikk.exe on February 03, 2011, 12:56:03 AM
Where is CheckAttacks() being called?
If it's also inside a While loop, then that won't work the way you want it.  I don't think you can nest While loops in that way.

You could change it like this perhaps:

Code: [Select]
if warnasteroid:GetNumSeedlings(0) > 0 or warnasteroid:GetNumSeedlings(2) > 0 or warnasteroid:GetNumSeedlings(3) > 0 then

-- code

elseif warnasteroid:GetNumSeedlings(0) == 0 and warnasteroid:GetNumSeedlings(2) == 0 and warnasteroid:GetNumSeedlings(3) == 0 then

-- other code

end
Title: Re: two whiles at once?
Post by: Aino on February 03, 2011, 01:05:56 AM
Thanks again annikk, like the third time I think? Well, I also got in notice that I used b as a global variable and b as a local variable at the same time several times :)
Title: Re: two whiles at once?
Post by: annikk.exe on February 03, 2011, 02:32:18 AM
No worries!  Glad to help :>