Array help

Helena

New member
Messages
238
Points
0
Emulator
rAthena
Hi again script pros.
default_smile.png


I have a issue with an array/menu I'm using. 

The snippet below is a part of my script and it works as intended except for one small issue.

As you can see, in the snippet I have 34 items in my setarray, but my items per page is 25. Which means that on the first page, it gives 25 items (which is how it should) BUT on the second it only gives 9 and it fills up the remaining 16 menu items with "null" to make it a total of 25 options.

My question is, how do i have 25 items per page but on the last page make it so it doesn't fill up with "null"s? Have those nulls cut off instead? Thank you sooo much! I appreciate everything you helped me with, community.
default_smile.png


Code:
    setarray .itemid,8028,8039,8031,8042,8053,8096,8134,8135,8155,8156,8170,8172,8182,8189,8190,8202,8203,8204,8211,8214,8215,8501,19004,19014,19029,19047,17048,29054,19170,12102,29121,19153,29193,16201;
 
    .itemperpage = 25;
 
    .@itemsize = getarraysize( .itemid );
    .@maxpage = .@itemsize / .itemperpage + ( .@itemsize % .itemperpage > 0 );
    while ( .@i < .@maxpage ) {
        .menu$[ .@i ] = ( .@i )? "^777777Previous Page^000000:" : ":" ;
        .@j = 1;
        while ( .@j < .itemperpage +1 ) {
            .itemname$[ .@k ] = getitemname( .itemid[ .@k ] );
            .menu$[ .@i ] = .menu$[ .@i ] + .itemname$[ .@k ] +":";
            .@j++;
            .@k++;
        }
        .menu$[ .@i ] = .menu$[ .@i ] +( ( .@i < .@maxpage -1 )? "^777777Next Page^000000" : "" );
        .@i++;
    }
    end;
 
My quick workaround would be adding a check if return value from getitemname is not "null". Then add the name to the menu.

 
My quick workaround would be adding a check if return value from getitemname is not "null". Then add the name to the menu.
Any idea how that could be achieved? Something like this?

if (getitemname( .itemid[ .@k ]) == "null" ){

end; 

}

?

 
Last edited by a moderator:
Probably the item doesn't exist on your item database?

Code:
*getitemname(<item id>)

Given the database ID number of an item, this function will return the 
text stored in the 'japanese name' field (which, in Hercules, stores an 
English name the players would normally see on screen).
Return "null" if no such item exist.
 
Replace

.itemname$[ .@k ] = getitemname( .itemid[ .@k ] );

with

.itemname$[ .@k ] = (getitemname( .itemid[ .@k ] ) != "null")?getitemname( .itemid[ .@k ] ):"";

That way nothing will be altered, client doesn't show empty options (""), but still counts them in when returning chosen index.

 
Back
Top