### Author Topic: while Puzzle1 == 1 do HelpTomfloria() end  (Read 832 times)

0 Members and 1 Guest are viewing this topic.

#### Tomfloria

• Shrub
• Thank You
• -Given: 0
• Posts: 232
• First iOS modder :D
##### while Puzzle1 == 1 do HelpTomfloria() end
« on: May 22, 2012, 06:03:13 PM »
Right, I can't see to get while loops to use a small pause before whats the in loop actually begins

Code: [Select]
function LevelLogic()
StartLevelLogic()

Puzzle1 = 1

while Puzzle1 == 1 do
WaitReal(4)
GetAsteroid(12):SendSeedlingsToTarget(0,100,GetAsteroid(13))
GetAsteroid(13):SendSeedlingsToTarget(0,100,GetAsteroid(14))
GetAsteroid(14):SendSeedlingsToTarget(0,100,GetAsteroid(15))
GetAsteroid(15):SendSeedlingsToTarget(0,100,GetAsteroid(16))
GetAsteroid(16):SendSeedlingsToTarget(0,100,GetAsteroid(17))
GetAsteroid(17):SendSeedlingsToTarget(0,100,GetAsteroid(18))
GetAsteroid(18):SendSeedlingsToTarget(0,100,GetAsteroid(19))
GetAsteroid(19):SendSeedlingsToTarget(0,100,GetAsteroid(12))
coroutine.yield()
end

end

This is my LevelLogic(), as you know the iOS version has a WaitReal() function which is explained here

Code: [Select]
function WaitReal(t)
t = t + GetRealTime()
while GetRealTime() < t do
CheckConditions()
coroutine.yield()
end
end

Now what I am trying to do here, is make enemy seedlings patrol asteroids, but I don't want them to move onto the next asteroid straight away, I want them to wait say 4 seconds?

But i've realised that the WaitReal() is actually stopping the coroutine.yield from working, meaning it only runs through it once, which is quite annoying.

This:
Code: [Select]
while Puzzle1 == 1 do
WaitReal(4)
GetAsteroid(12):SendSeedlingsToTarget(0,100,GetAsteroid(13))
GetAsteroid(13):SendSeedlingsToTarget(0,100,GetAsteroid(14))
GetAsteroid(14):SendSeedlingsToTarget(0,100,GetAsteroid(15))
GetAsteroid(15):SendSeedlingsToTarget(0,100,GetAsteroid(16))
GetAsteroid(16):SendSeedlingsToTarget(0,100,GetAsteroid(17))
GetAsteroid(17):SendSeedlingsToTarget(0,100,GetAsteroid(18))
GetAsteroid(18):SendSeedlingsToTarget(0,100,GetAsteroid(19))
GetAsteroid(19):SendSeedlingsToTarget(0,100,GetAsteroid(12))
coroutine.yield()
end

Won't send any seedlings at all.

This:
Code: [Select]
while Puzzle1 == 1 do
GetAsteroid(12):SendSeedlingsToTarget(0,100,GetAsteroid(13))
GetAsteroid(13):SendSeedlingsToTarget(0,100,GetAsteroid(14))
GetAsteroid(14):SendSeedlingsToTarget(0,100,GetAsteroid(15))
GetAsteroid(15):SendSeedlingsToTarget(0,100,GetAsteroid(16))
GetAsteroid(16):SendSeedlingsToTarget(0,100,GetAsteroid(17))
GetAsteroid(17):SendSeedlingsToTarget(0,100,GetAsteroid(18))
GetAsteroid(18):SendSeedlingsToTarget(0,100,GetAsteroid(19))
GetAsteroid(19):SendSeedlingsToTarget(0,100,GetAsteroid(12))
WaitReal(4)
coroutine.yield()
end

Will send the seedlings once

