math calculation

0 favourites
  • 3 posts
From the Asset Store
Aliens are invading our planet! Solve the math question, and attack the alien with your laser. Covers addition, subtract
  • Hi I'm new to Construct 2 and i'm trying to work out how to have 4 text boxes which return 2 with random number 1-10 and in and the third box to have random + - * / so that when i click on a sprite the two number boxes work out the math in the third and put the answer in another text box if anyone has a capx or a answer it will be greatly appriciated. Cheers RoyRobbo

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • on Start of Layout:

    -set Text to round(random(1,10)) for the 2 number text objects. (Number1Text and Number2Text)

    -set Text to choose("+","-","*","/") for the operator text box. (OperatorText)

    Then on Sprite click (your action button)

    -if OperatorText.text = "+" then Set AnswerText.text to int(Number1.text) + int(Number2.text)

    etc.. for each operator

    You need some other User button to reset the fields, so I suggest a Clear/Reset button which you can just re-execute the code in On Start of Layout.

  • so that when i click on a sprite the two number boxes work out the math

    You need to add the Mouse Object (double click the gray area in the Layout View).

    This will enable to have a Mouse Event called ->OnMouseClick: click on object

    that object should be your sprite that you mention in your post.

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