Log In  


I need help adding a variable to a menu. I've created simple menus that I can add plain text to with "", but I have no idea how to add a variable to that menu.
Context is that the variable is a hunger meter that will go down periodically. I want the menu to display the current number of hunger.



1

oh i think print(var_here,x,y,col)


1

If the variable is a number, than using the .. operator will work. Its main purpose is combining text, but numbers will be automatically converted to text when combined with text.

For example:

  h = 5
  t = "Your hunger is "..h
  print(h)

should result in printing "Your hunger is 5"


1

hey @Mondast,
it would be helpful if you post a pic or even a cart( In this post is my first try to post a cart :D , so we know what's your goal to do.

There is a "preview" button under the posts, and there you find "Formatting help" and "add image" "add cartridge" where you upload a pic/cart.

Try to read something about tables (pico-8) or array/list (other programm language)

I use tables (arrays) quite often, and with unpack() you can create readable code, I guess. but i'm a noob, might create other problems.
I found this unpack like here https://www.lexaloffle.com/bbs/?pid=100436#p

Here is some code,that creates a box, a bar changing with time an two barschanging with the buttons x,o. And an animal changing with to much hunger.

Might be to much, but i'm still learning pic0-8 and helping in forums ;)

-- hunger_tutorial
-- by zellente

function _init()
--some varible 
	t_frame = 0 
	hunger = 10
--															{ xstart,ystart, xend,yend,  colornumber}
	rect_hunger1 	= {5,5,            5,5,         3 }
	rect_hunger2 	= {5,10,5,10,4 }
	rect_hunger3 	= {5,15,5,15,5 }

	--a box
	rect_top 	= {0,0,100,40,2 }
	-- a sprite 
	myspr = {1,20,30}

end

function _draw()
	cls()
	--unpack separtes the numbers in a table, default by ","

	rectfill(unpack(rect_top))
-- 	rectfill(unpack(rect_top)) becomes rectfill(5,5,5,5,4) 

	rectfill(unpack(rect_hunger1))
	rectfill(unpack(rect_hunger2))
	rectfill(unpack(rect_hunger3))
--	works with spr() too
	spr(unpack(myspr))

print("press ❎ or 🅾️ ",0,25,9)

tmp_print = {"press ❎ and 🅾️ to reset",0,100,4}
print(unpack(tmp_print))
end

function _update()
--this grows every frame 
	if t_frame < 90 then
		t_frame+=1
	else
		t_frame=5
	end
	--[[this changes the 3rd value in
	rect_hunger1{...  ,  ..  ,this number,..}
	]]
	rect_hunger1[3] = t_frame

	if btn(🅾️) then
		rect_hunger2[3] += hunger
	end

	if btnp(❎) then
		rect_hunger3[3] += hunger
	end

	if rect_hunger3[3] > 40 then
		myspr[1] = 2
	end	

	--reset 
	if btnp(❎) and btnp(🅾️) then
	_init()
	end
end


Cart #hebitataku-0 | 2024-09-24 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
1



[Please log in to post a comment]