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

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
44,638
Reaction score
15,724
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

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
44,638
Reaction score
15,724
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,635
Reaction score
1,458
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 !
 

Latest Threads

Latest Posts

Latest Profile Posts

Hi everyone! Enjoying this nice long weekend. How are you all doing? :)
I just successfully tested having events check if specific actors are in a particular party slot and then changing image to match. This will let me make scenes take into account who is in the party at the time and arrange them accordingly - this is important since I'll have extra actors beyond current party. The script used is the same from MV and is compatible with my current core plugin setup in MZ. Thank goodness.
That awkward moment when you're talking about thinking about writing a limited shop stock plugin for MZ and then find out you already wrote one...last May. My memory is so bad.
When I open my project and I'm like, hell yeah.
Some drawings I made in Lapis, one day I intend to involve them in some RPG Maker project.
* maybe two wall frames
*or some sprite flower tiara, or maybe it inspires someone to do something.
bdd19b62e539d17b3b00cc3d63034f7d.jpg

fcca5c8471b34483da8e032cfe579275.jpg

Forum statistics

Threads
118,424
Messages
1,115,849
Members
155,376
Latest member
L4TNG
Top