making a simple retro game that generates numbers at the click of a button

0 favourites
  • 8 posts
From the Asset Store
Make your own platformer for both the web and mobile easy with this Santas Platformer Template, FULLY DOCUMENTED
  • was wondering how I could create a button that when pressed it would generate a random number between 1 and 1000 eg 543 and display it in a text box

    Then when u press the button again it will display a number that is between the recently selected number (in this example 543) and 1

    and then u press it again and again until it displays the number 1.

    The premise is that it is a chance game and the person that clicks the button and displays the number 1 is the loser.

  • that's what I have to begin with, sorry if it is very wrong I'm new to construct.

  • aliiwhiite Don't use round() with random, it produces uneven results. To get a number from 1 to 1000 use int(random(1,1001))

    So the code should be something like this:

    Variable R=1000
    
    On button pressed
    ...Set R to int(random(1, R+1))
    
    .....Compare variable R=1 : Text set text to "You lost!"
    .....Else : Text set text to "Random value=" & R
    
    
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • how do I put in a an if or else function- so that if variable is one u will lose but if its anything else it will run the variable again with the number given?

  • when I run it like this it just displays a 1 when I click the button

  • how do I put in a an if or else function

    "if" is just a pseudocode. Use "System Compare variable" condition. And to add "Else" step, select that condition and press X on keyboard.

    when I run it like this it just displays a 1 when I click the button

    Maybe the text is too small? Also, the formula should be int(random(1, variable1+1))

  • got it fully functioning thanks heaps mate

    just want to make the game more interactive- is there a way to make a sprite appear when the value of the text box is 1 (when the value of Variable1 is 1, because I tried to use the compare variable function but it doesn't seem to work and the sprite will just appear at the start of the game

  • Set the sprite invisible by default (in the editor). When the variable=1, set it visible.

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