Hi guys, thanks for the assist, takes alot for me to ask for help (always the strong silent type lol), but I figured, as I spent all night yesterday on the issue, but finally had to go to bed, figured there was no harm in asking and seeing if anybody had any ideas. Gave me something to try out once I had slept and then got back home from work.
Anyway...
@ATT_Turan The code block you quoted does actually work without any errors. It's what I left it at last night (it's near what should be happening, if not exactly what I need to be happening); The only issue is that, unlike my previous code blocks (the ones that do crash the game), it doesn't include the check to avoid the code picking the same item twice when generating the shop's goods array (which is how RPG Maker generates it's shop lists).
I left the pushes to the dupe arrays in there basically to prevent me having to rewrite the code for if we did come up with a solution to include a check on the dupe array contents that doesn't crash the game. That's all; I know without the actual check into a dupe array they essentially do nothing of any value.
As for the
&& statements; Like I said sorry my javascript knowledge is limited; I was using those instead of ending the code statements with
; so that it'd be easier to integrate what I need it to do once we found the correct terminology for "if item is not in array
do these multiple things else do this thing".
My experience with javascript, which honestly is mostly just from building battle damage formula for skills, is that if you use
; and move onto the next code statement within an
if statement, it'll ignore everything except the code before the first
; after the
? check (or sometimes even return an "expected
: instead of
;" sort of error), so I got into the habit of using
&& if I wanted to do multiple things so I could contain it before the
; bracket (for e.g. d > 1 ? thing && other thing : thing ; ), but that could just be a quirk with the way the battle skill formula interprets code or simply the way I write my code in those sections.
If you can get away with just using
; all the time though, it'd be good to know because it'd help me keep my code cleaner ^_^.
@BurningOrca
I've put it on multiple lines, but you could put that back into a single line. However I could not figure out, why your original code did not work at all. I've put it into console and it did work for me!
Yeah, it's so weird because like I said, the code
used to work with no issue back when I originally created the project which was around half a decade ago now. Haven't really done anything to it since but it just seems to have stopped working for no discernible reason.
What's weird as well, is when I try to call the shop again (without regenerating the random item list), it would also cause a crash. But I got around that by copying the 2 variable to a new variable, and then using the new variable whenever the shop is recalled without regenerating the item list; the original shop call when it first generates the list is still done using variable 2 and that works okay though. It just all seems so inconsistent when years ago it was all working flawlessly.
I tried the code you just suggested, but it results in the same error. I also tried it in a fresh project (just incase the other equally kitbashed script I have elsewhere in this project to do with Escape chance when a certain character is in the party was interfering somehow), but both my old code and your new suggested code here cause the same crash (of course I adjusted the numbers to make sure it could only pick items from the database that actually exist in the fresh project).
The error code "undefined is not a function" in the console is similar in both cases
JavaScript:
TypeError: undefined is not a function
at Game_Interpreter.eval (eval at <anonymous> (file:///E:/RPG%20Maker/RPGMaker%20MZ%20Projects/Code%20Test/js/rpg_objects.js:10500:10), <anonymous>:2:117)
at Game_Interpreter.command355 (file:///E:/RPG%20Maker/RPGMaker%20MZ%20Projects/Code%20Test/js/rpg_objects.js:10500:5)
at Game_Interpreter.executeCommand (file:///E:/RPG%20Maker/RPGMaker%20MZ%20Projects/Code%20Test/js/rpg_objects.js:8930:34)
at Game_Interpreter.update (file:///E:/RPG%20Maker/RPGMaker%20MZ%20Projects/Code%20Test/js/rpg_objects.js:8838:19)
at Game_Map.updateInterpreter (file:///E:/RPG%20Maker/RPGMaker%20MZ%20Projects/Code%20Test/js/rpg_objects.js:6115:27)
at Game_Map.update (file:///E:/RPG%20Maker/RPGMaker%20MZ%20Projects/Code%20Test/js/rpg_objects.js:6022:14)
at Scene_Map.updateMain (file:///E:/RPG%20Maker/RPGMaker%20MZ%20Projects/Code%20Test/js/rpg_scenes.js:608:14)
at Scene_Map.updateMainMultiply (file:///E:/RPG%20Maker/RPGMaker%20MZ%20Projects/Code%20Test/js/rpg_scenes.js:600:10)
at Scene_Map.update (file:///E:/RPG%20Maker/RPGMaker%20MZ%20Projects/Code%20Test/js/rpg_scenes.js:589:10)
at Function.SceneManager.updateScene (file:///E:/RPG%20Maker/RPGMaker%20MZ%20Projects/Code%20Test/js/rpg_managers.js:2024:25)
Which makes me think you could be right; That for some reason the includes function is undefined in the current version of RPGMaker MV by default for some reason (even though it was included in earlier versions of the engine); In which case the question I suppose then becomes...how do we go about redefining it for the engine?
Or if that's not an easy fix, what alternative ways to code this system would there be?
Maybe rather than checking if an array has the item already and not using it, instead populate all items into an initial array, once each, then move them from that array into the shop array randomly (removing them from the old array in the process so they couldn't be picked again)?
Maybe something along those lines? Would that be possible to do without needing to use the includes function for arrays?