JessIchigoShadow

Villager
Member
Joined
Sep 20, 2021
Messages
6
Reaction score
2
First Language
Italiano
Primarily Uses
RMMV
I read on the RPG Maker MV file sheet how to call the choice script, but the part about the callback isn't working how they displayed them there. There's something I didn't get? I tried other methods and now the game doesn't wait for the choice to be made and do other commands other than listening for the choise to be made.
 

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
44,110
Reaction score
15,525
First Language
English
Primarily Uses
RMMV
Please give a link to the sheet you're referring to, and show us screenshots so we can see how you implemented it.
 

JessIchigoShadow

Villager
Member
Joined
Sep 20, 2021
Messages
6
Reaction score
2
First Language
Italiano
Primarily Uses
RMMV
Please give a link to the sheet you're referring to, and show us screenshots so we can see how you implemented it.
Sorry I was able to see this only now.

The link I mentioned is this:
The screen of my code is this:
 

Attachments

  • Immagine.jpg
    Immagine.jpg
    287.6 KB · Views: 11

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
2,746
Reaction score
1,613
First Language
English
Primarily Uses
RMMV
Looking at that, my question is...why is it a function? I don't see you doing anything in there that can't be done by the basic event commands, so why isn't it just an event?
 

ethervagabond

Veteran
Veteran
Joined
Aug 20, 2018
Messages
37
Reaction score
10
First Language
English
Primarily Uses
RMMV
Looking at that, my question is...why is it a function? I don't see you doing anything in there that can't be done by the basic event commands, so why isn't it just an event?
maybe he just wants to practice his JavaScript? lol
 

caethyril

^_^
Global Mod
Joined
Feb 21, 2018
Messages
2,967
Reaction score
2,295
First Language
EN
Primarily Uses
RMMZ
@JessIchigoShadow: can you also show a screenshot of where you are calling this function in your game?

I see some potential problems:
  1. Context - this is context-dependent, details:
    Your function should be run in the context of the interpreter that you want to pause.

  2. Timing - risultato is always undefined because the interpreter only waits between commands. You will have to check the response in a different place, e.g. in another event command.

  3. Scope - because you need to check the response elsewhere (Timing), I suggest storing the response in a game variable instead, e.g.
    JavaScript:
    $gameMessage.setChoiceCallback(function(n) {
      // store selected index in game variable ID 1
      $gameVariables.setValue(1, n);
    });
(I'm guessing this is the basis for an item storage system.)
 

JessIchigoShadow

Villager
Member
Joined
Sep 20, 2021
Messages
6
Reaction score
2
First Language
Italiano
Primarily Uses
RMMV
I want to use the scripts for having an understanding on how everything works, so in the future I will be able to use this function in an even more complex script
Looking at that, my question is...why is it a function? I don't see you doing anything in there that can't be done by the basic event commands, so why isn't it just an event?
 

JessIchigoShadow

Villager
Member
Joined
Sep 20, 2021
Messages
6
Reaction score
2
First Language
Italiano
Primarily Uses
RMMV
@JessIchigoShadow: can you also show a screenshot of where you are calling this function in your game?

I see some potential problems:
  1. Context - this is context-dependent, details:
    Your function should be run in the context of the interpreter that you want to pause.

  2. Timing - risultato is always undefined because the interpreter only waits between commands. You will have to check the response in a different place, e.g. in another event command.

  3. Scope - because you need to check the response elsewhere (Timing), I suggest storing the response in a game variable instead, e.g.
    JavaScript:
    $gameMessage.setChoiceCallback(function(n) {
      // store selected index in game variable ID 1
      $gameVariables.setValue(1, n);
    });
(I'm guessing this is the basis for an item storage system.)

that's the place I call the function. Can you explain the waiting part about the interpreter? Sorry I'm pretty new to scripting for RPG Maker and Javascript, so I'm pretty confused.

For the rest, I'll try to modify the program on how you suggested!

And yes, I wanted to create a store system
 

Attachments

  • 1.jpg
    1.jpg
    180.7 KB · Views: 4
  • 2.jpg
    2.jpg
    152.8 KB · Views: 4

caethyril

^_^
Global Mod
Joined
Feb 21, 2018
Messages
2,967
Reaction score
2,295
First Language
EN
Primarily Uses
RMMZ
You could split your Negozio function into 2 new functions, e.g. (untested):
JavaScript:
(function() {

  var oggetti = [
    'Pozione',
    'Acqua magica',
    'Erba curativa',
    'Stimolante',
    'Pozione dell amore',
    'Zanne velenose',
    'Filo di tela'
  ];

  function Negozio1() {
    $gameMessage.add("What do you want to put in?");
    $gameMessage.setChoices(oggetti, 0, -1);
    $gameMessage.setChoiceBackground(0);
    $gameMessage.setChoicePositionType(2);
    $gameMessage.setChoiceCallback(function(n) {
      // store selected choice index in game variable 1
      $gameVariables.setValue(1, n);
    });
    this.setWaitMode("message");
  };

  function Negozio2() {
    var index = $gameVariables.value(1);
    var itemName = oggetti[index];
    if (itemName) {
      $gameMessage.add("You chose " + itemName);
      $gameMessage.add("How many do you want?");
    }
  };

})();
Then use Function#call to call those functions in the interpreter context:

◆Script:Negozio1.call(this); ◆Script:Negozio2.call(this);
More information here:
Hopefully that makes sense! :kaohi:
 

JessIchigoShadow

Villager
Member
Joined
Sep 20, 2021
Messages
6
Reaction score
2
First Language
Italiano
Primarily Uses
RMMV
Yes, thank you! Sorry for the late answer, and thank you again! I just have a last question, why you have to split the entire part in two functions instead of making everything in one?
 

caethyril

^_^
Global Mod
Joined
Feb 21, 2018
Messages
2,967
Reaction score
2,295
First Language
EN
Primarily Uses
RMMZ
The interpreter only waits between commands. When the choice is made, the message closes, and the next command can run. So everything after the setWaitMode should be called in a new command. This lets the interpreter wait for the player to make a choice before checking what that choice was.

Since we need two separate commands, that means we need two separate functions~
 

JessIchigoShadow

Villager
Member
Joined
Sep 20, 2021
Messages
6
Reaction score
2
First Language
Italiano
Primarily Uses
RMMV
The interpreter only waits between commands. When the choice is made, the message closes, and the next command can run. So everything after the setWaitMode should be called in a new command. This lets the interpreter wait for the player to make a choice before checking what that choice was.

Since we need two separate commands, that means we need two separate functions~
Oookay, thank you!
 

Latest Threads

Latest Posts

Latest Profile Posts

There are so many coding terms that are complete gibberish to me. Like what the heck is "Return" or "Array"??
Sometimes I forget how tiny and fun working in 16x16 is (or with 18x18 if ya counting the white outline LOL) and before you ask Yes. Yes this is an appropriate ratio of drinks to all the other stuff. :popcorn:
f37ac128dedc8a53af7deb2b12e8ea81becf6e46.png
Phew, sleep all day, awake all night. I don't know what to draw tonight!

Does that count as poetry? ..Is there a super fast way to test my creations in RPG Maker? Has anyone played the new Pokémon games? I'm itching to buy it but I don't think my husband will want me to after he finds out how much I spent on Christmas!
When can we get this?
RPG Maker MZ Saturn.png
Saturn port when?
I'm new to rpgmaker mv, link me some good stuff to learn.

Forum statistics

Threads
117,072
Messages
1,104,319
Members
153,053
Latest member
dusk_13
Top