This:
Code: [Select]
while Puzzle1 == 1 do
GetAsteroid(12):SendSeedlingsToTarget(0,100,GetAsteroid(13))
GetAsteroid(13):SendSeedlingsToTarget(0,100,GetAsteroid(14))
GetAsteroid(14):SendSeedlingsToTarget(0,100,GetAsteroid(15))
GetAsteroid(15):SendSeedlingsToTarget(0,100,GetAsteroid(16))
GetAsteroid(16):SendSeedlingsToTarget(0,100,GetAsteroid(17))
GetAsteroid(17):SendSeedlingsToTarget(0,100,GetAsteroid(18))
GetAsteroid(18):SendSeedlingsToTarget(0,100,GetAsteroid(19))
GetAsteroid(19):SendSeedlingsToTarget(0,100,GetAsteroid(12))
coroutine.yield()
end

Will send the seedlings constantly without stopping.

But like I said, I want a short break everytime

#### Tomfloria

• Shrub
• Thank You
• -Given: 0
• Posts: 232
• First iOS modder :D
##### Re: while Puzzle1 == 1 do HelpTomfloria() end
« Reply #1 on: May 22, 2012, 06:10:40 PM »
Tried this:

Code: [Select]
function LevelLogic()
StartLevelLogic()

Puzzle1 = 1

while GameRunning() do

while Puzzle1 == 1 do
GetAsteroid(12):SendSeedlingsToTarget(0,100,GetAsteroid(13))
GetAsteroid(13):SendSeedlingsToTarget(0,100,GetAsteroid(14))
GetAsteroid(14):SendSeedlingsToTarget(0,100,GetAsteroid(15))
GetAsteroid(15):SendSeedlingsToTarget(0,100,GetAsteroid(16))
GetAsteroid(16):SendSeedlingsToTarget(0,100,GetAsteroid(17))
GetAsteroid(17):SendSeedlingsToTarget(0,100,GetAsteroid(18))
GetAsteroid(18):SendSeedlingsToTarget(0,100,GetAsteroid(19))
GetAsteroid(19):SendSeedlingsToTarget(0,100,GetAsteroid(12))
Puzzle1 = 0
end

if Puzzle1 == 0 then
WaitReal(4)
Puzzle1 = 1
end

coroutine.yield()
end
end

But seems to stop working at WaitReal() again, it must not work with while loops?

#### annikk.exe

• Achiever
• Ent
• Thank You
• -Given: 0
• Posts: 1,794
##### Re: while Puzzle1 == 1 do HelpTomfloria() end
« Reply #2 on: May 23, 2012, 09:33:17 AM »
Code: [Select]
while Puzzle1 == 1 do
GetAsteroid(12):SendSeedlingsToTarget(0,100,GetAsteroid(13))
GetAsteroid(13):SendSeedlingsToTarget(0,100,GetAsteroid(14))
GetAsteroid(14):SendSeedlingsToTarget(0,100,GetAsteroid(15))
GetAsteroid(15):SendSeedlingsToTarget(0,100,GetAsteroid(16))
GetAsteroid(16):SendSeedlingsToTarget(0,100,GetAsteroid(17))
GetAsteroid(17):SendSeedlingsToTarget(0,100,GetAsteroid(18))
GetAsteroid(18):SendSeedlingsToTarget(0,100,GetAsteroid(19))
GetAsteroid(19):SendSeedlingsToTarget(0,100,GetAsteroid(12))
coroutine.yield()
end

Will send the seedlings constantly without stopping.

But like I said, I want a short break everytime

Code: [Select]
puzzletimer = GetGameTime() + 4
while Puzzle1 == 1 do
if GetGameTime() > puzzletimer then
GetAsteroid(12):SendSeedlingsToTarget(0,100,GetAsteroid(13))
GetAsteroid(13):SendSeedlingsToTarget(0,100,GetAsteroid(14))
GetAsteroid(14):SendSeedlingsToTarget(0,100,GetAsteroid(15))
GetAsteroid(15):SendSeedlingsToTarget(0,100,GetAsteroid(16))
GetAsteroid(16):SendSeedlingsToTarget(0,100,GetAsteroid(17))
GetAsteroid(17):SendSeedlingsToTarget(0,100,GetAsteroid(18))
GetAsteroid(18):SendSeedlingsToTarget(0,100,GetAsteroid(19))
GetAsteroid(19):SendSeedlingsToTarget(0,100,GetAsteroid(12))
puzzletimer = puzzletimer + 4
end
coroutine.yield()
end

