Today I learnt...

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
Gunroar:Cannon()
Party member
Posts: 1143
Joined: Thu Dec 10, 2020 1:57 am

Today I learnt...

Post by Gunroar:Cannon() »

... that a lua file has a limit of 200 local variables?

Code: Select all

Error

toybox/LGML.lua:125: Syntax error: hunt_TMP:201: main function has more than 200 local variables



Traceback

[C]: in function 'load'
toybox/LGML.lua:125: in function 'getSettingsToSave'
toybox/LGML.lua:165: in function 'saveData'
hunt/GameScreen.lua:1346: in function 'loadOverworld'
hunt/GameScreen.lua:1201: in function 'exitPlace'
hunt/Player.lua:393: in function 'action'
toybox/libs/chrono.lua:38: in function 'update'
toybox/entities/Room.lua:50: in function '__step'
toybox/entities/Game.lua:59: in function '__step'
toybox/LGML.lua:225: in function 'update'
[C]: in function 'xpcall'
Any fix for this? (This is the way I make save files.)
The risk I took was calculated,
but man, am I bad at math.

-How to be saved and born again :huh:
MrFariator
Party member
Posts: 559
Joined: Wed Oct 05, 2016 11:53 am

Re: Today I learnt...

Post by MrFariator »

Yep, lua has a hard-coded limit of 200 local variables within a given scope, or at least within a function. If you wrap some of those variables into a table, you can fit in more, because a table can hold many values, while only "consuming" one local.

Usually I think that reaching this limit is a code smell.
User avatar
Gunroar:Cannon()
Party member
Posts: 1143
Joined: Thu Dec 10, 2020 1:57 am

Re: Today I learnt...

Post by Gunroar:Cannon() »

Ahhh, heheh.

I use a lib called saveTable that saves the game data (nothing bulky, just states and triggers) in a lua file. And wince it was/is a "small" game and bitser seemed not to work on empty files or something, I used that and it's worked up to this point :P.

I guess maybe I'll try to really get bitser to work. :P :rofl:
The risk I took was calculated,
but man, am I bad at math.

-How to be saved and born again :huh:
User avatar
Gunroar:Cannon()
Party member
Posts: 1143
Joined: Thu Dec 10, 2020 1:57 am

Re: Today I learnt...

Post by Gunroar:Cannon() »

Something sinister here...how about if I make the lib write the tables in the save file as global instead of local ...just as a quick hack (for now) :P :rofl: ?
The risk I took was calculated,
but man, am I bad at math.

-How to be saved and born again :huh:
User avatar
darkfrei
Party member
Posts: 1204
Joined: Sat Feb 08, 2020 11:09 pm

Re: Today I learnt...

Post by darkfrei »

The saving and loading must be such easy as

Code: Select all

function on_save ()
  love.save ("data", Data) -- big letter means for global
end

Code: Select all

function on_load ()
  Data = love.load ("data")
end
Where Data is a table with tables and values, no metatables, no userdata, no functions or methods.
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests