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?
Without seeing your code it’s hard to tell. I suggest looking at my simple snake example:https://gist.github.com/Westenburg/6487451
In it the when the snake eats a mushroom a new one is generated at a random location.
As an alternative look up tables - I think they might help your TLDR question
Well currently the apple generation code is this:
appleX = math.random (1,560)
appleY = math.random (1,560)
appleX1 = math.random (1,560)
appleY1 = math.random (1,560)
appleX2 = math.random (1,560)
appleY2 = math.random (1,560)
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 - you need to learn about Lua tables. There are various tutorials around. I also cover them in my ebook below
So sre tables the solution?
@Adam9812 Here’s an example using tables to draw 50 hearts. Replace the heart sprite with your apple sprite.
for a=1,50 do
background(40, 40, 50)
for a,b in pairs(apples) do
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.
@Adam9812 - yes, learning about Lua will help a lot. I have other ebooks and a lot of posts here
And there is lots more stuff on the wiki link above.
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