wait in loops

Get help using Construct 2

Post » Sat Dec 28, 2013 8:55 pm

Trying to get my head around the wait x seconds. Don't know if it is a bug or more likely that I've gone brain dead from playing at the computer nearly all day.

All I have got is a sprite set towards the middle of the screen




Now I thought this would move the sprite slowly to the right of the screen (with a 0.1 second delay between each move) ?

It goes left and loopindex is sent to the text box as -1.

If I disable the Wait loopindex*0.1 seconds then it goes to the right (obviously without the delay).

Please someone point me at what I am doing wrong as I am pulling my hair out (and I didn't have much to start with !)

capx
August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
33
G
47
Posts: 1,194
Reputation: 30,812

Post » Sat Dec 28, 2013 9:10 pm

Events run every tick, top to bottom.
A loop in an event is ran, and then moves on to the next event, so any waits happen asynchronously.

What you are wanting is for it to move, and then move again.
Those must be separate ticks.
Image ImageImage
B
168
S
50
G
164
Posts: 8,239
Reputation: 105,597

Post » Sat Dec 28, 2013 9:15 pm

Try naming your loopindex:

Conditions:
For "Step" 1 to 10

Actions:
Wait loopindex("Step")*0.1 seconds
Sprite Set X to Sprite.X + loopindex("Step")/100

Alternatively, you could just do something like:

Conditions:
Every 0.1 Seconds

Actions:
Sprite Set X to Sprite.X + 1

You might be able to get smoother movement using lerp though:

Conditions:
Every Tick

Actions:
Sprite Set X to lerp(Sprite.X,Sprite.X + 1,dt*60)


I've not upgraded to r155 so can't open your example, I made this instead with the 3 methods above (two disabled):
Example r152OddConfection2013-12-28 21:40:27
Vote for all the Construct 2 games on Steam Greenlight - Find them here
B
32
S
9
G
7
Posts: 444
Reputation: 6,731

Post » Sat Dec 28, 2013 10:15 pm

Thanks for the replies.

I know this was a bad example I was just trying to get my head around the ideas.

I have no idea why it was going left - OddConfections went right ?

Obviously my loop was running and then running again and again. Also as I was adding loopindex and loopindex would be getting bigger then the step (to the right) would also get bigger.

Anyway after a couple of changes it is running as expected



Thanks for the help.

edit to add picture

Thanks for the help.RamPackWobble2013-12-28 22:17:34
August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
33
G
47
Posts: 1,194
Reputation: 30,812

Post » Sat Dec 28, 2013 10:28 pm

August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
33
G
47
Posts: 1,194
Reputation: 30,812


Return to How do I....?

Who is online

Users browsing this forum: Google [Bot], MaxxMunnn, ome6a1717 and 2 guests