# How do I set up my events for my maths puzzle game?

Hi

Ive started my first game a maths puzzle game but have run into a road block.

I need to set up my events so that if the player presses the correct order of calculations to reach the final desired number he proceeds to the next level, or if he gets the calculation wrong the level restarts.

Any help would be amazing.

Best Wishes

Iâ€™m new in GDevelop so I canâ€™t really give you a complete answer, however Iâ€™m not new to programming so maybe these steps would help you:

I guess youâ€™d have to save in an array which objects were selected, and when the user is done selecting blocks, then extract from each element in this array the mathematical value and, if possible, evaluate the mathematical expression in order to compare it to the desired value.

When creating your level, youâ€™d have to store, somehow, an ID of the object, or its value directly, in this array.

Iâ€™m not sure if itâ€™s possible to evaluate a mathematical expression in GDevelop, meaning calculating the result of an expression received from user input (like the user typing 5+5 in an input, Iâ€™m not sure if GDevelop is able to do the maths for us).

However, I know itâ€™s possible in JavaScript: eval() - JavaScript | MDN

Hope itâ€™s useful

1 Like

Iâ€™m hoping it is possible in Gdevelop.

Here is my events set up thats presently not working:

If you manually build each level, then create a scene variable named â€śuser_valueâ€ť (or something like that) and then create an event for each button.

Imagine this level:

• current_value = 10
• desired_value = 20

the grid of possibilites:

x2 -10 /3
/4 +5 -9
x9 +9 +5

Considering you read the grid from left to right, line by line, starting at 0, then the correct answers would be: pressing BUTTON4 (adding 5 to â€śuser_valueâ€ť) and pressing BUTTON8 (also adding 5 to â€śuser_valueâ€ť).

If you make it so that when you press a button the â€śuser_valueâ€ť is modified, then you can make this work.

My first answer was a solution for creating dynamic levels, but if you create each level manually then this is fine. Forget about the array variable I mentioned in my first answer.

1 Like

I will continue to experiment

Any further advise would be great

For another user i made keycode to open doors like a code for bank safe
Where you need to input 4 digits in correct order to open it
Code is 5 1 8 4
If you hit wrong number at it expected number for example
You input 5 1 7 or 5 1 3 it will reset back to expecting first digit

I was new to gdev when i was doing it so it is Frankensteins craft but it works
Go to the right stand close to spinning saw and text will appear waiting for â€śkeysâ€ť to be input (which are just numbers 5 1 8 4)

1 Like

Thanks for the information

Do you think you could fix my maths game?

Sure i could

I am really not best person to do it
Just to give you example
When i was young working and register in fastfood
Girl give me 20\$ to pay for her food
Instead of giving her 10\$ change
I gave her 100\$ change

That kind of dyslexia i have
And ADHD helps me NOT be able to easily come up with ideas to solve most problems

So if no one else can solve your issue i can help but better for you to wait for some big brain here to solve it

1 Like

Hopefully some one can help

ok no worries, I am dyslectic as well.

It can cause problems.

If your problem is not solved till monday just reply to me here and i will see what i can do

I think this is most fair deal i can offer

1 Like

BTW Keith is big brain so have faith in what he suggests and follow his instructions

1 Like

Thankyou for the help

1 Like