So I have been playing around with an evented cooking system and for some reason this error pops up. I'm not sure as to why it's not working. Any help would be really appreciated...
MV Help! $gameVariables.value(...).equals is not a function
Javascript/Plugin SupportYour first blue line should be $gameVariables.value(4)==[0,0,0]
I'm not even sure if that will work but you can try it
All the blue lines need to be in that format
I'm not even sure if that will work but you can try it
All the blue lines need to be in that format
JavaScript arrays don't have an
I think something like this would work:
[Edit: actually that's unlikely to be the problem, see Trihan's reply.]
equals method. A simple equality check won't work either, because that operates by reference for non-primitives, and each Array is a new object. You'd need to check each value individually.I think something like this would work:
JavaScript:
var a = [0,0,0]; $gameVariables.value(4).every(function(v, n) { return v === a[n]; });
[Edit: actually that's unlikely to be the problem, see Trihan's reply.]
i was going to suggest something along the lines of
, but the main point was covered. equals isnt an array function
Code:
JSON.stringify($gameVariables.value(4))==JSON.stringify([0,0,0])
You're actually incorrect; rpg_core.js adds Array.prototype.equals.
I think the issue here may be that the variable doesn't contain an array at the time it's trying to run the function.
Array.prototype.equals works on my end. I intentionally left off a bracket and I got a similar error as yours. Double check your syntax. It would at least return false if variable 4 was some kind of array.
There should be enough time for it to see it as an array so my current guess is that you may be missing a parenthesis or square bracket in your assignment of the variable 'array'.
Edit:
Also, when using .sort(), you don't need to re-assign it. You should just be able to do (edit: caethyril is correct though, assigning it should be just fine if you are using var - const will give you an error if you tried to assign something else to it I think):
There should be enough time for it to see it as an array so my current guess is that you may be missing a parenthesis or square bracket in your assignment of the variable 'array'.
Edit:
Also, when using .sort(), you don't need to re-assign it. You should just be able to do (edit: caethyril is correct though, assigning it should be just fine if you are using var - const will give you an error if you tried to assign something else to it I think):
@Trihan - oh, neat! And it's in MZ too.
Yea, in that case the variable probably hasn't been initialised correctly. Which seems strange because I don't see anything obviously wrong with the script call immediately before it, which sets the value.
@bass2yang - just tried that and a syntax error crashes the game at the Script command, rather than at Conditional Branch (
Per spec,
@Noonyons - ideas:
Yea, in that case the variable probably hasn't been initialised correctly. Which seems strange because I don't see anything obviously wrong with the script call immediately before it, which sets the value.
@bass2yang - just tried that and a syntax error crashes the game at the Script command, rather than at Conditional Branch (
command111). Maybe OP is using a plugin that makes such errors silent, though.Per spec,
Array#sort returns the sorted array, so what they have should be OK in that respect.@Noonyons - ideas:
- Copy+paste that entire script call here so people can check it for errors?
- Are you certain this is the event being activated, e.g. switch 3 is on & there are no similar events?
- Turn off all plugins, save your project to apply Plugin Manager changes, then test. If that fixes it, consider sharing a screenshot of your Plugin Manager.
- Press F8 during playtest to show the dev tools window, go to the Console tab, and type this:
[].equals
Press Enter and it should show some function code. If it showsundefinedinstead, then something strange is going on. 😅
-
- Editor version: Help -> About.
- Core script version: Game -> Open Folder, then check the first couple of lines of
js/rpg_core.jsin a text editor, e.g.
//============================================================================= // rpg_core.js v1.6.2
If necessary, instructions for updating your core scripts can be found here:
The announcement is for 1.6.1, but it's the same idea for all versions.Announcement - RPG Maker MV - v1.6.1 Stable Release!
6/21/2018 Everyone, please read the instructions carefully. The bugs that are being reported shouldn't happen if the correct files were even copied properly. Such examples like the "CTRL BUG" shouldn't happen if you copied index.html, package.json, the rpg*.js files and so on. I also received...
forums.rpgmakerweb.com
So i tried turning off all the plugins and it still caused an error. I started a new project and for some reason it worked there. I don't know why, but yah. It's sorta fixed like that
Original thread: https://forums.rpgmakerweb.com/threads/help-gamevariables-value-equals-is-not-a-function.168383/