Author Topic: two whiles at once?  (Read 4367 times)

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 4
  • -Receive: 30
  • Posts: 1,527
  • Eufloria: Yes
two whiles at once?
« 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:

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: two whiles at once?
« Reply #1 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

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 4
  • -Receive: 30
  • Posts: 1,527
  • Eufloria: Yes
Re: two whiles at once?
« Reply #2 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 :)
« Last Edit: February 03, 2011, 02:30:54 AM by Aino »

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: two whiles at once?
« Reply #3 on: February 03, 2011, 02:32:18 AM »
No worries!  Glad to help :>