1
NPC : 
var posArrayx = [-1638, -1496, -1386, -1366, -1286, -1252, -1178, -1040, -908, -884, -678, -578, -584, -438, -318, -200, 300, 560, 618, 784, 778, 894, 1142, 1048, 1234, 1348];
var eim, status = -1;

function start() {
    eim = cm.getPlayer().getEventInstance();
    if (eim != null) {
        action(1, 0, 0);
    } else {
        cm.warp(261000021);
        cm.dispose();
    }
}

function action(m, t, s) {
    if (m < 0) {
        cm.dispose();
        return;
    }
    if (m == 1)
        status++;
    else
        status--;
    if (status < 0) {
        cm.dispose();
        return;
    }
    var randClick = parseInt(eim.getProperty("randClick"));
    var mesosArray = eim.getProperty("mesosArray").split(",");
    var expArray = eim.getProperty("expArray").split(",");
    var clickedSpots = eim.getProperty("clickedSpots").split(",");
    for (var i = 0; i < posArrayx.length; i++) {
        if (npc.getPosition().getX() == posArrayx[i]) {
            if (i == randClick) {
                cm.sendOk("Lol its the right one, but it isnt coded yet");
                cm.dispose();
            } else if (clickedSpots[i] > 0) {
                cm.sendOk("Its looks someone already checked this place, i'd better look somewhere else.");
            } else if (expArray.indexOf(posArrayx[i]) >= 0) {
                cm.sendOk("You gained some mesos");
                var meso = Math.floor(Math.random() * 3000) + 1000;
                cm.gainMeso(meso);
            } else if (mesosArray.indexOf(posArrayx[i]) >= 0) {
                cm.sendOk("You gained some mesos");
                var exp = Math.floor(Math.random() * 3000) + 1000;
                cm.gainExp(exp);
            } else {
                cm.sendOk("Unable to find anything inside.");
            }
            clickedSpots[i] = 1;
        }
    }
    eim.setProperty("clickedSpots", clickedSpots.toString());
    cm.dispose();
}

Eim : 

var pqtime = 45, eventMaps = [926110000], minPlayers = 3, exitMap = 261000021;
var posArrayx = [-1638, -1496, -1386, -1366, -1286, -1252, -1178, -1040, -908, -884, -678, -578, -584, -438, -318, -200, 300, 560, 618, 784, 778, 894, 1142, 1048, 1234, 1348];

function init() {

}

function setup() {
    var eim = em.newInstance("Romeo and Juliet");
    var randClickSpot = Math.floor((Math.random() * 26) + 0);
    eim.setProperty("randClick", randClickSpot);
    var mesosArray = new Array();
    var expArray = new Array();
    var clickedSpots = new Array();
    for (var i = 0; i < posArrayx.length; i++) {
        clickedSpots.push(0);
        var rand = Math.floor(Math.random() * 5);
        if (i != randClickSpot) {
            if (rand == 4) {
                mesosArray.push(posArrayx[i]);
            } else if (rand == 3) {
                expArray.push(posArrayx[i]);
            }
        }
    }
    eim.setProperty("mesosArray", mesosArray.toString());
    eim.setProperty("expArray", expArray.toString());
    eim.setProperty("clickedSpots", clickedSpots.toString());
    eim.startEventTimer(1000 * 60 * pqtime);
    return eim;
}

function playerEntry(eim, player) {
    var map = eim.getMapInstance(eventMaps[0]);
    player.changeMap(map);
}

function playerDead(eim, player) {
}

function playerRevive(eim, player) {
    var party = eim.getPlayers();// player presses ok on the death pop up.
    if (eim.isLeader(player) || party.size() <= minPlayers) { // Check for party leader
        for (var i = 0; i < party.size(); i++) {
            playerExit(eim, party.get(i));
        }
        eim.dispose();
    } else {
        playerExit(eim, player);
    }
}

