# Use % and Random expressions for endless runner

Get help using Construct 2

### » Sat Dec 22, 2012 4:20 am

I am trying to build a game based on the following tutorial built in a different game engine...

http://gamedev.tutsplus.com/tutorials/from-scratch/build-a-canabalt-style-infinite-runner-from-scratch/

I am having trouble with the random platform generation and increasing the speed over time.

https://dl.dropbox.com/u/76047537/Endless_Runner_Example.capx

When I enable Line 11 the platforms stop generating.
B
4
S
1
Posts: 9
Reputation: 918

### » Sun Dec 23, 2012 5:51 pm

Hey there, Figured out your problem...
in line 7 & 8 instead of saying ticker%32/run_speed = 0 add two conditions.
if ticker%32/run_speed > -1      &&
ticker%32/run_speed < 1.

Purely because by changing run_speed to 5 you are returning a float value which is not = 0. Hope that helps.

What will happen is you will have gaps between your created objects so just change their width to 64px.

Peace
DC
B
7
S
1
G
1
Posts: 5
Reputation: 645

### » Sun Dec 23, 2012 5:56 pm

Sorry, i was just thinking their is an easier way..
all you do is add floor() to all of your equations to round them off eg.

floor(ticker % 32 / run_speed)=0

that also works
B
7
S
1
G
1
Posts: 5
Reputation: 645

### » Sun Dec 23, 2012 11:39 pm

Awesome!! Thank you!! That worked out perfectly using floor(ticker % 32 / run_speed)=0 and changing the platform size to 64px.

My other issue is on line 9 & 10 where I am trying to set a global variable to a random number but it doesn't seem to work, any ideas??

Here is the updated .capx

https://dl.dropbox.com/u/76047537/Endless_Runner_Example.capx
B
4
S
1
Posts: 9
Reputation: 918

### » Mon Dec 24, 2012 3:29 am

Hey Hey,

a random() argument takes in two numbers. so for eg.
random(0,5) will pick a number between 0 and 5 including float numbers.
and if you want an int its the same story as your previous posts floor(random(0,5))...
B
7
S
1
G
1
Posts: 5
Reputation: 645

### » Mon Dec 24, 2012 6:19 am

Thanks again worked like a charm
B
4
S
1
Posts: 9
Reputation: 918

### » Mon Dec 24, 2012 7:57 am

No Problem.... Enjoy!
B
7
S
1
G
1
Posts: 5
Reputation: 645

### » Mon Feb 18, 2013 10:06 am

Thank you so much for this! I've been banging my head for hours against why using a random value stopped the platforms from generating in my game. I didn't know the random numbers generated would be anything other than integers! This has really helped, thank you so much!

Argh I'm so happy I finally got past this problem.
B
13
S
3
Posts: 4
Reputation: 1,781

### » Sat Feb 23, 2013 5:44 am

Hello! Sorry to be opening this old post again, but could some explain what exactly is going on in the event sheet here? I downloaded the .capx file, I hope that that is okay.

I am unable to understand, the "floor(ticker % 32 / run_speed) = 0". Could someone please explain?

Thank you.
B
3
Posts: 6
Reputation: 512