Identify item by consuming it.

Hey guys, another head scratcher!

I want to have different potions that you can find in the dungeons, which gives a random effect (some beneficial, some not-so-good). The only way you can figure out what each potion does is by consuming it.

The potions are randomized on each playthrough.

So I have a Red Potion. When you acquire the Red Potion, you don't know what it does. Does it heal you? Does it poison you? Gulp it down and find out!

So basically I have 5 potions and 5 other potions that are identified with their effects set up.

Okay. At the beginning of the game, a common event fires up and assigns each potions to a colored potion. So the Red Potion can be anything, a healing potion, an antidote, a poison, etc.

When the user consumed the red potion, I want it to be identified forever, so if the Red Potion was a healing potion, then every time the user finds a red potion, they get a healing potion instead.

I'm having some difficulties breaking it down on what I have to do. This old brain of mine doesn't work like it used to, so I need some fresh ideas to help me out.

Thank you!
You'll need a couple of things here...

Your coloured potion items should all have a different common event in the Effects list. Each common event will turn on a unique switch (red potion - red switch) to indicate that it's been swallowed and you now know what it does. It will then count how many of the coloured potion you have in inventory, reduce your coloured potions by that many, and increase your action potions by that many (you'll need to determine if the count includes the one that you've just used or not, and adjust accordingly).

Then another common event for each coloured potion to be called when you acquire it (I assume here that you can only acquire it via events, and not battle drops). In this common event, check to see if the appropriate switch is on - if it is, the item has been identified and you can add the actual potion. If it isn't, the item hasn't been identified yet and you just get the coloured potion.

You could probably have a third common event that will be called by all of these to add the actual potion, based on your randomization at the start of the game.
Thank you, @Shaz

Yes, I was thinking of something like that. I have problems randomizing the potions and keeping it that way for the duration of the game, though. The game is meant to be played multiple times in sessions. It's kind of a rogue-like. So each time you get in the dungeon, potions change.

So I have 5 potions. I have 5 switches. I have 5 variables.

I wrote this small plugin to randomize the initial values:
Code:
function PotionSetup() {
    this.initialize.apply(this, arguments);
}

(function() {
//this function gets a random value and you can set a deleteFlag in order to decide whether to remove that from the given array
var GetRandomElement = function(myArray, deleteFlag) {
   var randomItem = myArray[Math.floor(Math.random()*myArray.length)];
   if (deleteFlag == true) {
      RemoveElement(myArray, randomItem);
   }
   return randomItem;
}


var PotionMixer = function() {
   var Number= new Array();
    for (var i=1; i<5; ++i) {
      Number.push(i);
   }
   $gameVariables.setValue(20, value); = GetRandomElement(Number, true);
   $gameVariables.setValue(21, value); = GetRandomElement(Number, true);
   $gameVariables.setValue(22, value); = GetRandomElement(Number, true);
   $gameVariables.setValue(23, value); = GetRandomElement(Number, true);
   $gameVariables.setValue(24, value); = GetRandomElement(Number, false);
}
 }) ();

Right? Okay. Now, this doesn't work. The variables stays at 0.

I was thinking of checking each potion over the variables and set it up on that number, like

RedPotion = $gameVariables.Value(20);
BluePotion = $gameVariables.Value(21);

[...]

Then having a common event like you suggested, checking if a switch is on, then replace the item with the known version.
I feel like I could have figured this out like 15 years ago, lol. Ah, aging is a cursed blessing.
I haven't looked through your code carefully, but I can tell you that you're setting the variables up incorrectly.

IF the logic in GetRandomElement is correct, you should put the assignments like this:

$gameVariables.setValue(20, GetRandomElement(Number, true));

I'm not sure using Number as your array name is a good idea. Is Number a reserved word (data type) in javascript?

Original thread: https://forums.rpgmakerweb.com/threads/identify-item-by-consuming-it.102570/