math calculation

Just started using Construct 2? Post your questions here

Post » Thu Oct 02, 2014 3:51 pm

:lol: 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
B
8
S
4
Posts: 9
Reputation: 770

Post » Fri Oct 03, 2014 3:08 pm

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.
B
88
S
29
G
14
Posts: 1,158
Reputation: 15,011

Post » Sat Oct 04, 2014 1:17 am

Robbo128 wrote: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.
B
88
S
29
G
14
Posts: 1,158
Reputation: 15,011


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 0 guests