menulist = new()
for(var/A in shopmenu)
var/obj/item/B = new A
if(level >= B.level)
menulist += B
if(!length(menulist))
return
Problem description:
I get that there are prolly other ways to do this. Im more worried about what happens to all the new items that the proc created when it creates new items to check if the player is a high enough level to use them. I know the shop keeper will only show items a player can use and thats how I want it but to avoid errors from null objects I have to create a new one of overything already in the shopmenu and then put them in the menulist if the player can use them.
Once the player buys the item he wants, he might shop again for another item, and do this like 50 times. See how it just keeps on creating new obj? Do these get deleted when the proc is over? Could these be sitting there in some kind of obj limbo, making it so every shop menu a player is shown takes up memory that is never freed? I hope I explained this good enough.
If you want to avoid needlessly creating objects you can store the initial batch of creations in a global list (or a list contained by something with its own refernces) and use them over and over without creating or deleting them multiple times.