Live data from Hacker News

I open sourced my game along with a tutorial on how to make it using Lua

github.com

11–20 of 96 posts

Re: I open sourced my game along with a tutorial on how to make it using Lua

#11
post #6

I've never heard of Lua, but now that I am looking at it, it seems very friendly. Love how they call things what they are, for example `local` is just a local variable, or `repeat X until Y` for a loop. It's a joy to see, to be honest.

1-index kept throwing me off though

I think 0-index causes a lot of new programmers (and non-programmers) confusion because they aren't used to treating 0 as a counting instance. For example, A.D. 2020 suggests that (allowing for the various changes and debates) Jesus was born 2020 years ago, instead of counting the first year which would make (2021-1 day) years ago. I see this every year around New Year, headlines saying "Actually, it will be [year + 1]"

Re: I open sourced my game along with a tutorial on how to make it using Lua

#12
post #6

I've never heard of Lua, but now that I am looking at it, it seems very friendly. Love how they call things what they are, for example `local` is just a local variable, or `repeat X until Y` for a loop. It's a joy to see, to be honest.

1-index kept throwing me off though

Once you get used to it, it does help prevent a whole bunch of off by one errors though, as you don't need math when grabbing a range.

Like a string will always be:

    s:sub(1, #s)
And a sequence table will always be:

    for i = 1, #t do
      t[i]
    end

Re: I open sourced my game along with a tutorial on how to make it using Lua

#14
post #12
post #6

Earlier quoted context omitted.

1-index kept throwing me off though

Once you get used to it, it does help prevent a whole bunch of off by one errors though, as you don't need math when grabbing a range. Like a string will always be: s:sub(1, #s) And a sequence table will always be: for i = 1, #t do t[i] end

I disagree. Particularly when parsing strings, it's useful if the upper bound of one substring is the lower bound of a nonoverlapping substring immediately after. For example, here's a routine to split a string into the part before the first dot and the part after:

  function split_dot(s)
    local idx = s:find(".", 1, true)
    if not idx then return s end
    return s:sub(1,idx-1), s:sub(idx+1)
  end
It may come as a surprise that one should use a difference of 2 to skip over one character!

In a language that used the half-open interval convention we would end up with:

  s:sub(0, #s)
and

  for i = 0, #t do
    t[i]
  end
which seem just as good to me.

Re: I open sourced my game along with a tutorial on how to make it using Lua

#16

I've never heard of Lua, but now that I am looking at it, it seems very friendly. Love how they call things what they are, for example `local` is just a local variable, or `repeat X until Y` for a loop. It's a joy to see, to be honest.

Check out (the now unfortunately named) CoronaSDK from (the also unfortunately named) Corona Labs. It's all Lua based and is now entirely MIT open sourced. One of the easiest to code cross platform development languages there is.

I was introduced to game development (and my first "real" project) through CoronaSDK 3-4 years ago. Wrote a very simple android game. Ah it was fun! :-)

Re: I open sourced my game along with a tutorial on how to make it using Lua

#18

I've never heard of Lua, but now that I am looking at it, it seems very friendly. Love how they call things what they are, for example `local` is just a local variable, or `repeat X until Y` for a loop. It's a joy to see, to be honest.

I was first introduced to Lua via World of Warcraft. It's the scripting language used for Interface Customization.

https://www.wowhead.com/guide=5338/comprehensive-beginners-g...

Re: I open sourced my game along with a tutorial on how to make it using Lua

#20
post #12

Earlier quoted context omitted.

Once you get used to it, it does help prevent a whole bunch of off by one errors though, as you don't need math when grabbing a range. Like a string will always be: s:sub(1, #s) And a sequence table will always be: for i = 1, #t do t[i] end

I disagree. Particularly when parsing strings, it's useful if the upper bound of one substring is the lower bound of a nonoverlapping substring immediately after. For example, here's a routine to split a string into the part before the first dot and the part after: function split_dot(s) local idx = s:find(".", 1, true) if not idx then return s end return s:sub(1,idx-1), s:sub(idx+1) end It may come as a surprise that…

You wouldn't end up with this:

     s:sub(0, #s)
You would end up with:

     s:sub(0, #s - 1)
Which demonstrates the off-by-one error.
Post reply on HN