Log In  


Hello, I'm very new to pico-8 (and fairly inexperienced with coding in general) and I need a bit of help with some menu code. I'd like to have a menu that has two sections to it that you can move between with the left and right arrows. I'm working off of pixelcod's menu code example, here is what I have so far:

--menu system

function init_menu()
	menu={"menu1","menu2"}
		menu.y=12
			menu1 = {}
				menu1.x=25
				menu1.options={"𝘸𝘒𝘭𝘬","𝘡𝘒𝘭𝘬","𝘡𝘒𝘬𝘦","𝘨π˜ͺ𝘷𝘦","π˜ͺ𝘯𝘷."}

			menu2 = {}
				menu2.x=88
				menu2.options={"𝘸𝘩𝘒𝘱","𝘬π˜ͺ𝘴𝘴","π˜₯π˜ͺ𝘴𝘴","𝘧𝘳𝘦𝘡","𝘴𝘡𝘯𝘺"}

	menu.amt=0
	menu.sel=1
	menu.swp=false

	for i in all(menu1.options,menu2.options) do
	  menu.amt+=1
	end

end

function update_menu()
 update_cursor()
end

function draw_menu()
	for i=1,menu.amt do
		oset=i*8
	end
 if menu.swp==true then
 	  if i==menu.sel then
	   spr(39,menu2.x,menu.y+oset,2,1)
			 print(menu2.options[i],menu2.x,menu.y+oset+1,10)	
			else
		 	spr(55,menu2.x,menu.y+oset,2,1)
				print(menu2.options[i],menu2.x,menu.y+oset+1,9)
			end
	else
			if i==menu.sel then
				spr(39,menu1.x,menu.y+oset,2,1)
				print(menu1.options[i],menu1.x,menu.y+oset+1,10)
			else
				spr(55,menu1.x,menu.y+oset,2,1)
				print(menu1.options[i],menu1.x,menu.y+oset+1,9)
		 end
		end
end

function update_cursor()
 if (btnp(⬆️)) menu.sel-=1 sfx(1)
 if (btnp(⬇️)) menu.sel+=1 sfx(1)
 if (btnp(⬅️)) menu.swp=false sfx(1)
 if (btnp(➑️)) menu.swp=true sfx(1)
 if (btnp(❎)) sfx(1)
 if (menu.sel>menu.amt) menu.sel=1
 if (menu.sel<=0) menu.sel=menu.amt
end

With this, it has the two menus that you can swap between left and right but the menu options don't show up/come up as [NIL]. At this point, I'm sure its something simple that I'm just not understanding! I'm also willing to more or less start over if it means I get the result I need (if you've ever played it, I am making a Princess Tomato in Salad Kingdom homage and want it to look like this: ). Any help I can get will be greatly appreciated!

1


In init_menu():

  • "menu1" and "menu2" in menu={"menu1","menu2"} are strings and don't refrence the menu1 and 2 tables. I would move the menu creation below menu1 and 2 and reference them directly like menu={menu1,menu2}, then to get a specific menu like menu1, you can do menu[1].
  • for i in all(menu1.options,menu2.options) do - all only takes one argument. You can get a quick reference and syntax for keywords by moving the cursor over one and hitting CTRL+U.
    Also, you can use # to count elements in a table like this: menu.amt = #menu1.options + #menu2.options. menu1.options refers to the options table in menu1, and # asks to count the number of elements in the table.

In draw_menu():

  • for i=1,menu.amt do oset=i*8 end - oset will be set to the last value of i when the loop ends.
  • You probably want to use a FOR loop for each side menu to draw each option. Something like for i=1,#menu1.options do ... end

Hope that helps!



[Please log in to post a comment]