Newbie Spellweaver
- Joined
- Jan 22, 2024
- Messages
- 5
- Reaction score
- 0
Hi guys, I have a little problem passing String array to nashorn. I wrote an alternative start method on NPCScriptManager to recieve String[] as an argument and put it in the iv and invoke the start script with it, however when I try to pick an option within the action function in the script, trying to call cm results in a client side crash.
start function works great and leads to a successful call of NPCMoreTalkHandler
start function works great and leads to a successful call of NPCMoreTalkHandler
Java:
public boolean start(MapleClient c, int npc, String fileName, MapleCharacter chr, String[] skills) {
try {
NPCConversationManager cm = new NPCConversationManager(c, npc, fileName);
if (cms.containsKey(c)) {
dispose(c);
}
if (c.canClickNPC()) {
cms.put(c, cm);
NashornScriptEngine iv = null;
if (iv == null) {
iv = getScriptEngine("npc/" + fileName + ".js", c);
}
if (iv == null) {
dispose(c);
return false;
}
iv.put("cm", cm);
iv.put("skills", skills);
scripts.put(c, iv);
c.setClickedNPC();
try {
System.out.println("start");
iv.invokeFunction("start", iv.get("skills"));
} catch (final NoSuchMethodException nsme) {
try {
iv.invokeFunction("start", chr);
} catch (final NoSuchMethodException nsma) {
nsma.printStackTrace();
}
}
} else {
c.announce(MaplePacketCreator.enableActions());
}
return true;
} catch (final UndeclaredThrowableException | ScriptException ute) {
FilePrinter.printError(FilePrinter.NPC + npc + ".txt", ute);
dispose(c);
return false;
} catch (final Exception e) {
FilePrinter.printError(FilePrinter.NPC + npc + ".txt", e);
dispose(c);
return false;
}
}
JavaScript:
var status = 0;
function start(skills) {
var jsSkills = Java.from(skills);
var menu = "Select your skill:\r\n";
for (var i = 0; i < jsSkills.length; i++) {
menu += "#L" + i + "#" + jsSkills[i] + "#l\r\n";
}
menu += "#k"
cm.sendSimple(menu);
}
function action(mode, type, selection) {
cm.sendOk("test1");
cm.dispose();
}