How do I let user input a maths expression e.g.4 +2 *SOLVED*

Just started using Construct 2? Post your questions here

Post » Thu Oct 01, 2015 3:55 am

I want the user to be able to type 4 +2 * 3 into an input field and for the program to work out the result.

I've tried using int(inputField.Text) but it just takes the first number. I've played around putting the string into a global variable but that's not working either.

Any ideas?

Thanks
Last edited by lukeb33 on Thu Oct 01, 2015 5:12 am, edited 1 time in total.
B
4
Posts: 2
Reputation: 204

Post » Thu Oct 01, 2015 4:04 am

Two options I can think of off the top of my head:

1. Create a parser to do it. Algorithms to do this are pretty common.

2. Use the ExecJS() expression in the browser object. e.g. ExecJS("4 + 2 * 3") returns 10. This can open you up to security problems, though, so be careful.
Moderator
B
113
S
41
G
20
Posts: 1,586
Reputation: 19,116

Post » Thu Oct 01, 2015 5:12 am

Awesome thanks, I'll look into those.
B
4
Posts: 2
Reputation: 204


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 3 guests