Log In  


Cart #23399 | 2016-06-21 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
8

Fireworks simulation in less 200 tokens !

8


Never really had a lot of Lua experience prior to this. So the commonly accepted way to make "objects" in Lua is to just make a function that returns a table of pre-configured values?

Also, is there a particular reason you did

function p_create(x,y,color,speed,direction)  
  p={}
  p.x=x
  p.y=y
  p.color=color
  p.dx=cos(direction)*speed
  p.dy=sin(direction)*speed
  return p
end

Rather than:

function p_create(x,y,color,speed,direction)  
  local p=
  {
    x=x,
    y=y,
    color=color,
    dx=cos(direction)*speed,
    dy=sin(direction)*speed,
  }
  return p
end

Like I said, not a Lua expert, but this seems to make more sense, since it saves about 5 tokens, and stops "p" from being a global variable.


even better:

function p_create(x,y,color,speed,direction)  
  return {
    x=x,
    y=y,
    color=color,
    dx=cos(direction)*speed,
    dy=sin(direction)*speed
  }
end

Hi Danjen and Musurca - indeed that's much better. Thank you very much - I did some research I just learned that in Lua, scope of variables is global by default (!)



[Please log in to post a comment]