# Need help with subtraction problem

Do = RandomInRange(1,9) to the value of scene variable ‘number1’
Do = RandomInRange(1,10-Variable(number1)) to scene variable ‘number2’
Do = Variable(number1) - Variable(number2) to the value of scene variable ‘result’

I get random options as 2-8, 2-3 etc… And result is negative…How to avoid negative result to those random combinations, and make it that always be (first number higher than second by subtraction)…?

Is there maybe way to achieve that wit external javascript event?

1 Like

You can use the absolute library function to always get a positive result.

Supposing that the variable var contains a value -10. The above expression will return a result of 10.

Do = abs(Variable(number1) - Variable(number2)) to the value of scene variable ‘result’

should work

Thank you so much…Great!..It works perfect, but there is one visual problem. I want my kid learn Math and it is bit a problem when he see e.g 2-8, OK now game accepts result as 6 that is fine, but my idea is to swap e.g 2-8 to 8-2 in case that first number is smaller just because of learning logic…Is that possible?
I mean that always random combination begins like 8-2 not 2-8, because it will be confusing .

Thank you very much!

Regards

David

1 Like

In order to make sure the second number never be higher than the first number, you can:

Do = RandomInRange(1,Variable(number1)) to scene variable ‘number2’

1 Like

Thank you man for your help again!..I tried that you wrote but it does not work…I still get combinations as 2-7 etc…

Regards,

David

I also tried to insert that scene variable in the game you uploaded last time, but still does not work…

While displaying the variable value in the required field, try comparing the two number, number1 and number2 and display the greater one first.

Event1: If value of number1 >= value of number2, then
display number1, then number2

Event2: If value of number2 >= value of number1, then
display number2, then number1

It should work because by using Variable(number1) as the maximum value in the range, the value of number2 should never be higher than the value of number1.

The example with structures uses different logic, you can’t just copy variables and expect it to work I’m afraid.

Thank you for your advice!..I understand principle but I do not know how to make part—>display number1 than display number 2

Regards…

Finally I could to fix that, now higher number is always first but I have another problem some combinations repeat much more than others…Your example is much better but there is problem that I do not know how to swap numbers so that higher always be first…Oh my god, by me always missing something…

Regards…

This is why I was using structures after. It is more complicated, but fixes the problem of certain numbers repeat too often while others never come up. Not sure how otherwise could be fixed easily because it is depends on what seed the random number generator is using but we can not use custom seeds as far as I know.

I meant that after comparing which number is greater, display the greater number on the left, then the other number on the right.

If you could send a screenshot of the way you are displaying the numbers, it would help

@ddabrahim’s way is nice too

So kind of you, thanks man…Thing is that I could finally swap numbers, but my problem is that some random combinations repeat too many times…ddabrahim’s example is much better but thing is that I do not know and he does not know how to swap numbers, so that in both games, mine and his missing something…lol

Here is my way with some recommended parts by ddabrahim…

1 Like

Thank you anyway for your time and your help!..It was very kind of you to try to help me…

Regards…

I’m a little confused, in case my suggestion worked than you don’t need to swap numbers because the second number should never be higher than the first and as far as I know the examples with structure I give you the other day does solve the problem of certain numbers repeat. Even if you can’t figure out the logic how it works, you can just replace the images and staff in the project I shared. I know it is not easy to see through, but unfortunately I don’t have time to explain in more detail.

ddabrahim,

To be honest I did not expect so much help, you have no idea how much I appreciate your time and effort to help me. You waisted so much time trying to help me, and I just can say that you are one great guy!.. To explain logic of all this you made to the guy like me with basic knowledge is no meaning. I did not expect that you need to explain all of that to me, because that what you have done for me is for my side more than enough, and I really feel bad about fact that you waisted your time because of me. Thank you very much ddabrahim!..

Concerning your example of the game, I tried that but as I said before combinations are great, but I still get combinations with negative result e.g 5-7…I do not know if you have updated game in the mean time?..I will download again your game and I will test it again. By now I do my version so far…

Thank you!

Greetings…

You are great!..I tested subtraction game, it works perfect…Thank you so much!!!..I will try to implement your source to the game I do, that is easiest way because I can not do over all sprites and tween motions, it is much work…

Thank you so much…

Greetings…

2 Likes