There you go :>

#### Tomfloria

• Shrub
• Thank You
• -Given: 0
• Posts: 232
• First iOS modder :D
##### Re: while Puzzle1 == 1 do HelpTomfloria() end
« Reply #3 on: May 23, 2012, 11:05:22 AM »
I could put that in GameRunning() right?

#### Tomfloria

• Shrub
• Thank You
• -Given: 0
• Posts: 232
• First iOS modder :D
##### Re: while Puzzle1 == 1 do HelpTomfloria() end
« Reply #4 on: May 23, 2012, 11:16:42 AM »
It seems to mess up the flow abit, meaning 100 seedlings are sent first, then like 30 because it some of the seedlings didn't make it, I've had a mess about with the numbers and that but I've not had luck :s, is there anyway of manually resetting gametime?

#### annikk.exe

• Achiever
• Ent
• Thank You
• -Given: 0
• Posts: 1,794
##### Re: while Puzzle1 == 1 do HelpTomfloria() end
« Reply #5 on: May 23, 2012, 11:43:39 AM »
It seems to mess up the flow abit, meaning 100 seedlings are sent first, then like 30 because it some of the seedlings didn't make it

I'm not sure what you mean.  Can you explain this to me? :>

The code should work..
Reasons why it might not work are:

1) There weren't enough seedlings at the asteroid to send.  You're attempting to send a total 800 seedlings every 4 seconds.  Since 4000 seedlings is the maximum allowed in the game, you would reach that after 20 seconds.
2) The target asteroid might have reached its cap.  I think the default cap is 1000 or something like that, so this would make sense - the first time 800 seedlings go, the second time only 200 can go...  8 lots of 30 seedlings = 240, which is what you are seeing.  The command Globals.Asteroids.SeedlingCap=(number) sets the default spawn cap on PC.  If you want to specify the cap for an individual asteroid, on PC that is done with GetAsteroid(0).SeedlingCap = number

Quote
I've had a mess about with the numbers and that but I've not had luck :s, is there anyway of manually resetting gametime?

Whatever it is you're trying to do, attempting to change the Game Time is a bad idea.. :>

I think it's point 2) above that causes the issue.  There's nothing wrong with the code I gave you... :>

#### annikk.exe

• Achiever
• Ent
• Thank You
• -Given: 0
• Posts: 1,794
##### Re: while Puzzle1 == 1 do HelpTomfloria() end
« Reply #6 on: May 23, 2012, 11:53:58 AM »
Just noticed you're sending to different destinations each time.  Looks like the seedlings all go round in a circle..

Ok let me suggest something else.

Is this happening because:

After the first move, Astereroid 13 sends seedlings to asteroid 14.
The seedlings all travel at different speeds, some of them arrive at asteroid 14 quickly, others take much longer.

After 4 seconds, it's time for the next round of SendSeedlings commands, but some of those slow seedlings still haven't reached asteroid 14.
So when the command is executed, they haven't yet arrived at asteroid 14.  When they DO arrive a few moments later, the SendSeedlings command has already been executed, but they were too slow and missed it.

Is that what is happening?

In which case, you can either:

1) Increase the speed of the seedlings
2) Decrease the distance between the asteroids
3) Increase the 4 second timer to something bigger like 10 seconds.

Option 3 would be my recommendation:

Code: [Select]
puzzletimer = GetGameTime() + 10
while Puzzle1 == 1 do
if GetGameTime() > puzzletimer then
GetAsteroid(12):SendSeedlingsToTarget(0,100,GetAsteroid(13))
GetAsteroid(13):SendSeedlingsToTarget(0,100,GetAsteroid(14))
GetAsteroid(14):SendSeedlingsToTarget(0,100,GetAsteroid(15))
GetAsteroid(15):SendSeedlingsToTarget(0,100,GetAsteroid(16))
GetAsteroid(16):SendSeedlingsToTarget(0,100,GetAsteroid(17))
GetAsteroid(17):SendSeedlingsToTarget(0,100,GetAsteroid(18))
GetAsteroid(18):SendSeedlingsToTarget(0,100,GetAsteroid(19))
GetAsteroid(19):SendSeedlingsToTarget(0,100,GetAsteroid(12))
puzzletimer = puzzletimer + 10
end
coroutine.yield()
end

