I want to present the player with a choice and do something based on the choice they select.
I am able to get the choice to popup and receive the given choice, but I am unable to keep track of useful variables that were encapsulated in the function that assigns the callback.
Farming.prototype.PlantSeedSelection = function (obj) {
//Collect all player items that are crops and create a choice array from them
var partyItems = $gameParty.allItems();
var possibleSeeds = [];
for (var i = 0; i < partyItems.length; i++) {
//TODO: Filter by notetags
possibleSeeds.push(partyItems);
}
if (possibleSeeds.length < 1)
{
$gameMessage.add("Go get some seeds!");
return;
}
//Display choices
$gameMessage.add("Choose a seed.");
choices = []; params = [];
for (var i = 0; i < possibleSeeds.length; i++) {
choices.push(possibleSeeds.name);
}
$gameMessage.setChoices(choices, 0);
$gameMessage.setChoiceCallback(function (choice) {
console.log(choice);
$farming.PlantSeed(obj, possibleSeeds[choice]); //ERROR. These parameters are not accessible
});
params.push();
}
I have tried to store the obj and choices in the $farming object (Which is a solution I wasn't fond of) but even that doesn't work.
Do I need to clone the objects in order to prevent them from being wiped?
Ideally I would be able to pass all my parameters into the callback because that would be the cleanest in my mind.
Please let me know if you have any ideas!
I am able to get the choice to popup and receive the given choice, but I am unable to keep track of useful variables that were encapsulated in the function that assigns the callback.
Farming.prototype.PlantSeedSelection = function (obj) {
//Collect all player items that are crops and create a choice array from them
var partyItems = $gameParty.allItems();
var possibleSeeds = [];
for (var i = 0; i < partyItems.length; i++) {
//TODO: Filter by notetags
possibleSeeds.push(partyItems);
}
if (possibleSeeds.length < 1)
{
$gameMessage.add("Go get some seeds!");
return;
}
//Display choices
$gameMessage.add("Choose a seed.");
choices = []; params = [];
for (var i = 0; i < possibleSeeds.length; i++) {
choices.push(possibleSeeds.name);
}
$gameMessage.setChoices(choices, 0);
$gameMessage.setChoiceCallback(function (choice) {
console.log(choice);
$farming.PlantSeed(obj, possibleSeeds[choice]); //ERROR. These parameters are not accessible
});
params.push();
}
I have tried to store the obj and choices in the $farming object (Which is a solution I wasn't fond of) but even that doesn't work.
Do I need to clone the objects in order to prevent them from being wiped?
Ideally I would be able to pass all my parameters into the callback because that would be the cleanest in my mind.
Please let me know if you have any ideas!