Dizzledorfs

Villager
Member
Joined
Jan 28, 2017
Messages
14
Reaction score
19
First Language
English
Primarily Uses
OK. Noob here, sorry. I am an experienced Actionscript coder, but have never tried javascript before, and this is also my first stab at RPGMaker MV. I am attempting to create a math game. I currently have a group of arrays that have the questions and 5 choices for answers. Then, in the array, the correct answer is listed last and in the past, I have checked the chosen answer against the correct answer and then proceeded from there. This is what I have so far... I realize that my format and style is probably all wrong as I just started this yesterday and I don't know what I am doing! :)


The issue at this point is that at the end of the code, it is supposed to give a congratulatory remark to the child, but nothing shows up. I cannot figure out why. Any constructive help is appreciated. If you need more information, just let me know.

Code:
var currentProblem = 0; //will be randomizing which item gets pulled from math array
var previousProblem; //use this to be sure it won't duplicate twice in a row
var aBlank = new Array();
var aFinalArray = new Array();
var finalArrayLength;
var aFill0 = new Array();
var aFill1 = new Array();
aZeroAdd.On = false; //property of each array that gets changed by a button in the game
aOneAdd.On = false;

factChoiceDone = function()
{ //will go through all of the 'On' features to see which arrays the child has turned on
    if(aZeroAdd.On == true)
        {
            aFill0 = aBlank.concat(aZeroAdd); //if it is on, add it to aFill0
        }
    if(aOneAdd.On == true)
        {
            aFill1 = aBlank.concat(aOneAdd);
        }
    aFinalArray = aBlank.concat(aFill0, aFill1); //combines all arrays into aFinalArray
    //console.log(aFinalArray.length);
    finalArrayLength = aFinalArray.length;
    shuffle3(aFinalArray); //shuffles the final array
}

function shuffle3(array_arr)
        {
            for(var i = 0; i < array_arr.length; i++)
            {
                var randomNum_num = Math.floor(Math.random() * array_arr.length);
                var arrayIndex = array_arr[i];
                
                array_arr[i] = array_arr[randomNum_num];
                array_arr[randomNum_num] = arrayIndex;
            }
           for(var j = 0; j < array_arr.length; j++)
           {
                console.log(j + " = " + array_arr[j]);
           }
            return array_arr; //returns aFinalArray shuffled
        }

//this function is called whenever the character runs into an object that triggers the math problem
function showMathProblem()
{
    $gameMessage.add(aFinalArray[0][0]);//adds the problem to the message
    $gameMessage.setChoices([aFinalArray[0][1],aFinalArray[0][2], aFinalArray[0][3], aFinalArray[0][4], aFinalArray[0][5]], aFinalArray[0][6], -1); //sets the choices 
    $gameMessage.setChoiceCallback(function(choice) //when choice is selected, calls this function
            {
                console.log(choice); //logs the number of the choice
                var currentChoice = choice + 1; //adds one to that number for easier lookup
                console.log(aFinalArray[0][currentChoice]); //shows their answer
                if(aFinalArray[0][currentChoice] == aFinalArray[0][6]) //compares their answer to the correct answer
                    {
                        console.log("that is the right answer"); //logs correctly
                        factAnswerCorrect();
                    }
                else
                    {
                        console.log("that is not the right answer"); //logs correctly
                        factAnswerWrong();
                    }
             });
    
};

function factAnswerCorrect()
{
    console.log("Fact Answer Correct Called"); //logs correctly
    $gameMessage.add("That was right!"); //NOTHING SHOWS UP
};

function factAnswerWrong()
{
    $gameMessage.add("That was wrong!");//NOTHING SHOWS UP
};
 

Clock Out

Veteran
Veteran
Joined
Jun 14, 2016
Messages
92
Reaction score
45
First Language
English
Primarily Uses
RMMV
aZeroAdd.On = false; //property of each array that gets changed by a button in the game
aOneAdd.On = false;


These are undefined so it's not possible to add properties to them. A working demo of your project would also help. Perhaps bad questions are being fed into the program.
 
Last edited by a moderator:

Dizzledorfs

Villager
Member
Joined
Jan 28, 2017
Messages
14
Reaction score
19
First Language
English
Primarily Uses
Oh, sorry... they are instatiated in a different javascript file because the arrays are rather lengthy. But, they are found just fine. Everything works up until I just want to tell the gameMessage that it was right or wrong. I haven't posted here before so I am not sure how to post the demo, but I will work on that. Thanks for at least looking at the code. I am sure it is just something silly.
 

Latest Threads

Latest Profile Posts

Zaj
Okay anothe stupid question from me. Why is when everyone's explaining the scripts in the scriptlets, it chnge into green. how do i know when do i code without knowing whether its turning green or not
So I realized that I really just don't have enough time to make videos. However I don't mind clicking stream and just letting people watch me work on my game. I don't really have a good microphone... okay it's a $20 headset so it's terrible, and I have no web cam. So the stream would largely be royalty free music and me working, with minor interaction. I guess the question is, would that actually interest anybody?
Child base test two, flappin' their arms like it's VX Ace.
ChildTest-02.gif
Zaj
Hi quick question. Is it possible for me to make a custom VXAce script without learning some bulkiness of Ruby?

Forum statistics

Threads
111,325
Messages
1,060,200
Members
144,638
Latest member
Larshpe
Top