Help making a shop on events but with randomized stock

Hello, i have spent the last two days racking my brain to make this work in any way.

I wanted to make a custom shop, and i was really inspired by the shop in the game tomodachi life. So i ended up making this layout to test out the mechanics it would have, and so far i managed to build almost the entire thing with just pictures, events and scripts.

Spoiler: Tomodachi life
tomodachi life.png
^ This is what the shop in tomodachi life looks like.

Spoiler: bad tomodachi life rip-off
1714437555370.png
^ and this is my poor recreation.

The problem is this: In case you are unfamiliar with tomodachi life, one of the elements of its shop is that the stock rotates and changes every day, and i thought, since my game has a calendar system, it wouldn't be too bad to implement something like that too.

What i came up with as solution was this: There is a variable for each item tab, so i randomized each of this variables, and display the name of the item with the text-to-picture plugin. (I know the label is in the wrong place now but earlier it was not there. I messed it up later, and since i stopped using it i did not bother to fix.)

Spoiler: Code for random stock
1714438157738.png
^ this is the common event i used to roll which number to each

Spoiler: code to display names
1714438255141.png
^ and this is the code to display the name of the items

When it came to me making the purchase screen, i realized i would also need to make an event for each option of each item tab variable, which would make usage of 25 if-s in total. Which is already not great, but considering i planned to add more items and only had 5 for the sake of testing out, makes it a complete disaster.

Some ideas i've tried:

- making a variable tag for all items and have each number for them (ex.: IdItem = 1 would mean flour, IdItem = 2 would mean eggs etc.)
- using shop plugins by PKD and DM
- using common events to list out all the items tag, and then have each item tab move that tag to their position

None of which have properly worked, all break something in some way.

I come here then as last resort, i have run out of solutions, and ideas to make this work. I know new developers can have tendency of biting more than they can chew, so to anyone wiser than me: is this just something unreasonable considering my limitations? I do not know how to code at all, i have been brute-forcing my way with events and searching here for others with similar problem, but i couldnt find anyone with this mixture of mine.

Even if it is impossible, any sort of suggestion or idea in anyway is appreciated, its not that the stock being actually randomized is a MUST, its more so that i cant figure out a way to make the visual representation of stock translate into an item in your slot in an efficient way.

I apologize ahead if there is a simpler way to do this that i didn't think of, or if this sounds convoluted, sometimes it just evades me.
Well, since you wrote that it doesn't even have to be randomized:

You can reference an item with $dataItems[Id], its name with $dataItems[Id].name and its price with $dataItems[Id].price (Id is the item id in your database).

So using 'control variables (script field)' you can set:
variable 1 -> $dataItems[1]
variable 2 -> $dataItems[1].name

