Random randomness

0 favourites
From the Asset Store
Easily generate many levels from a set of pre-built scenes (Construct 3 template)
  • can anybody help me i cant understand why this wont work?

    im trying to get the police sprite to spawn when the letters deliverd variable reaches a random number between 1 and 6

    have a look its pretty obvious what im trying to do.


  • change random(7) to int(random(7)) so only whole numbers are used 0,1,2,3...

  • thankyou

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • EDIT: Great... R0j0 beat me to the punch... Anyway this is a different way of doing it.

    Is this what you're after?

    Keep in mind this doesn't take into account if a policeman is already at the house... That's a bit more complex.

  • for some reason when i use int(random()) the police man appears at the begging of the layout, thats not what im after i want him only to spawn when the random number has been reached?

  • sqiddster

    yeah that would work but im just trying to understand how the random() function works, yours is more advanced than i need it to be.....but thats probably the way to go

  • Yeah, the random() function is a bit tricky with its upper and lower bounds. Keep in mind you have floor() and ceil(), which will either truncate, or truncate and add one.

    Here's what you get from int, floor, and ceil:

    ceil(5.6) gives 6

    floor(5.6) gives 5

    int(5.6) gives 5

    That's right, the int function does not round.

    Keep this all in mind, and in some cases, consider using the choose() function to randomly choose between a fixed set of parameters.

  • can i do choose(random()) its telling me something about parameters

    i thought seeing as the letters variable was a definite number 1,2,3 etc

    the random() function would be able to choose a number between the parameters you can set with equal to (the random number)

    i think that makes sense, its been a long day

  • ive looked at it again and this should work but alas it does not

    when i run it without using int(random()) and just put in a number, it works? bizarre, ive checked the relevant tutorial and this is what it tells me to do..........

    where am i going wrong?

    example 2

  • Your capx is messed up as it is not choosing a random house... You are doing something about letters.

    Maybe it would be better if you told us exactly what you want to accomplish.

    If you want him to appear at a random house, use the capx I sent you. What about mine isn't working for you?

    To choose from a set of parameters, use the choose() function.

  • yeah sorry ive not made it very clear

    what i want is the post man to go about delivering his letters, so six in this one.

    i want then to be able to spawn an object at a random drop off, so between 1-6 in the letters variable

    (the last capx i posted was the wrong one, ill try and find it....)

    here we go


  • You want to generate the random number once at the start of the layout. The way you're doing it, you're comparing letters to a new random number every tick.


  • ramones

    yeah so how do i generate that number? your capx wont work for me im getting document error

  • ok a good nights sleep and a fresh pair of eyes later, ive managed to sort it out.....thanks to everyone that helped me

    heres what i did in the end.....example3

  • I don't know what you're trying to do. Here's a 'random' explanation: int(random(5)) gives you a number between 0 and 4. int(random(5,10)) will give you 5 to 9

    Your events doesn't make sense to me

    EDIT: we posted at the same time >_<

    Oh now I get what you wanted to do

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