Log In  

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

Fireworks simulation in less 200 tokens !

P#23400 2016-06-21 15:18 ( Edited 2016-06-26 21:34)

:: Danjen

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.

P#23519 2016-06-23 22:19 ( Edited 2016-06-24 02:19)

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
P#23520 2016-06-23 22:34 ( Edited 2016-06-24 02:34)

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 (!)

P#23694 2016-06-26 17:34 ( Edited 2016-06-26 21:34)

[Please log in to post a comment]

Follow Lexaloffle:        
Generated 2020-02-27 21:57 | 0.018s | 2097k | Q:29