#### Tomfloria

• Shrub
• Thank You
• -Given: 0
• Posts: 232
• First iOS modder :D
##### Re: while Puzzle1 == 1 do HelpTomfloria() end
« Reply #7 on: May 23, 2012, 11:57:16 AM »
Just as I was writing what I meant, I've sorted it to work how I want it to

Code: [Select]
function LevelLogic()
StartLevelLogic()

Puzzle1 = 1
puzzletimer = GetGameTime()
while Puzzle1 == 1 do
if GetGameTime() > puzzletimer then
GetAsteroid(12):SendSeedlingsToTarget(0,100,GetAsteroid(13))
GetAsteroid(13):SendSeedlingsToTarget(0,100,GetAsteroid(14))
GetAsteroid(14):SendSeedlingsToTarget(0,100,GetAsteroid(15))
GetAsteroid(15):SendSeedlingsToTarget(0,100,GetAsteroid(16))
GetAsteroid(16):SendSeedlingsToTarget(0,100,GetAsteroid(17))
GetAsteroid(17):SendSeedlingsToTarget(0,100,GetAsteroid(18))
GetAsteroid(18):SendSeedlingsToTarget(0,100,GetAsteroid(19))
GetAsteroid(19):SendSeedlingsToTarget(0,100,GetAsteroid(12))
puzzletimer = puzzletimer + 32
end
coroutine.yield()
end
end

Changed a few minor things, works perfect now, thank you Fluffy.

Edit: In reply to you're recent reply, you're right about the circle, and all the speed is exactly the same, I've sorted it now though
« Last Edit: May 23, 2012, 12:07:31 PM by Tomfloria »

#### annikk.exe

• Achiever
• Ent
• Thank You
• -Given: 0
• Posts: 1,794
##### Re: while Puzzle1 == 1 do HelpTomfloria() end
« Reply #8 on: May 23, 2012, 12:38:29 PM »
Glad you got it sorted. :>

If the seedlings were all the same speed already, maybe it's because some of the started at the near side of the asteroid, whereas others started on the far side, and thus had further to travel.

32 seems much more sensible though.  And I see you've removed the delay at the start, so now seedlings will start to move as soon as it enters the while loop. :>

Looks like you're getting the hang of this.. :>

#### Tomfloria

• Shrub
• Thank You
• -Given: 0
• Posts: 232
• First iOS modder :D
##### Re: while Puzzle1 == 1 do HelpTomfloria() end
« Reply #9 on: May 23, 2012, 03:38:52 PM »
Yes i'm happy now , the reason you stated was why aswell, some seedlings like the dark side of the asteroid :O,

You did say this though... "And I see you've removed the delay at the start, so now seedlings will start to move as soon as it enters the while loop. :>"

So the delay at the start would have been the + 4 am I correct?

So this code tells me...
Code: [Select]
puzzletimer = GetGameTime() + 4
puzzletimer = puzzletimer + 22

puzzletimer = current game time plus 4

then later on...

puzzletimer = puzzletimer which is the current game time plus 4 but now is plus 22

sooooo... if GameTime = 0 then puzzletimer = 22 at this current moment in time?

This code then
Code: [Select]
GetGameTime() > puzzletimer
Would do nothing until GameTime is 22+ yes? which again would do the whole code again and...

GameTime = 22 and puzzletimer = 44 per say?

Really sorry if I sound like I can't speak English here, but this is how I work things out haha.

#### annikk.exe

• Achiever
• Ent
• Thank You
• -Given: 0
• Posts: 1,794
##### Re: while Puzzle1 == 1 do HelpTomfloria() end
« Reply #10 on: May 23, 2012, 04:14:45 PM »
"puzzletimer = GetGameTime()" appears twice.
Once before your While loop, and then again inside the while loop, near the end of it.

The first one is just initialising it, but you could create an additional delay at this point if you wish, like so:

Code: [Select]
puzzletimer = GetGameTime() + 5For a delay of 5 seconds before any seedlings start sending.

