I am trying to make a game where a blob eats apples. In order to make the dissapear when you eat it, a ‘gone’ variable was once used. Now, as I see that that is hard to use if you want the apple to reappear in another random spot, so I replaced it with appleNumber. The problem is. I can’t efficiently make a new apple in a new spot. I was hoping to use the existing variables appleX, and appleY, to determine area but for the second apple I need to make a whole new variable manually how do you make it so the code automatically does so. I know how to do it with strings “string1” + “string2”, but how do you do it with variables without arithmetically adding them up?
TLDR: How do you put variables next to one other to make a new one without adding them?
But, instead is there a way for for me to make as many apples as I want randomly without havering to use an infinite amount of variables and functions to eat the apple?
@Adam9812 Here’s an example using tables to draw 50 hearts. Replace the heart sprite with your apple sprite.
displayMode(FULLSCREEN)
function setup()
apples={}
for a=1,50 do
table.insert(apples,vec2(math.random(WIDTH),math.random(HEIGHT)))
end
end
function draw()
background(40, 40, 50)
for a,b in pairs(apples) do
sprite("Small World:Heart",b.x,b.y)
end
end
I am sorry if I seem unknowledgeble about lua. Thanks though. I will be sure to finish you book so I can more sufficiently solve these problems myself.
Never apologize for seeming unknowledgable, everyone starts there at some point \^-^/
Plus there’s a whole forum segment dedicated to peoples’ questions, you aren’t alone