How do I use int / floor? (Wierd: only round() works)

Get help using Construct 2

Post » Sun May 03, 2015 8:03 am

This one drives me crazy. It must be something stupid simple, but I can't get my head around it.

I have a function shuffle with three params. Params(1) and Params(2) are the boundaries for a random number. Simple:
Code: Select all
set randomPiece to round( random(shuffle.Param(1), shuffle.Param(2) ) )

This works.

The following should work too, but they don't:
Code: Select all
set randomPiece to int( random(shuffle.Param(1), shuffle.Param(2) ) )
set randomPiece to floor( random(shuffle.Param(1), shuffle.Param(2) ) )

The game simply doesn't start (black screen) and I get sometimes a browser error "Uncaught TypeError: Cannot read property 'current_even ' of undefined" and I event can't close the browser window.

The function has a inner condition and calls itself in case the new random number is the same than the given shuffle.Params(0) param:
Image

Why is int() and floor() not working for me?

Edit: if I deactivate the inner condition (event 8) int() and floor() work :?:
B
7
S
2
Posts: 38
Reputation: 577

Post » Sun May 03, 2015 9:44 am

My guess is that C2 does not do all the conditions sequentially (the logical way), it does everything at the same time. So basically randomPiece at 7 is NOT computed before the condition 8 is tested.

You should add wait to do anything in order you like...
B
7
S
2
Posts: 68
Reputation: 645

Post » Sun May 03, 2015 12:25 pm

To use int or floor, you need to add one to the second parameter, or that number will never be reached, as it is exclusive, not inclusive.

https://www.scirra.com/manual/126/system-expressions

So, int( random(shuffle.Param(1), shuffle.Param(2) + 1) )
ImageImageImage
B
71
S
21
G
221
Posts: 3,649
Reputation: 124,227


Return to How do I....?

Who is online

Users browsing this forum: Yahoo [Bot] and 16 guests