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

0 favourites
  • 3 posts
From the Asset Store
************ 2D top down floor spikes **************
  • 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:

    set randomPiece to round( random(shuffle.Param(1), shuffle.Param(2) ) )[/code:2ng7jv49]
    This works. 
    
    The following should work too, but they don't: 
    [code:2ng7jv49]set randomPiece to int( random(shuffle.Param(1), shuffle.Param(2) ) )
    set randomPiece to floor( random(shuffle.Param(1), shuffle.Param(2) ) )
    [/code:2ng7jv49]
    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:
    [img="http://www.heikokanzler.de/stuff/foren/c2/shuffle2.png"]
    
    [b]Why is int() and floor() not working for me?[/b]
    
    Edit: if I deactivate the inner condition (event 8) int() and floor() work
  • 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...

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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) )

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)