RPG Maker Forums

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
};

Latest Threads

Latest Posts

Latest Profile Posts

Day 9 of giveaways! 8 prizes today :D
He mad, but he cute :kaopride:

Our latest feature is an interview with... me?!

People4_2 (Capelet off and on) added!

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.

Forum statistics

Threads
106,040
Messages
1,018,470
Members
137,821
Latest member
Capterson
Top