Error in NPC Script , cannot convert to Intergers ???

Results 1 to 6 of 6
  1. #1
    Proficient Member TheJava is offline
    MemberRank
    Jan 2014 Join Date
    166Posts

    Error in NPC Script , cannot convert to Intergers ???

    PHP Code:
    var status 0;var randomitems = [1302000,1302001];function start() {    status = -1;    action(100);}
    function 
    action(modetypeselection) {    if (mode == -1) {        cm.dispose();    } else {        if (mode == && status == 1) {            cm.dispose();            return;        }        if (mode == 1)            status++;        else            status--;            if (status == 0) {                cm.sendNext("Test");            } else if (status == 1) {                cm.sendSimple("So, why are you talking to me? \r\n #L0##bPls giv me free items#k#l \r\n #L1##bNevermind#k#l");            } else if (status == 2) {                if (selection == 0) {               cm.gainItem(randomitems ,1);cm.dispose();               } else if (selection == 1) {                    cm.dispose();                }            }    } } 
    As you can see I made a var which has 2 items in it but when I do cm.gainItem(randomitems ,1); it gives me an error called "Cannot convert 1302000,1302001 to java.lang.Interger"

    Any help ?


  2. #2
    Member Drum is offline
    MemberRank
    Jul 2013 Join Date
    80Posts

    Re: Error in NPC Script , cannot convert to Intergers ???

    randomitems is of type array. The gainItem() method signature defines the first parameter to be java.lang.Integer. The error printed is telling you that the parser cannot implicitly convert an array to an integer. I think you might've intended this instead:

    PHP Code:
    cm.gainItem(randomitems[0], 1); // Indexing like so into the randomitems array will return its content at index 0, which in this case is an integer.
    cm.gainItem(randomitems[1], 1); // Same here for index 1. 

  3. #3
    Proficient Member TheJava is offline
    MemberRank
    Jan 2014 Join Date
    166Posts

    Re: Error in NPC Script , cannot convert to Intergers ???

    -Edit-
    The real purpose is to allow the player to gain different item each time he/she uses the NPC , what I can see from your method is he gains the item accordingly to [0] [1] e.t.c , anyways to change it to randomize ?
    Last edited by TheJava; 09-03-15 at 02:53 PM.

  4. #4
    Proficient Member TheJava is offline
    MemberRank
    Jan 2014 Join Date
    166Posts

    Re: Error in NPC Script , cannot convert to Intergers ???

    Bumpp

  5. #5
    Enthusiast Navi is offline
    MemberRank
    Sep 2014 Join Date
    38Posts

    Re: Error in NPC Script , cannot convert to Intergers ???

    gainItem(randomitems[Math.floor(Math.random()*randomitems.length)])

  6. #6
    Moderator Eric is offline
    ModeratorRank
    Jan 2010 Join Date
    DEV CityLocation
    3,188Posts

    Re: Error in NPC Script , cannot convert to Intergers ???

    Quote Originally Posted by TheJava View Post
    -Edit-
    The real purpose is to allow the player to gain different item each time he/she uses the NPC , what I can see from your method is he gains the item accordingly to [0] [1] e.t.c , anyways to change it to randomize ?
    Code:
    cm.gainItem(randomitems[Math.floor(Math.random() * randomitems.length)], 1);



Advertisement