Log In  

Hello everyone,
I am kinda new to Pico-8 (as I worked with TIC-80 before). I am working on a game and I was trying to manage the code to be more readable by moving some code around.

I added all the helper functions at the top of the p8 file (as I was trying to move it to another lua file to use the #include command). When I ran the code, no error but it didn't behave as it supposes to do. The helper functions use some global variables so I moved that code to be after the definition of the variables and it worked fine.

Does functions in pico8 lua bind the variables in the function to the global variables when it is defined (which is before the definition of the variables) that's why it is reading nil? I am not amazing with these binding stuff so sorry if I am using incorrect termonolgy.

Ahmed Khalifa

P#64526 2019-05-17 23:25

late reply but maybe useful!

I think you are asking whether lua does function hoisting, like javascript does? it doesn’t!

a function can reference and work with a global variable that’s defined after the function, but you can’t call the function before the variable is defined!

P#134499 2023-09-17 18:44

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-28 21:29:07 | 0.004s | Q:11