Trying to make random rewards based on a variable, that also changes the item name based on that variable.

I've tried several scripts and none of them will read any variables. They keep outputting the variable names instead. I've dug through tons of forums and can't find any answers.

What I want:
Control Variables : #0022 RanLoot 2 = Random 200...208 (works)
var itemID = $gameVariables.value(22); (works)
$gameParty.gainItem($dataArmors[itemID], 1); (works)
Text: "You found $dataArmors[\V[22]].name!" (does no work)

-----------------------------

What I've tried:

var itemID = $gameVariables.value(22);
$gameMessage.add("\\C[7]You found \\C[17]\\V[itemID]!");


Text:
\C[7]You found \C[17]$dataArmors[\V[22]].name! (Outputs the entire command)



$dataArmors($gameVariables.value(22)).name; (returns that $dataArmors is not a function)


$gameMessage.add('You found \\V[22]!'); (Outputs variable value)



var itemID = $gameVariables.value(22);
$gameParty.gainItem($dataArmors[itemID], 1);
$gameMessage.add("You found" $dataArmors[itemID]"!"); ( gives: Missing ) syntax error after argument)
Just put the name into the variable.

Control Variables -> 22 -> Script: $dataArmors[$gameVariables.value(22)].name

Show Text: "You found \V[22]!"
Just put the name into the variable.

Control Variables -> 22 -> Script: $dataArmors[$gameVariables.value(22)].name

Show Text: "You found \V[22]!"
Thank you so much! This was exactly what I needed and I couldn't find it on the script sheet.
@CrimsonShadow
FYI: your original problem was mixing script code and text code in the wrong way.

If you start a scriptcode, then the script cannot handle an included text code directly. That is why the solution needed to use the gamevariables instead of the \V

And if you start a text code there are limited ways how a script can be used inside the text code, so it's rarely a good idea to mix unless you know exactly what you're doing.

Original thread: https://forums.rpgmakerweb.com/threads/trying-to-make-random-rewards-based-on-a-variable-that-also-changes-the-item-name-based-on-that-variable.160086/