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

0 Members and 1 Guest are viewing this topic.

Aino

• Ent
• Thank You
• -Given: 1
• Posts: 1,492
• They'll eat you next!
• Eufloria: Yes
two whiles at once?
« on: February 02, 2011, 04:48:50 PM »
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
• Posts: 1,794
Re: two whiles at once?
« Reply #1 on: February 02, 2011, 04:56:03 PM »
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 -- codeelseif warnasteroid:GetNumSeedlings(0) == 0 and warnasteroid:GetNumSeedlings(2) == 0 and warnasteroid:GetNumSeedlings(3) == 0 then -- other codeend`

Aino

• Ent
• Thank You
• -Given: 1
• Posts: 1,492
• They'll eat you next!
• Eufloria: Yes
Re: two whiles at once?
« Reply #2 on: February 02, 2011, 05:05:56 PM »
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 02, 2011, 06:30:54 PM by Aino »

• Achiever
• Ent
• Thank You
• -Given: 0