设为首页收藏本站同能贴吧 切换语言 繁体中文
开启辅助访问 切换到窄版
扫描二维码关注官方公众号
返回列表
+ 发新帖
查看: 56|回复: 0

[转载发布] MVQuizzer - Educational Game Engine

[复制链接]
累计送礼:
0 个
累计收礼:
1 个
  • TA的每日心情
    开心
    2026-7-12 04:10
  • 签到天数: 209 天

    连续签到: 2 天

    [LV.7]常住居民III

    8037

    主题

    864

    回帖

    3万

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

    VIP
    7
    卡币
    30081
    OK点
    16
    推广点
    0
    同能卷
    50
    积分
    39012

    灌水之王

    发表于 5 天前 | 显示全部楼层 |阅读模式
    MVQuizzer v0.4
    by Starbird

    Free for non-commercial use.

    This system helps game developers create educational games or in-game quizzes very quickly.

    Note: This plugin is NOT plug-and-play. Detailed instructions for the simple setup steps are included.


    THE BASICS:
    What does it do? MVQuizzer displays and evaluates multiple choice, true/false, and short answer questions. The system allows you to create and manage a large database of questions with ease. Quickly add or change questions without having to step through maps and events.

    FEATURES:

    getQuestion.js
    Plugin reads questions from a js file in the plugins.
    questionDatabase.js
    JSON-based question database. Questions can either be left human-readable or encoded to hinder cheating. Easily balance rewards/penalties in a simple text editor.

    Create questions using included html forms. Just copy and paste the resulting text string into questionDatabase.js

    Multiple Choice Questions
    * Ask and evaluate multiple choice questions with two to five response choices displayed in randomized order
    * Include image and sound files with questions
    * Optional question timer

    True / False Questions
    * Ask and evaluate true/false questions
    * Include image and sound files with questions
    * Optional question timer

    Short Answer Questions
    * Ask and evaluate short answer questions
    * Include image files with questions
    * Option to check for proper capitalization
    * Optional question timer
    * Keyboard and mouse input

    Reward / Penalty System
    * Assign rewards and penalties for right and wrong answers.

    Streaks/Slumps
    Easily track streaks and slumps using included switches and counters to trigger event listeners.

    DOCUMENTATION:
    Full documentation PDF included in demo file below.

    CODE
                    JavaScript:       
    1. // DON'T TOUCH ANYTHING BELOW HERE UNLESS YOU KNOW WHAT YOU'RE DOING :)
    2. // --- MV QUIZZER ------------------------------
    3. // MVQ Pulls questions from QuestionDatabase.js. Determines question type and calls functions to process by type. Formats text str to fit in message boxes
    4. /*:
    5. * @plugindesc MVQuizzer uses the associated QuestionDatabas.js file in the plugin folder to ask true/false, multiple choice, and short answer style questions. It evaluates the answers and provides in-game results.
    6. * @author Starbird      
    7. *
    8. * @param Test Parameter
    9. * @desc This is a description of a test parameter. This does not currently do anything in the plugin.
    10. * @default 42
    11. */
    12. // Game Variable 1 - Stores text input strings for answering Short Answer questions
    13. // Game Variable 2 - Stores the question number and determines which question to pull next from the database.
    14. // Game Variable 3 - Stores the total number of correct answers
    15. // Game Variable 4 - Stores the total number of wrong answers
    16. // Game Variable 5 - Stores question timer result -- not yet implemented
    17. // Game Switch 2 - Switch that activates upon correct answer response
    18. // Game Switch 3 - Switch that activates upon wrong answer response
    19. // Picture 1 and 2 used
    20. // DETERMINE QUESTION TYPE. also determines string length and sends to line break function for formatting if necessary
    21. getQuestion = function(questionNumber){
    22. switch (questionDatabase.Questions[(questionNumber - 1)].Q_T) {
    23. case 1:
    24. var str = questionDatabase.Questions[(questionNumber - 1)].Q
    25. if (str.length > 160){
    26. str = '\\}'+ str
    27. var formattedQuestion = stringDivider(str, 70, '\n')
    28. AskShortAnswerQuestion(questionNumber, formattedQuestion)
    29. }
    30. else{
    31. var formattedQuestion = stringDivider(str, 37, '\n')
    32. AskShortAnswerQuestion(questionNumber, formattedQuestion)
    33. }
    34. break;
    35. case 2:
    36. var str = questionDatabase.Questions[(questionNumber - 1)].Q
    37. if (str.length > 200){
    38. str = '\\}'+ str
    39. var formattedQuestion = stringDivider(str, 95, '\n')
    40. AskTrueOrFalseQuestion(questionNumber, formattedQuestion)
    41. }
    42. else{
    43. var formattedQuestion = stringDivider(str, 56, '\n')
    44. AskTrueOrFalseQuestion(questionNumber, formattedQuestion)
    45. }
    46. break;
    47. case 3:
    48. AskMultipleChoiceQuestion(questionNumber) // reserved for 3-choice MC questions
    49. break;
    50. case 4:
    51. var str = questionDatabase.Questions[(questionNumber - 1)].Q
    52. if (str.length > 200){
    53. str = '\\}'+ str
    54. var formattedQuestion = stringDivider(str, 95, '\n')
    55. AskMultipleChoiceQuestion(questionNumber, formattedQuestion)
    56. }
    57. else{
    58. var formattedQuestion = stringDivider(str, 56, '\n')
    59. AskMultipleChoiceQuestion(questionNumber, formattedQuestion)
    60. }
    61. break;
    62. case 5:
    63. AskMultipleChoiceQuestion(questionNumber) // reserved for 5-choice MC questions
    64. break;
    65. default:
    66. console.log('check question type for question #' + questionNumber + ' in database')
    67. }
    68. }
    69. //--- ASK QUESTIONS -----------------------------
    70. // BEGIN MULTIPLE CHOICE SECTION
    71. //ASKS MULTIPLE CHOICE QUESTIONS
    72. AskMultipleChoiceQuestion = function(questionNumber, formattedQuestion) {
    73. var questionText = questionDatabase.Questions[(questionNumber - 1)].Q;
    74. var correctAnswer = questionDatabase.Questions[(questionNumber - 1)].C_A;
    75. var answerTwo = questionDatabase.Questions[(questionNumber - 1)].A2;
    76. var answerThree = questionDatabase.Questions[(questionNumber - 1)].A3;
    77. var answerFour = questionDatabase.Questions[(questionNumber - 1)].A4;
    78. //Image processing for Multiple Choice questions
    79. var isImg = questionDatabase.Questions[(questionNumber - 1)].I
    80. if (isImg == 1) {
    81. $gameScreen.showPicture(1, questionDatabase.Questions[(questionNumber - 1)].GUID, 0, 0, 0, 100, 100, 255, 0) || (1, 'imgError', 0, 0, 0, 100, 100, 255, 0)}   //come back to this
    82. else {};
    83. var isAudio = questionDatabase.Questions[(questionNumber - 1)].A
    84. // puts question in message box
    85. $gameMessage.add(formattedQuestion);
    86. //Plays audio file if there is one associated with the MC question
    87. if (isAudio == 1){
    88. $gameScreen.showPicture(2, 'audio', 0, 747, 0, 100, 100, 255, 0);
    89. var audioFile = questionDatabase.Questions[(questionNumber - 1)].GUID
    90. PlayAudio1(audioFile) || ('audio');}
    91. else {};
    92.    
    93. //initialize timer for answering question
    94. var d = new Date();
    95. var timeInitial = d.getTime();
    96. // 4-Question Multiple Choice Question Order Randomizer
    97. var answerOrder = Math.floor(Math.random() * (24)) + 1;
    98. switch (answerOrder) {
    99.   case 1:
    100.     $gameMessage.setChoices([correctAnswer, answerTwo, answerThree, answerFour], 0, -1);
    101.     var answerOffset = [0, 0, 0, 0]
    102.     checkAnswer_MC(timeInitial, questionNumber, answerOffset, isImg, isAudio);
    103.     break;
    104. case 2:
    105.     $gameMessage.setChoices([correctAnswer, answerTwo, answerFour, answerThree], 0, -1);
    106.     var answerOffset = [0, 0, -1, 1];
    107.     checkAnswer_MC(timeInitial, questionNumber, answerOffset, isImg, isAudio);
    108.     break;
    109. case 3:
    110.     $gameMessage.setChoices([correctAnswer, answerThree, answerTwo, answerFour], 0, -1);
    111.     var answerOffset = [0, -1, 1, 0];
    112.     checkAnswer_MC(timeInitial, questionNumber, answerOffset, isImg, isAudio);
    113.     break;
    114. case 4:
    115.     $gameMessage.setChoices([correctAnswer, answerThree, answerFour, answerTwo], 0, -1);
    116.     var answerOffset = [0, -1, -1, 2];
    117.     checkAnswer_MC(timeInitial, questionNumber, answerOffset, isImg, isAudio);
    118.     break;
    119. case 5:
    120.     $gameMessage.setChoices([correctAnswer, answerFour, answerTwo, answerThree], 0, -1);
    121.     var answerOffset = [0, -2, 1, 2];
    122.     checkAnswer_MC(timeInitial, questionNumber, answerOffset, isImg, isAudio);
    123.     break;
    124. case 6:
    125.     $gameMessage.setChoices([correctAnswer, answerFour, answerThree, answerTwo], 0, -1);
    126.     var answerOffset = [0, -2, 0, 2];
    127.     checkAnswer_MC( timeInitial, questionNumber, answerOffset, isImg, isAudio);
    128.     break;
    129. case 7:
    130.     $gameMessage.setChoices([answerTwo, correctAnswer, answerFour, answerThree], 0, -1);
    131.     var answerOffset = [-1, 1, -1, 1];
    132.     checkAnswer_MC(timeInitial, questionNumber, answerOffset, isImg, isAudio);
    133.     break;
    134. case 8:
    135.     $gameMessage.setChoices([answerTwo, correctAnswer, answerThree, answerFour], 0, -1);
    136.     var answerOffset = [-1, 1, 0, 0];
    137.     checkAnswer_MC(timeInitial, questionNumber, answerOffset, isImg, isAudio);
    138.     break;
    139. case 9:
    140.     $gameMessage.setChoices([answerTwo, answerThree, answerFour, correctAnswer], 0, -1);
    141.     var answerOffset = [-1, -1, -1, 3];
    142.     checkAnswer_MC(timeInitial, questionNumber, answerOffset, isImg, isAudio);
    143.     break;   
    144. case 10:
    145.     $gameMessage.setChoices([answerTwo, answerThree, correctAnswer, answerFour], 0, -1);
    146.     var answerOffset = [-1, -1, 2, 0];
    147.     checkAnswer_MC(timeInitial, questionNumber, answerOffset, isImg, isAudio);
    148.     break;   
    149. case 11:
    150.     $gameMessage.setChoices([answerTwo, answerFour, answerThree, correctAnswer], 0, -1);
    151.     var answerOffset = [-1, -2, 0, 3];
    152.     checkAnswer_MC(timeInitial, questionNumber, answerOffset, isImg, isAudio);
    153.     break;
    154. case 12:
    155.     $gameMessage.setChoices([answerTwo, answerFour, correctAnswer, answerThree], 0, -1);
    156.     var answerOffset = [-1, -2, 2, 1];
    157.     checkAnswer_MC(timeInitial, questionNumber, answerOffset, isImg, isAudio);
    158.     break;
    159. case 13:
    160.     $gameMessage.setChoices([answerThree, correctAnswer, answerTwo, answerFour], 0, -1);
    161.     var answerOffset = [-2, 1, 1, 0];
    162.     checkAnswer_MC(timeInitial, questionNumber, answerOffset, isImg, isAudio);
    163. break;
    164. case 14:
    165.     $gameMessage.setChoices([answerThree, correctAnswer, answerFour, answerTwo], 0, -1);
    166.     var answerOffset = [-2, 1, -1, 2];
    167.     checkAnswer_MC(timeInitial, questionNumber, answerOffset, isImg, isAudio);
    168.     break;
    169. case 15:
    170.     $gameMessage.setChoices([answerThree, answerTwo, correctAnswer, answerFour], 0, -1);
    171.     var answerOffset = [-2, 0, 1, 0];
    172.     checkAnswer_MC(timeInitial, questionNumber, answerOffset, isImg, isAudio);
    173.     break;
    174. case 16:
    175.     $gameMessage.setChoices([answerThree, answerTwo, answerFour, correctAnswer], 0, -1);
    176.     var answerOffset = [-2, 0, -1, 3];
    177.     checkAnswer_MC(timeInitial, questionNumber, answerOffset, isImg, isAudio);
    178.     break;
    179. case 17:
    180.     $gameMessage.setChoices([answerThree, answerFour, correctAnswer, answerTwo], 0, -1);
    181.     var answerOffset = [-2, -2, 2, 2];
    182.     checkAnswer_MC(timeInitial, questionNumber, answerOffset, isImg, isAudio);
    183.     break;
    184. case 18:
    185.     $gameMessage.setChoices([answerThree, answerFour, answerTwo, correctAnswer], 0, -1);
    186.     var answerOffset = [-2, -2, 1, 3];
    187.     checkAnswer_MC(timeInitial, questionNumber, answerOffset, isImg, isAudio);
    188.     break;   
    189. case 19:
    190.     $gameMessage.setChoices([answerFour, correctAnswer, answerThree, answerTwo], 0, -1);
    191.     var answerOffset = [-3, 1, 0, 2];
    192.     checkAnswer_MC(timeInitial, questionNumber, answerOffset, isImg, isAudio);
    193.     break;
    194. case 20:
    195.     $gameMessage.setChoices([answerFour, correctAnswer, answerTwo, answerThree], 0, -1);
    196.     var answerOffset = [-3, 1, 1, 1];
    197.     checkAnswer_MC(timeInitial, questionNumber, answerOffset, isImg, isAudio);
    198.     break;
    199. case 21:
    200.     $gameMessage.setChoices([answerFour, answerTwo, answerThree, correctAnswer], 0, -1);
    201.     var answerOffset = [-3, 0, 0, 3];
    202.     checkAnswer_MC(timeInitial, questionNumber, answerOffset, isImg, isAudio);
    203.     break;   
    204. case 22:
    205.     $gameMessage.setChoices([answerFour, answerTwo, correctAnswer, answerThree], 0, -1);
    206.     var answerOffset = [-3, 0, 2, 1];
    207.     checkAnswer_MC(timeInitial, questionNumber, answerOffset, isImg, isAudio);
    208.     break;   
    209. case 23:
    210.     $gameMessage.setChoices([answerFour, answerThree, answerTwo, correctAnswer], 0, -1);
    211.     var answerOffset = [-3, -1, 1, 3];
    212.     checkAnswer_MC(timeInitial, questionNumber, answerOffset, isImg, isAudio);
    213.     break;
    214. case 24:
    215.     $gameMessage.setChoices([answerFour, answerThree, correctAnswer, answerTwo], 0, -1);
    216.     var answerOffset = [-3, -1, 2, 2]
    217.     checkAnswer_MC(timeInitial, questionNumber, answerOffset, isImg, isAudio);
    218.     break;   
    219. default:
    220. console.log('something is wrong')
    221. };
    222. };
    223. //CHECK ANSWER FOR MULTIPLE CHOICE QUESTION
    224. checkAnswer_MC = function (timeInitial, questionNumber, answerOffset, isImg, isAudio){
    225. var guid = questionDatabase.Questions[(questionNumber - 1)].GUID;
    226. var questionText = questionDatabase.Questions[(questionNumber - 1)].Q;
    227. var correctAnswer = questionDatabase.Questions[(questionNumber - 1)].C_A;
    228. var answerTwo = questionDatabase.Questions[(questionNumber - 1)].A2;
    229. var answerThree = questionDatabase.Questions[(questionNumber - 1)].A3;
    230. var answerFour = questionDatabase.Questions[(questionNumber - 1)].A4;
    231. var questionStandard = questionDatabase.Questions[(questionNumber - 1)].S || '';
    232. var answerReward = questionDatabase.Questions[(questionNumber - 1)].R_A;
    233.   $gameMessage.setChoiceCallback(function (choice) {
    234. //timer
    235. var e = new Date();
    236. var timeFinal = e.getTime();
    237. var timeTaken = Math.round( ((timeFinal - timeInitial) / 1000) * 10 ) / 10;
    238.   //erases question pictures if there are any
    239. if (isImg == 1) {
    240. $gameScreen.erasePicture(1);
    241. }
    242. else {};
    243. if (isAudio == 1) {
    244.   $gameScreen.erasePicture(2);
    245. }
    246. else {};
    247.         //check and log answer response result
    248.         var adjustedChoice = (choice - answerOffset[choice])
    249.         switch (adjustedChoice){
    250.         
    251.         case 0:                //  RIGHT ANSWER ',"GUID":"' + guid in case GUID is needed
    252.         var answerResult = '{"GUID":' +guid + ',"Q_N":' +questionNumber + ',"I_C":"Y","T":' + timeTaken + ',"Q_T":4,' + '"Q":"' + questionText + '","C_A":"' + correctAnswer + '","A2":"' + answerTwo + '","A3":"' + answerThree + '","A4":"' + answerFour + '","S":"' + questionStandard + '","R_A":'+ answerReward + '},'
    253.         // record total correct answers
    254. var totalCorrectAnswers = $gameVariables.value(3) + 1
    255. $gameVariables.setValue(3, totalCorrectAnswers);
    256. // calculate total percent correct
    257. var percentCorrect = (totalCorrectAnswers / questionNumber) * 100;
    258. var percentCorrect = Math.floor(percentCorrect);
    259. saveGame(answerResult, percentCorrect);   
    260. $gameSwitches.setValue(2, true);
    261. // send to reward system
    262. rewardSystem();
    263.         
    264.         break;
    265.         
    266.         case 1:                   //WRONG ANSWER
    267.         var answerResult = '{"GUID":' +guid + ',"Q_N":' +questionNumber + ',"I_C":"N","G_A":"'+ answerTwo + '","T":' + timeTaken + ',"Q_T":4,' + '"Q":"' + questionText + '","C_A":"' + correctAnswer + '","A2":"' + answerTwo + '","A3":"' + answerThree + '","A4":"' + answerFour + '","S":"' + questionStandard + '","R_A":'+ answerReward + '},'
    268.         console.log(answerResult);
    269.       
    270.        // record total wrong answers
    271.        var totalWrongAnswers = $gameVariables.value(4) + 1
    272.        $gameVariables.setValue(4, totalWrongAnswers);
    273.        // calculate total percent correct
    274.        var percentCorrect = (totalCorrectAnswers / questionNumber) * 100;
    275.        var percentCorrect = Math.floor(percentCorrect);
    276.       
    277.       
    278.        saveGame(answerResult, percentCorrect);      
    279.        $gameSwitches.setValue(3, true);
    280.       
    281.         // send to penalty system
    282.         penaltySystem();
    283.         
    284.       
    285.         break;
    286.         
    287.         case 2:                //WRONG ANSWER
    288.         var answerResult = '{"GUID":' +guid + ',"Q_N":' +questionNumber + ',"I_C":"N","G_A":"'+ answerThree + '","T":' + timeTaken + ',"Q_T":4,' + '"Q":"' + questionText + '","C_A":"' + correctAnswer + '","A2":"' + answerTwo + '","A3":"' + answerThree + '","A4":"' + answerFour + '","S":"' + questionStandard + '","R_A":'+ answerReward + '},'
    289.         console.log(answerResult);
    290.         
    291.         // record total wrong answers
    292.        var totalWrongAnswers = $gameVariables.value(4) + 1
    293.        $gameVariables.setValue(4, totalWrongAnswers);
    294.        // calculate total percent correct
    295.        var percentCorrect = (totalCorrectAnswers / questionNumber) * 100;
    296.        var percentCorrect = Math.floor(percentCorrect);
    297.       
    298.       
    299.        saveGame(answerResult, percentCorrect);      
    300.        $gameSwitches.setValue(3, true);
    301.       
    302.         // send to penalty system
    303.         penaltySystem();
    304.         
    305.         
    306.         break;
    307.         
    308.         case 3:                //WRONG ANSWER
    309.         var answerResult = '{"GUID":' +guid + ',"Q_N":' +questionNumber + ',"I_C":"N","G_A":"'+ answerFour + '","T":' + timeTaken + ',"Q_T":4,' + '"Q":"' + questionText + '","C_A":"' + correctAnswer + '","Two":"' + answerTwo + '","Three":"' + answerThree + '","Four":"' + answerFour + '","S":"' + questionStandard + '","R_A":'+ answerReward + '},'
    310.         console.log(answerResult);
    311.         
    312.         // record total wrong answers
    313.        var totalWrongAnswers = $gameVariables.value(4) + 1
    314.        $gameVariables.setValue(4, totalWrongAnswers);
    315.        // calculate total percent correct
    316.        var percentCorrect = (totalCorrectAnswers / questionNumber) * 100;
    317.        var percentCorrect = Math.floor(percentCorrect);
    318.       
    319.       
    320.        saveGame(answerResult, percentCorrect);      
    321.        $gameSwitches.setValue(3, true);
    322.       
    323.         // send to penalty system
    324.         penaltySystem();
    325.         
    326.       
    327.         break;
    328.         default:
    329.         console.log('Something is wrong. The adjustedChoice value is: ' + adjustedChoice);
    330.         };
    331.     // save results from question response
    332.    
    333.    
    334.     // $gameVariables.setValue(questionNumber, answerResult);
    335.    
    336. });
    337. }
    338. // ---------------END MULTIPLE CHOICE SECTION
    339. // BEGIN TRUE FALSE SECTION
    340.    
    341. // ASKS TRUE OR FALSE QUESTION
    342. AskTrueOrFalseQuestion = function(questionNumber, formattedQuestion){
    343. var questionText = questionDatabase.Questions[(questionNumber - 1)].Q;
    344. var correctAnswer = questionDatabase.Questions[(questionNumber - 1)].C_A;
    345. var isImg = questionDatabase.Questions[(questionNumber - 1)].I;
    346. var isAudio = questionDatabase.Questions[(questionNumber -1)].A;
    347. //checks for any image associated with questions
    348. if (isImg == 1) {
    349. $gameScreen.showPicture(1, questionDatabase.Questions[(questionNumber - 1)].GUID, 0, 0, 0, 100, 100, 255, 0)}
    350. else {};
    351. //Plays audio file if there is one associated with the MC question
    352. if (isAudio == 1){
    353. $gameScreen.showPicture(2, 'audio', 0, 747, 0, 100, 100, 255, 0);
    354. PlayAudio1(questionDatabase.Questions[(questionNumber - 1)].GUID) || ('audio');}   
    355. else {};
    356. $gameMessage.add(formattedQuestion);
    357. //initialize timer
    358. var d = new Date();
    359. var timeInitial = d.getTime();
    360. $gameMessage.setChoices(['True', 'False'], 0, -1);
    361. checkAnswer_TF(questionNumber, timeInitial);
    362. };
    363. // CHECK ANSWER FOR TRUE OR FALSE QUESTION
    364. checkAnswer_TF = function (questionNumber, timeInitial){
    365. $gameMessage.setChoiceCallback(function (choice)
    366. {
    367. var guid = questionDatabase.Questions[(questionNumber - 1)].GUID;
    368. var questionType = questionDatabase.Questions[(questionNumber - 1)].Q_T;
    369. var questionText = questionDatabase.Questions[(questionNumber - 1)].Q;
    370. var isImg = questionDatabase.Questions[(questionNumber - 1)].I;
    371. var isAudio = questionDatabase.Questions[(questionNumber - 1)].A;
    372. var correctAnswer = questionDatabase.Questions[(questionNumber - 1)].C_A;
    373. var questionStandard = questionDatabase.Questions[(questionNumber - 1)].S || '';
    374. var answerReward = questionDatabase.Questions[(questionNumber - 1)].R_A;     
    375. //timer
    376. var e = new Date();
    377. var timeFinal = e.getTime();
    378. var timeTaken = Math.round( ((timeFinal - timeInitial) / 1000) * 10 ) / 10;
    379. //erases question pictures if there are any
    380. if (isImg == 1) {
    381. $gameScreen.erasePicture(1);
    382. }
    383. else {};
    384. if (isAudio == 1) {
    385.   $gameScreen.erasePicture(2);
    386. }
    387. else {};
    388.     if (choice == correctAnswer){                // CORRECT ANSWER
    389.      if (correctAnswer == 0){
    390.          correctAnswer = 'TRUE'
    391.      }
    392.      else {correctAnswer = 'FALSE'}
    393.         
    394.      var answerResult = '{"GUID":' +guid + ',"Q_N":' +questionNumber + ',"I_C":"Y","T":' + timeTaken + ',"Q_T":2,' + '"Q":"' + questionText + '","C_A":"' + correctAnswer + '","S":"' + questionStandard + '","R_A":'+ answerReward + '},'
    395.      console.log(answerResult);
    396.    
    397. // record total correct answers
    398. var totalCorrectAnswers = $gameVariables.value(3) + 1
    399. $gameVariables.setValue(3, totalCorrectAnswers);
    400. // calculate total percent correct
    401. var percentCorrect = (totalCorrectAnswers / questionNumber) * 100;
    402. var percentCorrect = Math.floor(percentCorrect);
    403. saveGame(answerResult, percentCorrect);   
    404. $gameSwitches.setValue(2, true);
    405. // send to reward system
    406. rewardSystem();
    407.     }
    408.         else {                                 //WRONG ANSWER
    409.             if (correctAnswer == 0) {            
    410.         var answerResult = '{"GUID":' +guid + ',"Q_N":' +questionNumber + ',"I_C":"N","G_A":"FALSE","T":' + timeTaken + ',"Q_T":2,' + '"Q":"' + questionText + '","C_A": "TRUE", "S":"' + questionStandard + '","R_A":'+ answerReward + '},'
    411.         console.log(answerResult);
    412.         
    413.         // record total wrong answers
    414.        var totalWrongAnswers = $gameVariables.value(4) + 1
    415.        $gameVariables.setValue(4, totalWrongAnswers);
    416.        // calculate total percent correct
    417.        var percentCorrect = (totalCorrectAnswers / questionNumber) * 100;
    418.        var percentCorrect = Math.floor(percentCorrect);
    419.       
    420.        saveGame(answerResult, percentCorrect);      
    421.        $gameSwitches.setValue(3, true);     
    422.       
    423.        // send to penalty system
    424.         penaltySystem();
    425.         
    426.         }
    427.         else {
    428.         var answerResult = '{"GUID":' +guid + ',"Q_N":' +questionNumber + ',"I_C":"N","G_A":"TRUE","T":' + timeTaken + ',"Q_T":2,' + '"Q":"' + questionText + '","C_A":"FALSE","S":"' + questionStandard + '","R_A":'+ answerReward + '},'   
    429.         console.log(answerResult);
    430.    
    431.     // record total wrong answers
    432.        var totalWrongAnswers = $gameVariables.value(4) + 1
    433.        $gameVariables.setValue(4, totalWrongAnswers);
    434.        // calculate total percent correct
    435.        var percentCorrect = (totalCorrectAnswers / questionNumber) * 100;
    436.        var percentCorrect = Math.floor(percentCorrect);
    437.       
    438.       
    439.        saveGame(answerResult, percentCorrect);      
    440.        $gameSwitches.setValue(3, true);
    441.         // send to penalty system
    442.         penaltySystem();
    443.         
    444.         };
    445.         };
    446.       // save results from question response
    447.      // $gameVariables.setValue(questionNumber, answerResult);
    448.    
    449.         });
    450. }
    451. // ------------------END TRUE FALSE SECTION
    452. // BEGIN SHORT ANSWER QUESTION SECTION
    453. //Calls  CmdInp.js authored by Darkkitten - used for Short Answer question
    454. var $gameInterp = new Game_Interpreter();
    455. function EnterText() {
    456.   $gameInterp.pluginCommand('enter_text');
    457. }
    458. // ASKS SHORT ANSWER QUESTION
    459. var $gameInterp = new Game_Interpreter();
    460. AskShortAnswerQuestion = function(questionNumber, formattedQuestion){
    461. var correctAnswer = questionDatabase.Questions[(questionNumber - 1)].C_A;
    462. var questionStandard = questionDatabase.Questions[(questionNumber - 1)].S;
    463. var answerReward = questionDatabase.Questions[(questionNumber - 1)].R_A;
    464. var imageFile = questionDatabase.Questions[(questionNumber - 1)].GUID
    465. var isImg = questionDatabase.Questions[(questionNumber - 1)].I;
    466. if (isImg == 0) {
    467. var args = '1'+ ' ' + correctAnswer.length + ' ' + 'noImg' + ' ' + formattedQuestion   //answer variable, max length, image, question text
    468. $gameInterp.pluginCommand('enter_text', args.split(' '));
    469. console.log(formattedQuestion);
    470. }
    471. else {
    472. var args = '1' + ' ' + correctAnswer.length + ' ' + imageFile + ' ' + formattedQuestion || '1' + ' ' + correctAnswer.length + ' ' + 'imgError' + ' ' + questionText
    473. $gameInterp.pluginCommand('enter_text', args.split(' '));   
    474. console.log(formattedQuestion);
    475. }
    476. }
    477. // CHECK ANSWER FOR SHORT ANSWER QUESTION
    478. checkAnswer_SA = function (questionNumber, answerText, timeInitial_SA) {
    479. var guid = questionDatabase.Questions[(questionNumber - 1)].GUID;
    480. var questionType = questionDatabase.Questions[(questionNumber - 1)].Q_T;
    481. var questionText = questionDatabase.Questions[(questionNumber - 1)].Q;
    482. var isImg = questionDatabase.Questions[(questionNumber - 1)].I;
    483. var isAudio = questionDatabase.Questions[(questionNumber - 1)].A;
    484. var correctAnswer = questionDatabase.Questions[(questionNumber - 1)].C_A;
    485. var caseSensitive = questionDatabase.Questions[(questionNumber - 1)].C_S;
    486. var questionStandard = questionDatabase.Questions[(questionNumber - 1)].S || '';
    487. var answerReward = questionDatabase.Questions[(questionNumber - 1)].R_A;
    488. // check for case sensitivity
    489. if (caseSensitive == 0){
    490.     var correctAnswer = correctAnswer.toLowerCase();
    491.     var answerText = answerText.toLowerCase();
    492. }
    493. else {};
    494. //timer
    495. var e = new Date();
    496. var timeFinal = e.getTime();
    497. var timeTaken = Math.round( ((timeFinal - timeInitial_SA) / 1000) * 10 ) / 10;
    498. //CHECK GIVEN ANSWER AGAINST CORRECT ANSWER
    499.     // WHEN CORRECT ANSWER
    500. if (answerText == correctAnswer){   
    501. // record answer result
    502. var answerResult = '{"GUID":' +guid + ',"Q_N":' +questionNumber + ',"I_C":"Y","T":' + timeTaken + ',"Q_T":1,' + '"Q":"' + questionText + '","C_A":"' + (correctAnswer) + '","S":"' + questionStandard + '","R_A":'+ answerReward + '},'
    503. console.log(answerResult);
    504. // record total correct answers
    505. var totalCorrectAnswers = $gameVariables.value(3) + 1
    506. $gameVariables.setValue(3, totalCorrectAnswers);
    507. // calculate total percent correct
    508. var percentCorrect = (totalCorrectAnswers / questionNumber) * 100;
    509. var percentCorrect = Math.floor(percentCorrect);
    510. saveGame(answerResult, percentCorrect);   
    511. $gameSwitches.setValue(2, true);
    512. // send to reward system
    513. rewardSystem();
    514. }
    515.   // WHEN WRONG ANSWER
    516. else {
    517. // record answer result
    518. var answerResult = '{"GUID":' +guid + ',"Q_N":' +questionNumber + ',"I_C":"N","G_A":"'+ (answerText) + '","T":' + timeTaken + ',"Q_T":1,' + '"Q":"' + questionText + '","C_A":"' + (correctAnswer) + '","S":"' + questionStandard + '","R_A":'+ answerReward + '},'
    519. console.log(answerResult);
    520. // record total wrong answers
    521. var totalWrongAnswers = $gameVariables.value(4) + 1
    522. $gameVariables.setValue(4, totalWrongAnswers);
    523. // calculate total percent correct
    524. var percentCorrect = (totalCorrectAnswers / questionNumber) * 100;
    525. var percentCorrect = Math.floor(percentCorrect);
    526. saveGame(answerResult, percentCorrect);      
    527. $gameSwitches.setValue(3, true);
    528. // send to penalty system
    529. penaltySystem();
    530. }
    531. };
    532. // -----------END SHORT ANSWER SECTION
    533. // UTILITY FUNCTIONS
    534. // REWARD SYSTEM
    535. rewardSystem = function(){
    536.     playSoundEffect('MVQ_Wrong_Answer');
    537.     var rewardType = questionDatabase.Questions[(questionNumber - 1)].R_T;
    538.     var rewardId = questionDatabase.Questions[(questionNumber - 1)].R_I;
    539.     var rewardAmount = questionDatabase.Questions[(questionNumber - 1)].R_A;
    540.     var onlyLeader = questionDatabase.Questions[(questionNumber - 1)].O_L;
    541.    
    542.     if (rewardType == 'Enemy'){
    543.         
    544.     BattleManager.setup(rewardId, true, true);    // initiates battle but player can escape and can lose
    545.     $gamePlayer.makeEncounterCount();
    546.     SceneManager.push(Scene_Battle);
    547.         
    548.     };
    549.    
    550.     if (rewardType == 'Gold'){
    551.     $gameParty.gainGold(rewardAmount);
    552.     }
    553.      if (rewardType == 'Armor'){
    554.          $gameParty.gainItem($dataArmors[rewardId], rewardAmount, true)
    555.      };
    556.    
    557.     if (rewardType == 'Item'){
    558.             $gameParty.gainItem($dataItems[rewardId], rewardAmount);
    559.     };
    560.    
    561.     if (rewardType == 'Weapon'){
    562.             $gameParty.gainItem($dataWeapons[rewardId], rewardAmount, true);
    563.     };
    564.    
    565.    
    566.     if (rewardType == 'HP'){
    567.         
    568.         if (onlyLeader == 1) {$gameParty.leader().gainHp(rewardAmount)}
    569.         
    570.         else{
    571.             $gameParty.members().forEach(function(member){member.gainHp(rewardAmount)})
    572.         }
    573.         
    574.         };
    575.    
    576.     if (rewardType == 'XP'){
    577.         
    578.         if (onlyLeader == 1) {$gameParty.leader().gainExp(rewardAmount)}
    579.         
    580.         else{
    581.         $gameParty.members().forEach(function(member){member.gainExp(rewardAmount)})
    582.         }
    583.         
    584.         
    585.     };
    586.    
    587.     if (rewardType == 'MP'){
    588.         if (onlyLeader == 1) {$gameParty.leader().gainHp(rewardAmount)}
    589.         
    590.         else{
    591.         $gameParty.members().forEach(function(member){member.gainMp(rewardAmount)})
    592.         }
    593.     };
    594.    
    595.     if (rewardType == 'TP'){
    596.         
    597.         if (onlyLeader == 1) {$gameParty.leader().gainTp(rewardAmount)}
    598.         
    599.         else{      
    600.         $gameParty.members().forEach(function(member){member.gainTp(rewardAmount)})
    601.         }
    602.     };
    603.    
    604.         
    605.      if (rewardType == 'Skill'){
    606.         if (onlyLeader == 1) {$gameParty.leader().gainHp(rewardAmount)}
    607.         
    608.         else{   
    609.         $gameParty.members().forEach(function(member){member.learnSkill(rewardId)})
    610.         }
    611.    
    612.    
    613.      };
    614.    
    615.     if (rewardType == 'MHP'){
    616.         if (onlyLeader == 1) {$gameParty.leader().addParam(0, rewardAmount)}
    617.         
    618.         else{
    619.         $gameParty.members().forEach(function(member){member.addParam(0, rewardAmount)})
    620.         }
    621.         
    622.          };
    623.    
    624.     if (rewardType == 'MMP') {
    625.         if (onlyLeader == 1) {$gameParty.leader().addParam(1, rewardAmount)}
    626.         
    627.         else{
    628.         $gameParty.members().forEach(function(member){member.addParam(1, rewardAmount)})
    629.         }
    630.     };
    631.    
    632.       if (rewardType == 'ATK') {
    633.         if (onlyLeader == 1) {$gameParty.leader().addParam(2, rewardAmount)}
    634.         
    635.         else{
    636.         $gameParty.members().forEach(function(member){member.addParam(2, rewardAmount)})
    637.         }
    638.      };
    639.    
    640.       if (rewardType == 'DEF') {
    641.         if (onlyLeader == 1) {$gameParty.leader().addParam(3, rewardAmount)}
    642.         
    643.         else{
    644.          $gameParty.members().forEach(function(member){member.addParam(3, rewardAmount)})
    645.         }
    646.      };
    647.    
    648.      if (rewardType == 'AddState') {
    649.         if (onlyLeader == 1) {$gameParty.leader().addState(rewardId)}
    650.         
    651.         else{
    652.         $gameParty.members().forEach(function(member){member.addState(rewardId)})
    653.         }
    654.          };
    655.    
    656.    
    657.      if (rewardType == 'RemoveState') {
    658.         if (onlyLeader == 1) {$gameParty.leader().removeState(rewardId)}
    659.         
    660.         else{
    661.         $gameParty.members().forEach(function(member){member.removeState(rewardId)})
    662.         }
    663.         
    664.          };
    665.    
    666.     // need to implement notetag reading to get good/bad/neutral quality of each state
    667.     // if (rewardType == 'RemoveAllBadStates'){};   
    668.    
    669.    
    670.     // no reward
    671.     if (rewardType == 'None'){};
    672.    
    673.    
    674.    
    675.     };
    676.    
    677. // PENALTY SYSTEM
    678. penaltySystem = function(){
    679.     playSoundEffect('MVQ_Correct_Answer');
    680.     var penaltyType = questionDatabase.Questions[(questionNumber - 1)].P_T;
    681.     var penaltyID = questionDatabase.Questions[(questionNumber - 1)].P_I;
    682.     var penaltyAmount = parseInt(questionDatabase.Questions[(questionNumber - 1)].P_A *-1);
    683.     // var penaltyAmount = parseInt(penaltyAmount *-1);
    684.     console.log(penaltyAmount)
    685.     var onlyLeader = questionDatabase.Questions[(questionNumber - 1)].O_L;
    686.    
    687.     if (penaltyType == 'Enemy'){
    688.         
    689.     BattleManager.setup(rewardId, false, false);    // initiates battle where player cannot escape and must win or die
    690.     $gamePlayer.makeEncounterCount();
    691.     SceneManager.push(Scene_Battle);
    692.         
    693.     };
    694.    
    695.     if (penaltyType == 'Gold'){
    696.     $gameParty.gainGold(penaltyAmount);
    697.     }
    698.      if (penaltyType == 'Armor'){
    699.          $gameParty.gainItem($dataArmors[penaltyId], penaltyAmount, true)
    700.      };
    701.    
    702.     if (penaltyType == 'Item'){
    703.             $gameParty.gainItem($dataItems[penaltyId], penaltyAmount);
    704.     };
    705.    
    706.     if (penaltyType == 'Weapon'){
    707.             $gameParty.gainItem($dataWeapons[rewardId], penaltyAmount, true);
    708.     };
    709.    
    710.    
    711.     if (penaltyType == 'HP'){
    712.         
    713.         if (onlyLeader == 1) {$gameParty.leader().gainHp(penaltyAmount)}
    714.         
    715.         else{
    716.             $gameParty.members().forEach(function(member){member.gainHp(penaltyAmount)})
    717.         }
    718.         
    719.         };
    720.    
    721.     if (penaltyType == 'XP'){
    722.         
    723.         if (onlyLeader == 1) {$gameParty.leader().gainExp(penaltyAmount)}
    724.         
    725.         else{
    726.         $gameParty.members().forEach(function(member){member.gainExp(penaltyAmount)})
    727.         }
    728.         
    729.         
    730.     };
    731.    
    732.     if (penaltyType == 'MP'){
    733.         if (onlyLeader == 1) {$gameParty.leader().gainHp(penaltyAmount)}
    734.         
    735.         else{
    736.         $gameParty.members().forEach(function(member){member.gainMp(penaltyAmount)})
    737.         }
    738.     };
    739.    
    740.     if (penaltyType == 'TP'){
    741.         
    742.         if (onlyLeader == 1) {$gameParty.leader().gainTp(penaltyAmount)}
    743.         
    744.         else{      
    745.         $gameParty.members().forEach(function(member){member.gainTp(penaltyAmount)})
    746.         }
    747.     };
    748.    
    749.         
    750.      if (penaltyType == 'Skill'){
    751.         if (onlyLeader == 1) {$gameParty.leader().gainHp(penaltyAmount)}
    752.         
    753.         else{   
    754.         $gameParty.members().forEach(function(member){member.forgetSkill(penaltyId)})
    755.         }
    756.    
    757.    
    758.      };
    759.    
    760.     if (penaltyType == 'MHP'){
    761.         if (onlyLeader == 1) {$gameParty.leader().addParam(0, penaltyAmount)}
    762.         
    763.         else{
    764.         $gameParty.members().forEach(function(member){member.addParam(0, penaltyAmount)})
    765.         }
    766.         
    767.          };
    768.    
    769.     if (penaltyType == 'MMP') {
    770.         if (onlyLeader == 1) {$gameParty.leader().addParam(1, penaltyAmount)}
    771.         
    772.         else{
    773.         $gameParty.members().forEach(function(member){member.addParam(1, penaltyAmount)})
    774.         }
    775.     };
    776.    
    777.       if (penaltyType == 'ATK') {
    778.         if (onlyLeader == 1) {$gameParty.leader().addParam(2, penaltyAmount)}
    779.         
    780.         else{
    781.         $gameParty.members().forEach(function(member){member.addParam(2, penaltyAmount)})
    782.         }
    783.      };
    784.    
    785.       if (penaltyType == 'DEF') {
    786.         if (onlyLeader == 1) {$gameParty.leader().addParam(3, -penaltyType)}
    787.         
    788.         else{
    789.          $gameParty.members().forEach(function(member){member.addParam(3, penaltyAmount)})
    790.         }
    791.      };
    792.    
    793.      if (penaltyType == 'AddState') {
    794.         if (onlyLeader == 1) {$gameParty.leader().addState(penaltyId)}
    795.         
    796.         else{
    797.         $gameParty.members().forEach(function(member){member.addState(penaltyId)})
    798.         }
    799.          };
    800.    
    801.    
    802.      if (penaltyType == 'RemoveState') {
    803.         if (onlyLeader == 1) {$gameParty.leader().removeState(penaltyId)}
    804.         
    805.         else{
    806.         $gameParty.members().forEach(function(member){member.removeState(penaltyId)})
    807.         }
    808.         
    809.          };
    810.    
    811.     // need to implement notetag reading to get good/bad/neutral quality of each state
    812.     // if (penaltyType == 'RemoveAllBadStates'){};   
    813.    
    814.    
    815.     // no penalty
    816.     if (penaltyType == 'None'){};
    817.    
    818.    
    819.    
    820. }
    821. playSoundEffect = function(audioFile){
    822.    
    823.      var se = {
    824.             name: audioFile,
    825.             volume: 100,
    826.             pitch: 100,
    827.             pan: 0
    828.         }
    829.      AudioManager.playSe(se);
    830.      };
    831. //Audio Function for MC and TF questions
    832. PlayAudio1 = function(audioFile){
    833.    
    834.      var se = {
    835.             name: questionDatabase.Questions[(questionNumber - 1)].GUID,
    836.             volume: 100,
    837.             pitch: 100,
    838.             pan: 0
    839.         }
    840.      AudioManager.playSe(se);
    841.      };
    842. //--- Plugin Command call --------------------------------------------------      
    843. var aliasPluginCommand = Game_Interpreter.prototype.pluginCommand;
    844. Game_Interpreter.prototype.pluginCommand = function(command, args){
    845. aliasPluginCommand.call(this, command, args);
    846. // var parameters = PluginManager.parameters('GetQuestion');
    847. // var variableBandwidth = parameters
    848. console.log('GetQuestion plugin called')
    849. //Fetches question by number
    850. if(command == 'GetQuestion'){
    851. // this loops the database back to the first question in the database if it gets to the end of the database
    852. var questionNumber = $gameVariables.value(2) + 1;
    853. var databaseLength = questionDatabase.Questions.length;
    854. if (questionNumber > databaseLength) {
    855.     var questionNumber = 1};
    856. window.questionNumber = questionNumber;
    857. console.log(questionDatabase);
    858. console.log(questionNumber);
    859. $gameVariables.setValue(2, (questionNumber));
    860. getQuestion(questionNumber);
    861. }     
    862. }
    863. //WORD WRAP FOR QUESTION FORMATTING
    864. function stringDivider(str, width, spaceReplacer) {
    865.     if (str.length>width) {
    866.         var p=width
    867.         for (;p>0 && str[p]!=' ';p--) {
    868.         }
    869.         if (p>0) {
    870.             var left = str.substring(0, p);
    871.             var right = str.substring(p+1);
    872.             return left + spaceReplacer + stringDivider(right, width, spaceReplacer);
    873.         }
    874.     }
    875.     return str;
    876. }
    877. //ROT13 - Not currently used
    878. function rot13(str)
    879. {
    880.     return (str ? str : this).split('').map(function(_)
    881.      {
    882.         if (!_.match(/[A-Za-z]/)) return _;
    883.         c = Math.floor(_.charCodeAt(0) / 97);
    884.         k = (_.toLowerCase().charCodeAt(0) - 83) % 26 || 26;
    885.         return String.fromCharCode(k + ((c == 0) ? 64 : 96));
    886.      }).join('');
    887. }
    888. // dummy saveGame function
    889. function saveGame (){}
    890. //native save game
    891. /*
    892. function saveGame(answerResult, percentCorrect) {
    893.         $gameSystem.onBeforeSave();
    894.         var totalQuestions = $gameVariables.value(2)
    895.         // Generate savegame data
    896.         var json = JsonEx.stringify(DataManager.makeSaveContents());
    897.         if (json.length >= 500001) {
    898.             console.log('Save data too big');
    899.         };   
    900.         // Initialize HTTP Request
    901.         var xhttp = new XMLHttpRequest();
    902.         var data = "action=recordAnswer&guid="+encodeURIComponent(_guid)+"&userName="+encodeURIComponent(_userName)+"&password="+encodeURIComponent(_password)+"&gameName="+encodeURIComponent(_gameName)+"&gameVersion="+encodeURIComponent(_gameVersion)+"&gameData="+encodeURIComponent(json)+"&answerResult="+encodeURIComponent(answerResult)+"&percentRight="+encodeURIComponent(percentCorrect)+"&totalQuestions="+encodeURIComponent(totalQuestions);
    903.         
    904.         // Send savegame data
    905.         xhttp.open('POST', _url+"/cloudmanager.php", false);
    906.         xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    907.         xhttp.send(data);
    908.         
    909.         var result = xhttp.responseText;
    910.         console.log(result);
    911.         console.log('made it through save');
    912.                     
    913.     };
    914.     */
    复制代码


    End notes:

    Known issues:
    -Scene pop problem after defeating enemy on wrong answer (fix soon)
    -occasional timer lag

    There are a handful of features that I had intended to add to this plugin system, but with the upcoming release of MZ, I'm currently planning to revisit this plugin once I've purchased the new RPG Maker. Any further releases will probably be for that platform instead of MV.


    本贴来自国际rpgmaker官方论坛作者:Starbird_Resources处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:https://forums.rpgmakerweb.com/threads/mvquizzer-educational-game-engine.124179/

    本帖子中包含更多资源

    您需要 登录 才可以下载或查看,没有账号?立即注册

    x
    天天去同能,天天有童年!
    回复 送礼论坛版权

    使用道具 举报

    文明发言,和谐互动
    文明发言,和谐互动
    高级模式
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    简体中文
    繁體中文
    English(英语)
    日本語(日语)
    Deutsch(德语)
    Русский язык(俄语)
    بالعربية(阿拉伯语)
    Türkçe(土耳其语)
    Português(葡萄牙语)
    ภาษาไทย(泰国语)
    한어(朝鲜语/韩语)
    Français(法语)
    关闭

    幸运抽奖

    社区每日抽奖来袭,快来试试你是欧皇还是非酋~

    立即查看

    聊天机器人
    Loading...

    QQ|Archiver|手机版|小黑屋|同能RPG制作大师 ( 沪ICP备12027754号-3 )

    GMT+8, 2026-8-1 10:42 , Processed in 0.157556 second(s), 55 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.

    快速回复 返回顶部 返回列表