function changedMap(eim, player, mapid) {
    var onEvent = false;
    for (var i = 0; i < eventMaps.length; i++) {
        if (mapid == eventMaps[i]) {
            onEvent = true;
        }
    }
    if (!onEvent) {
        removePlayer(eim, player);
    }
}

function playerDisconnected(eim, player) {
    var party = eim.getPlayers();
    if (eim.isLeader(player) || party.size() < minPlayers) {
        var party = eim.getPlayers();
        for (var i = 0; i < party.size(); i++) {
            if (party.get(i).equals(player)) {
                removePlayer(eim, player);
            } else {
                playerExit(eim, party.get(i));
            }
            eim.dispose();
        }
    } else {
        removePlayer(eim, player);
    }
}

function leftParty(eim, player) {
    var party = eim.getPlayers();
    if (party.size() < minPlayers) {
        for (var i = 0; i < party.size(); i++) {
            playerExit(eim, party.get(i));
        }
        eim.dispose();
    } else {
        playerExit(eim, player);
    }
}

function disbandParty(eim) {
    var party = eim.getPlayers();
    for (var i = 0; i < party.size(); i++) {
        playerExit(eim, party.get(i));
    }
    eim.dispose();
}

function playerExit(eim, player) {
    eim.unregisterPlayer(player);
    player.changeMap(exitMap);
}

function removePlayer(eim, player) {
    eim.unregisterPlayer(player);
    player.getMap().removePlayer(player);
    player.setMap(exitMap);
}

function clearPQ(eim) {
    var party = eim.getPlayers();
    for (var i = 0; i < party.size(); i++) {
        playerExit(eim, party.get(i));
    }
    eim.dispose();
}

function allMonstersDead(eim) {
}

function monsterDead(eim) {

}

function monsterValue(eim) {
    return -1;
}

function cancelSchedule() {
}

function scheduledTimeout(eim) {
    if (eim != null) {
        if (eim.getPlayerCount() > 0) {
            var pIter = eim.getPlayers().iterator();
            while (pIter.hasNext()) {
                playerExit(eim, pIter.next());
            }
        }
        eim.dispose();
    }
}

function dispose(eim) {

}

