HayaEdu

Villager
Member
Joined
Jul 15, 2018
Messages
6
Reaction score
1
First Language
Filipino
Primarily Uses
RMMV
I have problems with my simple math game. The answer for the operation is wrong; I think it did not go into one of the conditioning on my script. I think showing pictures is a better explanation.
I'm a beginner with things like this, but I think I have no big problem with the variables.
1.png
The problem is with this, having an issue with the conditioning.
2.png
Proof of the problem, the answer is just for testing.
3.png
 

Kuro DCupu

Trust me, I'm a veteran RMer
Veteran
Joined
Jul 6, 2014
Messages
480
Reaction score
1,474
First Language
Indonesia
Primarily Uses
RMMV
That's some pretty bizarre code...
If I want to cut it short :

event.PNG

Works pretty well this way. You don't even need to initiate the random value beforehand. I still can't figure why yours doesn't work. It looks fine tho.

Edit : Here's a copy :

Code:
var tary = [' + ', ' - ', ' * ', ' / '];
tary = tary[Math.randomInt(tary.length)];
var a = 1 + Math.randomInt(50);
var b = 1 + Math.randomInt(50);
$gameVariables.setValue(1, a.toString() + tary + b.toString());
$gameVariables.setValue(2, eval($gameVariables.value(1)));
 
Last edited:

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
2,411
Reaction score
1,821
First Language
EN
Primarily Uses
RMMZ
@HayaEdu Kuro's solution looks sound; just as an explanation, I believe your plus variable is getting assigned incorrectly:
Code:
plus=$gameVariables.setValue(13,ope);
The setValue "function" is actually a method (JavaScript doesn't formally distinguish the two) without an explicit return value, meaning the plus variable remains undefined.

For future reference, you may find console.log() useful. To see how it works, make a simple map event with the following script call:
Code:
var test = $gameVariables.setValue(1, 2);
console.log('Value of test is now', test);
Press F8 during test-play to open the console window, then activate the event to see the message! Very useful when debugging. ^_^
 

HayaEdu

Villager
Member
Joined
Jul 15, 2018
Messages
6
Reaction score
1
First Language
Filipino
Primarily Uses
RMMV
Wow, thanks for helping guys! I learned something new today, will reply again if I finally solved it.

I finally did it, and I'm going to post another problem I have.
 
Last edited:

Latest Threads

Latest Profile Posts

Still early in development but feel like I'm hitting a wall. Either I can't find plugins to do what I need, or they're paywalled :/
Screenshot-2021-05-02-at-15-07-54.png


Tivadar will help you travel to distant places in Eniko: Ghosts Of Grace

Finally done with the school project, here's the raw video of it. o_O :smile:

Forum statistics

Threads
111,176
Messages
1,058,988
Members
144,422
Latest member
martinlukscg
Top