Log In  

Is multiple assignment possible within a table, e.g.

e={
 x,y,health,timer=0,0,0,0,
 score_val=100,
 colour=7
}

When I do that, for some reason the timer value is returning nil.

Or, is there a limit to the number of multiple assignments? I am currently setting 16 variables to zero.

P#80734 2020-08-14 00:57 ( Edited 2020-08-14 01:09)

I just googled lua multiple assignment and got this stack overflow page that answers pretty thoroughly:
https://stackoverflow.com/questions/31780277/lua-multiple-assignment-with-tables

Judging from what that says, I think the closest way to what you have would be this:

e = {}
e.x,e.y,e.heath,e.time=0,0,0,0
e.score_val=100
e.colour=7

I'm not sure it'd be worth it though, since I think that'd be more tokens than just setting them individual in the initial table assignment.

P#80735 2020-08-14 05:50

Yeah, I already saw that, but it's no use, as the whole point of me using multiple assignment within tables was to save tokens.

P#80739 2020-08-14 08:42
2

You can use this trick with _ENV. It hides the environment and only becomes interesting with 8 elements or more.

e={}
do
  local _𝘦𝘯𝘷 = e
  x,y,health,timer,score_val,colour = 0,0,0,0,100,7   
end
P#80752 2020-08-14 13:54

That's perfect. Someone should add that to the Pico-8 guide for token reduction.

P#80753 2020-08-14 14:09

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-28 11:11:27 | 0.009s | Q:12