Then you can use your Text Picture plugin to show variable 2 with \V[2] (your item's name)

And then when you make the purchase,
Lose gold (first check that you have enough): $gameParty.loseGold($gameVariables.value(1).price);
Gain item: $gameParty.gainItem($gameVariables.value(1), 1);

If you want to make it randomized, I guess you'll have to write your items into an array and pick random values from there, but you'll have to ask someone else how to do that. Also, have you tried checking if there's plugins that would make this easier?
Your suggestions have been great! Since you suggested me looking into arrays i thought they'd be convenient with what i want, so i spent the entire day digging through tutorials and other explanations and thanks to those sources i managed to make an array that worked almost perfectly

i say almost because it has been presenting a very specific quirk

Spoiler: Array code
1714528277296.png

^ this is what i managed to frankenstein, and for the most part it did what i wanted, until it got to display the 5th number

Spoiler: array quirk
nw_hFKtQRfuKZ.png

it always and i mean ALWAYS displays 0 when it comes to showing the 5th item, which i thought was maybe a sign that the limit to arrays was like of 5 items or something, until i added another one to the array just for the sake of testing and then:

Spoiler: Magic
nw_AQTsUY6FJ1.png

it displays everything perfectly? so now i am just floored and confused

so this has been the latest mystery that ive encountered, i ask, if anyone with a better grasp of arrays could help me out here too? i did look for plugins, but i couldnt think of any of them that would help me out, if you have suggestions tho, im willing to try.
I don't really know programming, so don't know what you did wrong. But I tested this myself, and it seems to work (I made an array with 10 item names and am placing 5 random to game variables 10-14):

let items = [$dataItems[7].name,$dataItems[8].name,$dataItems[9].name,$dataItems[10].name,$dataItems[11].name,$dataItems[12].name,$dataItems[13].name,$dataItems[14].name,$dataItems[15].name,$dataItems[16].name];

for (let i = 10; i < 15; i++) {
let random = Math.randomInt(items.length);
let item = items[random];
$gameVariables.setValue(i, item);
items.splice(random, 1);
}
I don't know why you are using $gameSystem.statArray to set the array, but in any case, in your code, you have an extra coma, statArray is actually saving 6 elements basically.

change this
Code:
$gameSyste.statArray = [
$dataItems[1].name,$dataItems[2].name,$dataItems[3].name,
$dataItems[4].name,
$dataItems[5].name,
];

to this
Code:
$gameSyste.statArray = [$dataItems[1].name,
$dataItems[2].name,
$dataItems[3].name,
$dataItems[4].name,
$dataItems[5].name
];

That could be the problem, just test it out and see if that fixes the issue, just remember to remove that extra item you added latter.
so this has been the latest mystery that ive encountered, i ask, if anyone with a better grasp of arrays could help me out here too?
I'm not sure if you're aware, so just in case: array indexes start at 0. This means that [1] accesses the second element, and [5] accesses the sixth (which presumably doesn't exist, so getting it as variable value returns 0).
let items = [$dataItems[7].name,$dataItems[8].name,$dataItems[9].name,$dataItems[10].name,$dataItems[11].name,$dataItems[12].name,$dataItems[13].name,$dataItems[14].name,$dataItems[15].name,$dataItems[16].name];

for (let i = 10; i < 15; i++) {
let random = Math.randomInt(items.length);
let item = items[random];
$gameVariables.setValue(i, item);
items.splice(random, 1);
}
this seemed to work, but it only brings me one result, do you know how i can store all the randomized items order? and also, could you explain this line?
for (let i = 10; i < 15; i++) {
i know you gave a brief summary of what it does, but i wished to know exactly how it works in case i want to add more than 10 items, so i know what to alter to make it work. i tested it with some higher numbers but that didn't seem to do the trick, so i want to know if theres more to it than what ive understood.
That could be the problem, just test it out and see if that fixes the issue, just remember to remove that extra item you added latter.
i removed the comma but it was still not working unfortunately.
I'm not sure if you're aware, so just in case: array indexes start at 0. This means that [1] accesses the second element, and [5] accesses the sixth (which presumably doesn't exist, so getting it as variable value returns 0).
yeah, i actually made this mistake earlier yesterday! lol when i realized i was like oooh so thats why its not working (and then it still kept not working).
Not sure what you mean with "it only brings me one result"...that should put the names of 5 random items (from 10) to game variables 10-14. And if you run it again, the items are different?

That 'for' thing is a javascript loop. I want to reference with 'i' the game variables 10-14 (for 5 items), so I start with 10, loop as long as it's less than 15, increment with +1 every loop (i++).
i meant like, which value do i need to call to access the result? When i tried last time, every single line displayed the same word, so to me it seemed like it was only storing only one item. Which array should i call to get it all listed like "egg, sugar, milk, butter, flour" in the way it was randomized?

That 'for' thing is a javascript loop. I want to reference with 'i' the game variables 10-14 (for 5 items), so I start with 10, loop as long as it's less than 15, increment with +1 every loop (i++).

ooooh i see, thank you for explaining.
That code stored the names to game variables 10-14.

So you would show game variable 10, 11, 12 etc.

You were using the text picture plugin, that accepts text codes, so you can show a variable in text with \V[x] (where x is the variable number).
oooooh i see, yes it works now perfectly, thank you so much for your help! <3

Original thread: https://forums.rpgmakerweb.com/threads/help-making-a-shop-on-events-but-with-randomized-stock.168193/