I have a wardrobe that I want the player to pick items from. The wardrobe is a dictionary, and the choices offered to the player should be nested. I.e.: "Pants > Jeans" or "Top > Tee".
I do get the first level working, but then the messaging system stops reacting. I somewhat understand that this due to how the external JS is interpreted by RPGM. I know I can do nested selection using Event's UI, I wrote a post below explaining why this is not an option.
Here is my code. Could somebody please kindly help with RPGM's API - how can I do a nested selection using JS? I am failing even at showing a message after the selection has been made.
Thank you.
PS I saw a similar post asking for help, yet it was unsolved: link
I do get the first level working, but then the messaging system stops reacting. I somewhat understand that this due to how the external JS is interpreted by RPGM. I know I can do nested selection using Event's UI, I wrote a post below explaining why this is not an option.
Here is my code. Could somebody please kindly help with RPGM's API - how can I do a nested selection using JS? I am failing even at showing a message after the selection has been made.
JavaScript:
//This is a dictionary with the 2-level nested choice
my_wardrobe = {
"Pants" : ["Jeans", "Shorts"],
"Top" : ["Shirt", "Tee"]
};
//This is the callback function factored out
function on_wardropbe_selection(items, selection){
message = `Selected: ${items[selection]}`
console.log(message)
//$gameMessage.newPage();
$gameMessage.add(message);
}
//This function displays selection prompt
(function() {
offer_choice = function(message, my_items) {
const items = my_items
$gameMessage.add(message)
$gameMessage.setChoices(items, 0, -1)
$gameMessage.setChoiceBackground(0);
$gameMessage.setChoicePositionType(2)
$gameMessage.setChoiceCallback(function(selection) {
on_wardropbe_selection(items, selection)
});
}
})();
//This takes dictionary's keys and turns them into 1st level selection prompt
function chose_from_dictionary(message, my_dict){
offer_choice(message, Object.keys(my_dict))
}
//This takes dictionary's values and turns them into arrays
function chose_from_array(my_array){
offer_choice(message, my_array)
}
//Function called from an event via Script: my_wardrobe_menu()
(function() {
my_wardrobe_menu = function() {
chose_from_dictionary("Wardrobe choices?", my_wardrobe)
}
})();
Thank you.
PS I saw a similar post asking for help, yet it was unsolved: link