This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
hbomb79's profile picture

Dynamic List

Started by hbomb79, 17 December 2014 - 03:11 AM
hbomb79 #1
Posted 17 December 2014 - 04:11 AM
Hey everyone, Kinda stumped on this…

Lets say I have an array with several ID numbers inside of it, And I want to loop through it and display the number on screen… Thats simple enough right? What happens when the array contains more than 19 IDs… they move the page down hiding the rest.

I would like help doing the following:

Lets say the array has 13 IDs, I want it so that the first 6 are displayed on screen like thumbnails, I can handle the button drawing… So ones in the top left, next in the top right, then middle left, and so on… Then there is a next button that takes you to the next page displaying the next 6 IDs… and so on until you get to the last page where the button of course no longer does anything and dissappears, there will also be a back button which does the exact opposite (obviously)

can anyone give me any help on this, I have looked at other code but its too difficult for my self to follow..

Thanks in advance -Harry
Edited on 17 December 2014 - 03:42 AM
KingofGamesYami #2
Posted 17 December 2014 - 04:48 AM
I had to do this with my menu. Here's the specific part separating the argument table (tArgs) into the pages.

relevant part

local pages = {[1]={}} --#make table, first entry is another table
for i = 1, #tArgs, 1 do --#iterate through tArgs
	if #pages[ #pages ] == 7 then --#if the length of the last table in the array is 7 then
		pages[ #pages + 1 ] = {} --#add a new empty table
	end
	pages[ #pages ][ #pages[#pages] + 1 ] = tArgs[ i ] --#*
end
*This requires a bit of an explination:

Two parts:

pages[ #pages ] --#last table in the pages table

[ #pages[#pages] + 1 ]#--length of the last table in the table pages + 1

--#smash it together and you get
--#inserting an entry into the last table in the pages table, at the length of the last table in the pages table + 1
hbomb79 #3
Posted 17 December 2014 - 06:01 PM
Thanks, the page calculation is very helpful, although every thing else is replaced by my Apis and buttons, very helpful tho. Thanks for your help