If Variable value = x then assign text

Hello
Just downloaded RPG Maker MZ and had a question that I'm struggling to resolve myself.
I am completely new to the software and coding - so please be gentle.
I'm trying to create a pie eating contest in a carnival, I'm using RPG maker as a graphical aid for a D&D session.
I have a few variables but effectively wish that when someone rolls a pie is selected based on their dice roll (0-9).
Once selected the name of the pie and caveats around what it does will be displayed as thought the host is telling the crowd.
I appreciate I can do this within the main menus via controlling variables but thought it would be faster to do this scripted as there are 10 pies, 5 characters at least 50 entries just to say what the pie name is and what it does, never mind if they are "in" or "out! of the competition, a damage counter, etc.
Anyway this is what i have and its throwing a Syntax Error of undefined identifier
All help greatly appreciated
if($gameVariables.value(6)==0){
$gameVariables.setValue(23, 'text');
}
Thank you for your response and doing so as swiftly as you did. That has resolved the syntax error thank you.
However when ran it now only says Pie one.
I assume i needed some else ifs in there - however once I've done I'm again getting a syntax error of Unexpected token '{' Can you please advise where i;m wrong.
I assumed i'd need an elseif until the final statement than just an else.
Below is what I have now:


if($gameVariables.value(6)==0){
$gameVariables.setValue(23, 'Pie 1');
}
elseif($gameVariables.value(6)==1){
$gameVariables.setValue(23, 'Pie 2');
}
elseif($gameVariables.value(6)==2){
$gameVariables.setValue(23, 'Pie 3');
}
else
$gameVariables.setValue(23, 'Pie 4');

**updated with image of code also
I think this should work?

var pies = ['Pie 1', 'Pie 2', 'Pie 3'];
if($gameVariables.value(6) > pies.length-1){
$gameVariables.setValue(23, 'Pie 4');}
else{
$gameVariables.setValue(23, pies[$gameVariables.value(6)]);
}
I need to apologise profusely. Your first suggested did resolve it. However I was calling the wrong variable and so the it was always 0 (as i wasn't changing it!). Changed the variable to the correct value and this is now resolved.
Thank you so much!

Final code attached for future readers if needed.
1692992853651.png
Just to put it out there, you really don't need to use code for any of this. You can do this entirely with the built-in event commands for Conditional Branch and Control Variables.

That would, of course, save you any possible problems with syntax errors in the code.

Good luck with your project!
Thank you. Appreciate you trying to save me the time.
I will need to repeat this multiple times for each round and each player. As such I thought it quicker to code once and then to do a find and replace on the code to replace variables and then I can just copy and paste rather than having to many manual entries.

That's the logic at least.

And thank you for the good wishes 🙂
As a corollary to what @ATT_Turan said, you could do this a lot more simply:

JavaScript:
const roll = $gameVariables.value(2);
$gameVariables.setValue(23, `Pie ${roll <= 2 ? roll + 1 : '4'}`);

Original thread: https://forums.rpgmakerweb.com/threads/if-variable-value-x-then-assign-text.160629/