Jump to content
  • 0

How to paginate menu/select?


Foob

Question


  • Group:  Members
  • Topic Count:  46
  • Topics Per Day:  0.02
  • Content Count:  267
  • Reputation:   40
  • Joined:  01/19/17
  • Last Seen:  

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?

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

  • Group:  Members
  • Topic Count:  34
  • Topics Per Day:  0.01
  • Content Count:  215
  • Reputation:   45
  • Joined:  05/03/13
  • Last Seen:  

Hello,

Split in different string .@menu1$, .@menu2$ ect, with a next/previous, so you'll simulate pagination

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  1
  • Topics Per Day:  0.00
  • Content Count:  18
  • Reputation:   12
  • Joined:  04/10/20
  • Last Seen:  

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
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  50
  • Topics Per Day:  0.01
  • Content Count:  1702
  • Reputation:   238
  • Joined:  09/05/12
  • Last Seen:  

You can check out @Skorm post here 

 

  • Like 1
Link to comment
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.   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.

×
×
  • Create New...