What could be causes of softlocks?

I stumbled upon a weird situation. I was making another function for different power up effect which uses scheme from other power up functions, it’s not big deal. But apparently I find out that this particular function cause softlock. When I deleted/commented this function, code works. With it, (even with empty body) while loading that module (gameplay module that loads after selecting start from menu), game freezes. Which is, can’t load game.lua, and just left in menu, app still works though. (debug prints in module didn’t show up in console so I assume it can’t load)

As far as I know, a cause could be left “and” or “==” empty etc. I had that problem before. But now I checked carefully that function and every other that I edited since code still worked, but with no succes. I won’t send the whole code 'cause it’s about 5k lines long and I wanna debug it by myself. I just want some hints about this situation.

Also I thought it could be problem with unwanted characters in document (i’m using Sublime btw.), I even noticed that i couldn’t write --[[ ]]-- comment at some point in area of that function. BUT I rewrite this part of code, and still doesn’t work. Even I send whole code to chatgpt to find some bad characters but no succes. More over, now code doesn’t work even I left this function or not. I have no clue why since I didn’t make any changes in file since rewriting function.

I made backup and started deleting some parts of code but nothing changed yet.

Any suggestions?

SOLVED

I found out (by using online Lua Interpreter) that might be too much globals. Deleted some, and it works. So that’s it. It’s time for tide up the code I guess

1 Like

As a general rule, try to avoid globals entirely if you can. I don’t have any at all (unless I make a mistake and accidentally create one), instead I have files which return a table for values that need to be references in multiple files.

I would also say try not to have too many individual local variables at the top of any file. If you have lots of variables you can probably condense them into a single table.

I won’t send the whole code 'cause it’s about 5k lines long

If that’s all in one file, I would definitely recommend splitting it up into multiple files. It will become really unmanageable if every aspect of the game is in one file. AI tools will probably be able to do it for you.

I even noticed that i couldn’t write --[[ ]]-- comment at some point in area of that function

This problem wasn’t related to your error, it’s most likely because you have [ ] characters in the code you are trying to comment out. Try putting an equals sign between the comment block markers, as that should allow the comment to work:

--[=[ 
block comment here
--]=]

You can even nest block comments this way, by using different number of equal signs

--[=[
this is comment block 1
this is comment block 1
    --[==[
    this is nested comment block 2
    this is nested comment block 2
    --]==]
this is comment block 1
this is comment block 1
--]=]
1 Like