I've hit a wall, Script Call with Array?

Fuchsilein

Devil Fox
Veteran
Joined
Aug 20, 2015
Messages
53
Reaction score
19
First Language
German
Primarily Uses
Hi there!

I'm trying to build a Deck logic for my game idea
the following code work on my test fine but doesnt work as an script call in MV, can anyone say me why or what i have to change?

var drawArray = [0, 1];
for (i = 0; i < $gameVariables.value(1); ) {
var x = Math.floor((Math.random() * ($gameVariables.value(6) - $gameVariables.value(5) + 1) + $gameVariables.value(5)));
if (drawArray.includes(x)) {
}
else {
drawArray.push(x);
$gameVariables.setValue(8, x);
show_actor_command($gameVariables.value(3), "use_skill", $gameVariables.value(8));
i++
}
}
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,108
Reaction score
13,713
First Language
English
Primarily Uses
RMMV
What error are you getting? What's happening, or not happening?

Shouldn't there be an i++ on the second line?

When posting code, it's better to use code tags than quote tags - all of your indenting is lost, making it harder to read, and it will also often cause certain character strings to be converted to emoticons.
 

Fuchsilein

Devil Fox
Veteran
Joined
Aug 20, 2015
Messages
53
Reaction score
19
First Language
German
Primarily Uses
Hi thanks for the info,

After some trial and error it turns out that MV doesnt support the .includes() - Array function.

So instead of
Code:
if (drawArray.includes(x)) {}
I just had to do
Code:
if (drawArray.indexOf(x) >= 0) {}
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,108
Reaction score
13,713
First Language
English
Primarily Uses
RMMV
How could it work on your test then? Or were you testing in a different engine (that would be good info to include in the first post).
 

Fuchsilein

Devil Fox
Veteran
Joined
Aug 20, 2015
Messages
53
Reaction score
19
First Language
German
Primarily Uses
Tested on a compiler, kinda forgot to include that info :(
 

Jonforum

Veteran
Veteran
Joined
Mar 28, 2016
Messages
1,623
Reaction score
1,440
First Language
French
Primarily Uses
RMMV
Hi thanks for the info,

After some trial and error it turns out that MV doesnt support the .includes() - Array function.

So instead of
Code:
if (drawArray.includes(x)) {}
I just had to do
Code:
if (drawArray.indexOf(x) >= 0) {}
yep it normal depending the version you use.
You have several choices.
1: make a core plugin of you project, and add all polyfill from es6 (you can find it on google)
2: update to rmmv 1.6, with the new node nwjs that use new chromium with es6.

in your example polyfill of include are
PHP:
// https://tc39.github.io/ecma262/#sec-array.prototype.includes
if (!Array.prototype.includes) {
  Object.defineProperty(Array.prototype, 'includes', {
    value: function(searchElement, fromIndex) {

      // 1. Let O be ? ToObject(this value).
      if (this == null) {
        throw new TypeError('"this" is null or not defined');
      }

      var o = Object(this);

      // 2. Let len be ? ToLength(? Get(O, "length")).
      var len = o.length >>> 0;

      // 3. If len is 0, return false.
      if (len === 0) {
        return false;
      }

      // 4. Let n be ? ToInteger(fromIndex).
      //    (If fromIndex is undefined, this step produces the value 0.)
      var n = fromIndex | 0;

      // 5. If n ≥ 0, then
      //  a. Let k be n.
      // 6. Else n < 0,
      //  a. Let k be len + n.
      //  b. If k < 0, let k be 0.
      var k = Math.max(n >= 0 ? n : len - Math.abs(n), 0);

      // 7. Repeat, while k < len
      while (k < len) {
        // a. Let elementK be the result of ? Get(O, ! ToString(k)).
        // b. If SameValueZero(searchElement, elementK) is true, return true.
        // NOTE: === provides the correct "SameValueZero" comparison needed here.
        // except for NaN because NaN === NaN returns false
        if (o[k] === searchElement || isNaN(o[k]) && isNaN(searchElement)) {
          return true;
        }
        // c. Increase k by 1.
        k++;
      }

      // 8. Return false
      return false;
    }
  });
}
and you can add it to your core plugin as function include(){//polyfill}

also recomended you to use formate you loop like this for keep good performance and save some ms
for (i = 0, len = $gameVariables.value(1); i <len; i++ ) {

because the other way, length are recalculate at each iteration !
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

Day 9 of giveaways! 8 prizes today :D
He mad, but he cute :kaopride:

Our latest feature is an interview with... me?!

People4_2 (Capelet off and on) added!

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.

Forum statistics

Threads
106,040
Messages
1,018,476
Members
137,824
Latest member
dobratemporal
Top