Hello everyone.
As I strive to become better at programming, theres one thing that is annoyingly very recurrent in my code which are counters.
I have counters for playing a sound effect only when changing scene, or when a collision first happens.
I have counters to manage the speed of swapping animation frames
I also have counters just to tell the passage of time or trigger elements or behaviours after a while.
My general approach is: Create a global time variable with the name for the thing it's timing
animationcounter = 0
Then on update or draw I have some sort of
if animationcounter <= 20 then sp +=1 animationcounter = 0 else animationcounter +=1 end |
Is there a better way to do this that can be used for all counters necessary? With a function? or maybe an object where we instantiate counters or something?


.jpg)


Hello everyone
I want to add an item for pick up on my procedural generated levels.
I have a pick up quantity and a table to hold them, and an individual table for each object.
I want items to be placed on tiles with the flag 5 because it's a busy street where my character can't get to a lot of the places.
Seemingly my only option is to use a while loop to iterate through x and y positions until it finds a flag 5 and then discount 1 from the pickup quantity until it's 0.
Unfortunately this results in the game not loading.
while crateamt > 0 do local x = rnd(map_end) local y = rnd(map_endy) if fget(mget(x*8,y*8),5) then add(crates, crate:new({ x=x, y=y })) crateamt -=1 else x = rnd(map_end) y = rnd(map_endy) end end |
What other options do I have?



Hello everyone.
First of all, I apologise if my code is a mess. I am learning to code and although stuff sometimes work, I don't fully understand why.
I am doing a game with a procedural map where there are buildings, and each building might or might not be a level. When generating the buildings I attach a level object to it if it is a level and I am printing underneath the ones that are levels, as well as the x and y coordinates and what level number it is.
The game is meant to have the following objects and relationships
Player (obvious)
A Building object > a level object > a combos object > multiple combos objects

