Log In  


I am asking this because the code I make is basically functions inside functions inside functions inside functions and I just think it makes the code really messy.

1


1

If it works for you, it's fine. There's really no right or wrong when coding for Pico-8, just personal preference. I myself create functions when I'm going to need the code to be repeated multiple times on different contexts. For example, I create a function to draw sprites for my game objects, so instead of doing something like this:

draw sprite for obj1
draw sprite for obj2
draw sprite for obj3
draw sprite for obj4...

I do this:
for s in all(objects) do
drawsprite(s)
end

and "drawsprite" would do everything I want to with those game objects sprites. That way, I avoid repeating myself in code and all I have to do is make sure the objects I want to draw are in the same table (the "objects" table, in this case).

That's how I decide when to create a function or not.


Do you meant that you have too many functions defined inside other functions, or called from other functions? The latter would be very normal.


I meaned functions called by other functions. Sorry


Then it’s just normal. We don’t want to have a wall of impossible to read code, so we move bits of functionality into functions and call them. There is a cost (with the virtual CPU cycles defined by pico-8), but it’s much better than having no functions!



[Please log in to post a comment]