Mathematics Game

Hello


I'm currently making a Mathematic game for kids 


I'm making a basic four types of operation : multiply , addition , division and subtraction


The rest are done but I'm currently stuck on division operation part


If I do normally , the answer is still correct , its just that there are no decimal point


for example 3 / 2 = 1


But it should be 1.5


What I'm trying to achieve is :


A variable that holds one decimal point


A way for player to answer the question in one decimal point too.


How do I achieve that?


Thank you very much!


#EDIT


Succesfully stored value into variable


Here's the code if someone interested


I used the Control Variable event to generate random numbers


var x = $gameVariables.value(1); // get value from variable that stores num 1
var y = $gameVariables.value(2); // get value from variable that stores num 1
var z = (x /y).toFixed(1); // Divide operation and toFixed(how_many_decimal)
$gameVariables.setValue(4, z); // Assign the value into variable


So now all is left is how to let player answer in decimal too 🙁  


Untitled.png
To hold one decimal point


n = a/b; // Where a/b is the division operation

n = n * 10; // Multiply by 10 to shift the dot to the right

n = Math.floor(n); // It will trim everyting after the integer value

n = n / 10; // Dividing by 10 to shift the dot back to original place




Sorry about the "moving the dot" comments. I don't know how to explain properly in English when there's numbers after the dot.


Also there's probably a function that automatically trims the the value in a single line.


A way for player to answer the question in one decimal point too.


I have a piece of code that parses a string and returns a integer/float. It's probably not the easiest way to implement. I'm going to wait a little bit to see whether someone else answer. If no one else gives a solution about the second part, I can post my code here. 🙂
To hold one decimal point



n = a/b; // Where a/b is the division operation

n = n * 10; // Multiply by 10 to shift the dot to the right

n = Math.floor(n); // It will trim everyting after the integer value

n = n / 10; // Dividing by 10 to shift the dot back to original place




Sorry about the "moving the dot" comments. I don't know how to explain properly in English when there's numbers after the dot.


Also there's probably a function that automatically trims the the value in a single line.


A way for player to answer the question in one decimal point too.


I have a piece of code that parses a string and returns a integer/float. It's probably not the easiest way to implement. I'm going to wait a little bit to see whether someone else answer. If no one else gives a solution about the second part, I can post my code here. 🙂

I'm really beginner in programming so I understand a bit and got the idea.


If there's no simple way , then I'm willing and gladly will follow your tutorial! 


Would be great if there's plugin lol


#EDIT 


I'm not sure which part I did wrong but the dot doesn't appear


The output should be 1.5 but its 1


Ignore the minus operation. I forgot to change in text message


Untitled.png#EDIT This thread explain why it does not show dots. I don't quite understand though





#EDIT


Alright , I did this


var x = $gameVariables.value(1);
var y = $gameVariables.value(2);
var z = x / y;
$gameVariables.setValue(4, z);
$gameMessage.add("What's is "+x+"/"+y+" "+z.toString());




It works fine and probably the most easy way. Not sure if its a good way though.
If your approach works and doesn't have long loops or excessive memory usage, it's good. 🙂


Did you manage to solve the player's input too? If not, would you mind telling me if you are going to store the input in a string or float?
If your approach works and doesn't have long loops or excessive memory usage, it's good. 🙂


Did you manage to solve the player's input too? If not, would you mind telling me if you are going to store the input in a string or float?

No , I still have no idea on player input. 🙁  



#EDIT


I managed to display the point using toFixed();


No more toString


so


var z = (x /y).toFixed(1); // This should truncate into 1 decimal


Since , the output is what I want , does it also store the numbers as the shown output?


0.6 the answer


Untitled.png
umm... I just figured that the input part will be trickier than I thought.


I think we should do a "divide and conquer" approach, but I need to know more about your math puzzle.


There's two possibilities.

  1. Create a new scene where the puzzle will happen. (like a battle)
  2. Stay on map scene and open a new window.

Which one do you prefer?


The first one is more fancy. But it's much harder to make too, since you will have to deal with sprites.


Here's an example of a math puzzle on new scene  https://atelierrgss.wordpress.com/rmv-yuru-yuri/
umm... I just figured that the input part will be trickier than I thought.


I think we should do a "divide and conquer" approach, but I need to know more about your math puzzle.


There's two possibilities.

  1. Create a new scene where the puzzle will happen. (like a battle)
  2. Stay on map scene and open a new window.

Which one do you prefer?


The first one is more fancy. But it's much harder to make too, since you will have to deal with sprites.


Here's an example of a math puzzle on new scene  https://atelierrgss.wordpress.com/rmv-yuru-yuri/

1. Seems too fancy. 


2. I'm not quite understand you mean.


My  game is quite simple , though.


I use Battle Event option to run the mathematics question. I will explain as simple as I can


The Battle Event page , I set the conditions as HP Actor <=100% , so it will trigger the event I inserted there.


The normal battle system will not appear like this. My game won't and never will use this


 Untitled.png


Battle event


Untitled.png


How to start a battle? I add a monster on map so when the Player touch the event ,it will trigger the Battle processing as shown picture below


Untitled.png


The idea is really simple and easy 🙂!


But if you can make the input way like calculator on (1) , would be great too 🙂


I can send you the demo if you want



Thank you for helping out 🙂
Oh... so you want to change the battle system?


Umm... in this case I think I won't be able to provide much help. I never tinkered the battle scene; I've always made battle system from scratch or used third-party plugins.


You can still ask questions about database access or sprite manipulation though.


Maybe, if nobody else answers, you should make a new thread asking more specific questions about how to edit the battle scene to make it support the input, since the output is already working.
Oh... so you want to change the battle system?


Umm... in this case I think I won't be able to provide much help. I never tinkered the battle scene; I've always made battle system from scratch or used third-party plugins.


You can still ask questions about database access or sprite manipulation though.


Maybe, if nobody else answers, you should make a new thread asking more specific questions about how to edit the battle scene to make it support the input, since the output is already working.



Alright


Thank you for helping out 🙂


Very appreciate 


Just wondering , if you were to create a new one like you said. How would it look?


#EDIT
Successfully stored the value into variable


Now , if theres only a way to answer it lol


#EDIT


Found a plugin but its for VX Ace only 🙁


https://galvs-scripts.com/2012/10/04/keypad-input/
Just wondering , if you were to create a new one like you said. How would it look?



Umm... I think I'd create a new scene, with 2 or 3 layers of image for background, create sprites for numbers, dot, "enter" and backspace for input, access the RMMV database to "create" the enemy.


For mechanics, the player would have to answer the operation to deal damage. If the timer runs out or he miss the answer, the player takes damage.


---------------------


It may be pretty hard for people who just started making scripts for RMMV, but it's completely possible to implement a mechanic like this and with enough knowledge it can be made in less than a week.


I really want to emphasize that you don't have to be a skilled programmer to do it. You just need to know the right stuff.


I don't know if you already know this guy. He made many video tutorials. If you watch the first 25 videos you will have a good idea of how you can make it.


https://www.youtube.com/playlist?list=PLAhuV2yrS6nrkVwtEIjIC1isySa8l2F4h

Original thread: https://forums.rpgmakerweb.com/threads/mathematics-game.73548/