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.

P#95204 2021-07-23 01:42 ( Edited 2021-07-23 01:47)

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.

P#95214 2021-07-23 18:47 ( Edited 2021-07-23 18:48)

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

P#95223 2021-07-23 21:33

I meaned functions called by other functions. Sorry

P#95787 2021-08-08 20:23

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!

P#95790 2021-08-09 00:02

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-29 04:39:03 | 0.007s | Q:14