Author Topic: Argh, stupid code.... am i blind?  (Read 5690 times)

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Argh, stupid code.... am i blind?
« on: January 24, 2010, 12:56:52 AM »
Code: [Select]
--level 3 wave 1 - THIS WORKS FINE

if levelthree == 1 and GetGameTime() > Timer and wavenumber == 0 then
GetAsteroid(9):SendSeedlingsToTarget(2,500,GetAsteroid(7))
wavenumber = 1
GetAsteroid(9):AddSuperSeedlings(1000)
Timer = GetGameTime() + 300

Pause()
MessageBox("Level 3 - Wave One")
WaitDialog()
Unpause()

end


--level 3 wave 2 - THIS DOESN'T WORK - WHY??

if levelthree == 1 and GetGameTime() > Timer and wavenumber == 1 then
GetAsteroid(9):SendSeedlingsToTarget(2,1000,GetAsteroid(7))
wavenumber = 2
GetAsteroid(9):AddSuperSeedlings(1200)
Timer = GetGameTime() + 300

Pause()
MessageBox("Level 3 - Wave Two")
WaitDialog()
Unpause()

end

This is a short extract from a gigantic While loop in my function LevelLogic().
Wave 1 is triggering.  Wave 2 is not.  I can't work out why.

I've been staring at this code for ages but as far as I can tell, when wave 1 is triggered that should set everything in motion for wave 2 to be triggered 5 minutes later... but in the game, it just doesn't happen.  It reaches 5 minutes after wave 1 began, and wave 2 does not begin.  Nothing happens at all.  No message box, no new seeds, no swarmy attacking action.  It seems like not all of the conditions of that If statement are being met...

Anyone has any ideas what could be wrong? :>
« Last Edit: January 24, 2010, 01:44:16 AM by annikk.exe »

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Argh, stupid code.... am i blind?
« Reply #1 on: January 25, 2010, 02:32:02 AM »
Tried adding a second While loop in case there was a limit to the number of If statements I can have in each While, but that didn't work.

I did some testing to generate message boxes when levelthree = 1 and that worked, it is being set to 1, so that condition is being met.
Next I tested to see if wavenumber = 1, and sure enough the message box came up at the right time, so that condition is also being met.
That could mean that timer is not being met.

So I tried using a different variable to trigger wave 2, in case Timer was being screwed up by something else... that didn't work either.  I'm not sure what else to try to get this to work....as far as I can tell, all of this is immaculate code that I have used successfully elsewhere in the level.  :S

Please halp, someone ?

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Argh, stupid code.... am i blind?
« Reply #2 on: January 25, 2010, 03:26:01 AM »
Just had a breakthrough, discovered if I just use the sequential nature of the Function Level Logic and use While loops to coroutine.yield to delay the progress by however much I want, that works...

I'm not sure why my old method doesn't work, but I've found a workaround now so I'll be using that from now on.. :>

evoke

  • Guest
Re: Argh, stupid code.... am i blind?
« Reply #3 on: February 28, 2010, 07:04:36 AM »
I realize you've solved this to your partial satasfaction, just remarking
it would be easier to put a dialog inside your second if to check all conditions at once.
If you get the text, you entered and it will be a send seedlings related constraint on
superseedlings or sufficient seedlings or the like, if not, you know it was if conditional
or code getting hung up earlier in some kind of wait or dialog stuck state.

Note: I don't know LUA or the Eufloria API yet, (reading up), so purely chopping logic abstractly.
I have just started browsing some custom levels lua for the learning experience.

You have a vareity of nifty coding techniques on initial browse, btw.
And verbose commenting.  :-) Posted in large part just to say thanks for that.
Makes the learning curve a lot nicer.

-evoke

evoke

  • Guest
Re: Argh, stupid code.... am i blind?
« Reply #4 on: February 28, 2010, 07:09:55 AM »
Misc:

I'd check the return value...?
I notice you don't do that much.

Not critiquing, merely saying I see no overt flow control bug,
but reading the api notes the call only says it attempts to send,
not that it guarentees it.  Since it sends when you wait by a yield method,
probably not the call per se, just putting in the good word for return value checks.

You might try bulletproofing calls with checks on the seedling count before
sending, or sending the seedlings the census count returns as a more robust
technique to the unexpected.

Again, I don't know lua / eufloria well yet, but we woudln't want players able to
monkeywrench cheat our hard levels by nicking 1 seed off a 1000 seed count
world and shortcircuiting a wave from launching.  :-)  Not sure if it would work
that way, and tangent to your thread, merely chatting.

-evoke