Then the second one is the delay you want between each wave.  So for example:

Code: [Select]
puzzletimer = GetGameTime() + 30
That would create a 30 second delay before the next round of seedlings are sent.

So basically the code appears twice.
The first time is to initialise the "puzzletimer" variable, and optionally to add an initial delay before the seeds send for the first time.
The second time is to add on a delay until the next send.

I'll also respond to your questions directly:

Quote
So the delay at the start would have been the + 4 am I correct?

Correct.  :>  In the code I gave you before, I put a 4 second delay by adding "+ 4" to the line that initialises puzzletimer.  :>

Quote
So this code tells me...

Code: [Select]
puzzletimer = GetGameTime() + 4
puzzletimer = puzzletimer + 22

puzzletimer = current game time plus 4

That's right.  The first time the command is run, puzzletimer is set equal to the game time.
So lets imagine 60 seconds of game time have passed so far... puzzletimer therefore is equal to 60.

If we want to create a delay, we should set puzzletimer to be greater than the current game time.
Hence puzzletimer = GetGameTime() + 20

The "If" statement then checks if the gametime is greater than puzzletimer.
In this case the puzzletimer was set at 80 (remember, 60 seconds have passed and as per above we're adding a 20 sec delay)
So game time will proceed and the If statement will be checked lots, but each time it discovers that nope, game time is still smaller than puzzletimer.

Eventually, after say 81 sec, it runs the If statement again and discovers that now, finally, GameTime is greater than puzzletimer.
Then it runs the code inside the If statement, which includes a statement to increase puzzletimer again!

So puzzletimer gets another 20 added on and becomes 100, meaning another 20 second delay until the If statement is triggered again.

Quote
Code: [Select]
GetGameTime() > puzzletimer

Would do nothing until GameTime is 22+ yes? which again would do the whole code again and...

Yes.

Quote
GameTime = 22 and puzzletimer = 44 per say?

Exactly!

Quote
Really sorry if I sound like I can't speak English here, but this is how I work things out haha.

Ah it's all good.  You should see my code comments.
Code: [Select]
-- ahhh seedkkkkkk why doesnt the thing work... i need the PiVariable to be negative.. blah..

#### Tomfloria

• Shrub
• Thank You
• -Given: 0
• Posts: 232
• First iOS modder :D
##### Re: while Puzzle1 == 1 do HelpTomfloria() end
« Reply #11 on: May 23, 2012, 04:22:37 PM »
Now a little bubble has turned up, It seems something went wrong, and now I have 8 asteroids with 700 seedlings which should be split into 7 100's but I have 6 100's and a 64 and 36 now >.<, but I did change the bottom puzzletimer = puzzletimer to 22, so i've put it up to 30 and will do another test :D7

Also thanks again for all your help man, and Aino and Pilchard123 when you've helped, really appreciate it guys!

#### annikk.exe

• Achiever
• Ent
• Thank You
• -Given: 0
• Posts: 1,794
##### Re: while Puzzle1 == 1 do HelpTomfloria() end
« Reply #12 on: May 23, 2012, 05:50:54 PM »
My pleasure :>

Quote
Now a little bubble has turned up, It seems something went wrong, and now I have 8 asteroids with 700 seedlings which should be split into 7 100's but I have 6 100's and a 64 and 36 now >.<

Delicious bugs.. :>
Hmm.  What could be wrong?

One thing I did notice... you say you have 7 asteroids that should have 100 seedlings on each of them, but instead you have 6 asteroids with 100 seedlings each, and an asteroid with 36, and another with 64.
Isn't that 8 asteroids?

#### Tomfloria

• Shrub
• Thank You
• -Given: 0
• Posts: 232
• First iOS modder :D
##### Re: while Puzzle1 == 1 do HelpTomfloria() end
« Reply #13 on: May 23, 2012, 06:11:15 PM »
So imagine an octagon and each point is an asteroid (so 8 asteroids), but there needs to be one asteroid which doesn't have and seedlings on, so when I send a seedling I can move around with the enemy seedlings but without being killed, it's a puzzle so you have to time it correctly. Get me? :p

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