Jump to content
  • 0
Sign in to follow this  
Helena

Array help

Question

Hi again script pros. :)

 

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. :)

 

 

    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;

Share this post


Link to post
Share on other sites

5 answers to this question

Recommended Posts

  • 0

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.

Share this post


Link to post
Share on other sites
  • 0

My quick workaround would be adding a check if return value from getitemname is not "null". Then add the name to the menu.

Share this post


Link to post
Share on other sites
  • 0

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; 

}

 

?

Edited by Helena

Share this post


Link to post
Share on other sites
  • 0

Probably the item doesn't exist on your item database?

*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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.