Error : 
Caused by: sun.org.mozilla.javascript.internal.EvaluatorException: Array index 1
5 is out of bounds [0..0]. (<Unknown source>#49)
        at sun.org.mozilla.javascript.internal.DefaultErrorReporter.runtimeError
(Unknown Source)
        at sun.org.mozilla.javascript.internal.Context.reportRuntimeError(Unknow
n Source)
        at sun.org.mozilla.javascript.internal.Context.reportRuntimeError(Unknow
n Source)
        at sun.org.mozilla.javascript.internal.Context.reportRuntimeError2(Unkno
wn Source)
        at sun.org.mozilla.javascript.internal.NativeJavaArray.put(Unknown Sourc
e)
        at sun.org.mozilla.javascript.internal.ScriptableObject.putProperty(Unkn
own Source)
        at sun.org.mozilla.javascript.internal.ScriptRuntime.setObjectIndex(Unkn
own Source)
        at sun.org.mozilla.javascript.internal.ScriptRuntime.setObjectIndex(Unkn
own Source)
        at sun.org.mozilla.javascript.internal.Interpreter.interpretLoop(Unknown
 Source)
        at sun.org.mozilla.javascript.internal.Interpreter.interpret(Unknown Sou
rce)
        at sun.org.mozilla.javascript.internal.InterpretedFunction.call(Unknown
Source)
        at sun.org.mozilla.javascript.internal.ContextFactory.doTopCall(Unknown
Source)
        at com.sun.script.javascript.RhinoScriptEngine$1.superDoTopCall(Unknown
Source)
        at com.sun.script.javascript.RhinoScriptEngine$1.doTopCall(Unknown Sourc
e)
        at sun.org.mozilla.javascript.internal.ScriptRuntime.doTopCall(Unknown S
ource)
        at sun.org.mozilla.javascript.internal.InterpretedFunction.call(Unknown
Source)
        ... 27 more

No matter how am i trying to do it. for somereason i can't change the clickedSpots Array.. it does recognize the array but i can't change the data. i cant push into it. and i can't change the data inside it. Line : 49 is , clickedPos[i] = 1. any one have a solution to this problem ? i'm really desperate. i tried couple of things and none of them are working.

  • 2
    This seems rather strange, `clickedSpots` is an array, but then you try to call `split(",")` on it. – ci_ Aug 31 '15 at 15:35
  • You beat me to it @ci_ – xDaevax Aug 31 '15 at 15:36
  • @xDaevax except that wouldn't generate the exception presented here, something is odd – ci_ Aug 31 '15 at 15:45
  • You are correct, my bad. i've eddited the post . the error is the same error,. @ci_ –  Aug 31 '15 at 15:47
  • What is `posArrayx` and where is it defined? – Howard Renollet Aug 31 '15 at 15:51
  • 1
    Can you give us a more complete code sample? What framework are you using that defines `setProperty` and `getProperty` methods? Where is eim declared in the top code listing? – xDaevax Aug 31 '15 at 15:52
  • Agreed @xDaevax, I feel like we're missing some key points here that would help in figuring this out. – Howard Renollet Aug 31 '15 at 15:53
  • 1
    I'll just post the full code, One moment please, –  Aug 31 '15 at 15:53
  • Added the full code, @xDaevax –  Aug 31 '15 at 15:59
  • Thanks for that. Still could use a bit more context though. What is `em`? What is `cm`? Are you using some framework? – xDaevax Aug 31 '15 at 16:00
  • Well, im not using framework. about the em and cm. they are classes in my source. –  Aug 31 '15 at 16:01
  • @BillowXD I'm not even sure you're looking at the right line here, can you debug this step by step and give us some more information what line breaks, what the types of the variables are at that stage and any other parameters? – ci_ Aug 31 '15 at 16:05
  • @ci_ The error happends when im trying to push new data to the clickedSpots array. for somereason its work properly in the eim script. but not in the npc script. –  Aug 31 '15 at 16:08
  • Also, you have `var clickedSpots = eim.getProperty("clickedSpots").split(",");` which is an Array, then you push to the array, then you store the **ARRAY** back in the `setProperty` method, but in your setup you store `array.ToString()` If line "49" is the issue, then it seems like line 52 should be storing `clickedSpots` as a string, rather than an array so it is consistent with your setup method. Don't know if that is *the* issue, but it is *an* issue. – xDaevax Aug 31 '15 at 16:10
  • setProperty / getProperty works on string stored data. so if i want to store an array i'll have to parse the array to string. –  Aug 31 '15 at 16:16
  • Seems like you're using ScriptScraft to write a MineCraft mod, is that correct? – xDaevax Aug 31 '15 at 16:29
  • Im taking my word back, nothing work no matter how am i trying to do this method. I'll post the new try method. –  Aug 31 '15 at 16:33
  • xDaevax. i've posted the other way of doing it. but still nothing works. –  Aug 31 '15 at 16:44
  • is there a jsfiddle for this? i tried to run `start()` but only got an error that cm is not defined – llamerr Aug 31 '15 at 21:51
  • @llamerr , cm is not defined because you need the source files. i've just posted a tiny piece of the code. and i don't know whats worng about it. –  Sep 01 '15 at 14:49
  • what I meant is that you could provide jsfiddle example which everyone can inspect and have same result as you – llamerr Sep 01 '15 at 15:07
  • We need to see what setProperty and getProperty do. There may be an underlying implementation detail causing the behavior. The closest I came to a working fiddle that reproduced a similar issue was: http://jsfiddle.net/xDaevax/eq70awut/ – xDaevax Sep 01 '15 at 16:31

0 Answers0