Jump to content
  • 0

How to paginate menu/select?


Question

Posted

I have this problem when select menu has many entry such as 50+ menu.

e.g.

setarray .@menu_list[0],1,2,3,4,5,6,up-to,100;
.@size = getarraysize(.@menu_list);
for( .@i = 0; .@i < .@size; .@i++ ) and so on..

In-game it will only appear up-to 50 and other will not show.

Is there a way to paginate select lets say for example per page is 30 menu then next is 30?

3 answers to this question

Recommended Posts

  • 0
Posted (edited)

It's pretty basic, but I've got a pagination function (based on Chris' found here: Click) that I use for my unlockable warper NPC. You should be able to use it in the same way.

 

This is the syntax for use:

@menuoption = callfunc("F_MPages",implode(@MENU_T$,":"));

@menuoption will return the array location. 

@MENU_T$ is the array containing all of the menu items.

 

Change .@pg_max to the number of options you'd like on each page. 

function	script	F_MPages	{

	.@debug = 0;

	.@pg_max = 20;
	explode(.@pg_array$,getarg(0),":"); // Re-Saving string into Array
	.@as = getarraysize(.@pg_array$);
	if(.@debug == 1){debugmes ".@as = "+.@as;}
	if(getarraysize(.@pg_array$) < .@pg_max){ 
		.@pg_count = 1;
		if(.@debug == 1){debugmes "Defaulting to 1 page";} 
	} else { 
		.@pg_count = 1;
		while(.@as > .@pg_max){
			.@pg_count = .@pg_count+1;
			.@as = .@as - .@pg_max;
		}
		@pg_count = (.@as/.@pg_max); // Calculating max pages based on .@pg_max
		if(.@debug == 1){debugmes "Setting "+.@pg_count+" pages";}  
	}
	set .@cur_pg,1;
	if(.@debug == 1){
		debugmes ".@pg_max = "+.@pg_max;
		debugmes ".@cur_pg = "+.@cur_pg;
		debugmes "Array size = "+getarraysize(.@pg_array$);
	}
MAIN:
		if(.@debug == 1){debugmes "Current Page ["+.@cur_pg+"]";}
		.@menu$ = "";
		for(.@i=.@q; .@i < (.@q+.@pg_max); .@i++){
				.@menu$ = .@menu$+.@pg_array$[.@i]+":";
			}
		if(.@cur_pg == .@pg_count){
			.@menu$ = .@menu$+"[^FF0000Cancel^000000]";
		} else if(.@cur_pg < .@pg_count){
			.@menu$ = .@menu$+"[^008722Next Page^000000]";
		}
		.@choice = select(.@menu$);
		if(.@debug == 1){debugmes ".@choice = "+.@choice;}
		if(.@choice > .@pg_max){ 
			if(.@cur_pg == .@pg_count) { callfunc "close3"; } 
			else if(.@cur_pg < .@pg_count) { .@cur_pg = .@cur_pg+1; .@q = .@q+.@pg_max; goto MAIN; }
		}
if(.@cur_pg == 1){ .@return = .@choice-1; }
else { .@return = (.@choice-1)+((.@cur_pg-1)*.@pg_max);  }
if(.@debug == 1){debugmes "return = "+.@return;}
return .@return;
//close;
}

 

Edited by PottScilgrim

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.   Paste as plain text instead

  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.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...