My first project, advice and tips welcome!

Show off your games, demos and other (playable) creations.
pekka
Party member
Posts: 206
Joined: Thu Jan 07, 2010 6:48 am
Location: Oulu, Finland
Contact:

Re: My first project, advice and tips welcome!

Post by pekka »

ninwa wrote:

Code: Select all

			if( (v["alive"] == false) and
Quick tip here. In lua v["alive"] and v.alive are the same when v is a table. Both access the field under the key "alive" in the table, and you can also access fields that are not there. You will get a nil as a result.

You may have programmed previously with languages featuring static typing where this does not hold. Some dynamic language would also raise an error when accessing a key that does not exist, but Lua does not. You just get a nil.

Since v.alive is a little less noisy-looking, I recommend using it. In fact I'd use not v.alive as the test here. Not a big deal, though, but just a style preference :)
User avatar
ninwa
Party member
Posts: 118
Joined: Tue Oct 12, 2010 1:21 am
Location: Metro Detroit
Contact:

Re: My first project, advice and tips welcome!

Post by ninwa »

pekka wrote:
ninwa wrote:

Code: Select all

			if( (v["alive"] == false) and
Quick tip here. In lua v["alive"] and v.alive are the same when v is a table. Both access the field under the key "alive" in the table, and you can also access fields that are not there. You will get a nil as a result.

You may have programmed previously with languages featuring static typing where this does not hold. Some dynamic language would also raise an error when accessing a key that does not exist, but Lua does not. You just get a nil.

Since v.alive is a little less noisy-looking, I recommend using it. In fact I'd use not v.alive as the test here. Not a big deal, though, but just a style preference :)
Awesome! Thank you very much. I definitely like that a lot better (and will undoubtedly be going back and changing all of my code, just like I did when TechnoCat recommended ipairs :p). And yes, I've spent most of my programming time in C++ so the concepts of loose-typing is still bouncing around trying to settle in my brain. I am really enjoying it though. I had actually started writing this game initially using SDL and happened upon Love2D when I was looking something up and decided it was time to try something new. I think after this I'm going to go out and swallow a LUA manual, figuring it out as you go is fun but not always very efficient.
User avatar
zac352
Party member
Posts: 496
Joined: Sat Aug 28, 2010 8:13 pm
Location: In your head.
Contact:

Re: My first project, advice and tips welcome!

Post by zac352 »

pekka wrote:
ninwa wrote:

Code: Select all

			if( (v["alive"] == false) and
Quick tip here. In lua v["alive"] and v.alive are the same when v is a table. Both access the field under the key "alive" in the table, and you can also access fields that are not there. You will get a nil as a result.

You may have programmed previously with languages featuring static typing where this does not hold. Some dynamic language would also raise an error when accessing a key that does not exist, but Lua does not. You just get a nil.

Since v.alive is a little less noisy-looking, I recommend using it. In fact I'd use not v.alive as the test here. Not a big deal, though, but just a style preference :)
You have no idea how much more debugging spelling errors is without it erroring. :P
I also don't like how Lua prints one error, then gives up.. I have to run my scripts hundreds of times. o_e
Hello, I am not dead.
pekka
Party member
Posts: 206
Joined: Thu Jan 07, 2010 6:48 am
Location: Oulu, Finland
Contact:

Re: My first project, advice and tips welcome!

Post by pekka »

zac352 wrote:You have no idea how much more debugging spelling errors is without it erroring. :P
I also don't like how Lua prints one error, then gives up.. I have to run my scripts hundreds of times. o_e
This is a common complaint and the usual answers are in the Lua users Wiki on this page:

http://lua-users.org/wiki/DetectingUndefinedVariables

You can use the pcall and xpcall functions to execute portions of code with error handling. They are explained in the manual. Unit testing would also help with catching erroneous behavior early in the development process. I suggest you look into it.

By the way, I have no strong language preferences myself. I like statically typed languages too. I've enjoyed programming even in Haskell, which is pretty darn strongly typed compared to anything else I've tried. But when we live in the dynamic typing land, as with Lua, we better adapt. So, please do consider using unit testing. A lot. You code will thank you :)

(I've been looking at using Lunatest lately: http://github.com/silentbicycle/lunatest . I don't yet have much experience with it, as I haven't had the chance to write anything interesting these past two weeks or so. The docs are all right, but they don't teach you how to write unit tests. There's a lot of advice for that elsewhere.)

P.S. I'm not trying to take over this thread. If you wish to argue language features or unit testing, try it in another thread. I'll let the OP take over again!
User avatar
zac352
Party member
Posts: 496
Joined: Sat Aug 28, 2010 8:13 pm
Location: In your head.
Contact:

Re: My first project, advice and tips welcome!

Post by zac352 »

pekka wrote:
zac352 wrote:You have no idea how much more debugging spelling errors is without it erroring. :P
I also don't like how Lua prints one error, then gives up.. I have to run my scripts hundreds of times. o_e
This is a common complaint and the usual answers are in the Lua users Wiki on this page:

http://lua-users.org/wiki/DetectingUndefinedVariables

You can use the pcall and xpcall functions to execute portions of code with error handling. They are explained in the manual. Unit testing would also help with catching erroneous behavior early in the development process. I suggest you look into it.

By the way, I have no strong language preferences myself. I like statically typed languages too. I've enjoyed programming even in Haskell, which is pretty darn strongly typed compared to anything else I've tried. But when we live in the dynamic typing land, as with Lua, we better adapt. So, please do consider using unit testing. A lot. You code will thank you :)

(I've been looking at using Lunatest lately: http://github.com/silentbicycle/lunatest . I don't yet have much experience with it, as I haven't had the chance to write anything interesting these past two weeks or so. The docs are all right, but they don't teach you how to write unit tests. There's a lot of advice for that elsewhere.)

P.S. I'm not trying to take over this thread. If you wish to argue language features or unit testing, try it in another thread. I'll let the OP take over again!
I know how to find undefined values. I'm just lazeh. :|
Hello, I am not dead.
pekka
Party member
Posts: 206
Joined: Thu Jan 07, 2010 6:48 am
Location: Oulu, Finland
Contact:

Re: My first project, advice and tips welcome!

Post by pekka »

ninwa wrote: I think after this I'm going to go out and swallow a LUA manual, figuring it out as you go is fun but not always very efficient.
Lua people would have you write it as a word, since it is a Portuguese word (for the moon!) and not an abbreviation. So please use Lua and not LUA :)

Programming in Lua is a good book and I recommend referring to it while you are learning on your own. The on-line version has some dated info about a few technical details, but that shouldn't cause a lot of trouble. There are a few things about modules that have changed in Lua 5.1 which is what Löve uses, so you should read about them from the Lua Users Wiki after getting to them in the (on-line) PiL. And there may be some other minor differences, but I don't remember any right now. That kind of suggests you won't need to worry about them yet either.

The newest version is for sale as a physical book or an e-book. I think it is completely up to date until Lua 5.2 comes officially out (and Löve devs switch to it...).

Here is the on-line version:
http://www.lua.org/pil/
User avatar
zac352
Party member
Posts: 496
Joined: Sat Aug 28, 2010 8:13 pm
Location: In your head.
Contact:

Re: My first project, advice and tips welcome!

Post by zac352 »

pekka wrote:
ninwa wrote: I think after this I'm going to go out and swallow a LUA manual, figuring it out as you go is fun but not always very efficient.
Lua people would have you write it as a word, since it is a Portuguese word (for the moon!) and not an abbreviation. So please use Lua and not LUA :)
I used to say "LUA stands for Licking Under Arms. Lua is a programming language.", but it is rather immature. Can anyone think of a better acronym? :P
Hello, I am not dead.
User avatar
Thursdaybloom
Citizen
Posts: 81
Joined: Mon Feb 15, 2010 3:43 am
Location: Australia

Re: My first project, advice and tips welcome!

Post by Thursdaybloom »

Can anyone re-rail this thread back on track?

Thanks
User avatar
ninwa
Party member
Posts: 118
Joined: Tue Oct 12, 2010 1:21 am
Location: Metro Detroit
Contact:

Re: My first project, advice and tips welcome!

Post by ninwa »

Thursdaybloom wrote:Can anyone re-rail this thread back on track?

Thanks
Please and thank you, I'll try.

Minor update:
  • Added sound effects
  • Added scoring
  • Changed the waves around
  • Changed all table lookups from x["y"] style to x.y style.
Download: http://www.josephbleau.com/SpaceScout_v0-4.love
Last edited by ninwa on Tue Oct 12, 2010 2:18 pm, edited 2 times in total.
User avatar
Thursdaybloom
Citizen
Posts: 81
Joined: Mon Feb 15, 2010 3:43 am
Location: Australia

Re: My first project, advice and tips welcome!

Post by Thursdaybloom »

Good work ninwa.

You posted the update right before I was about to sleep :P so I'll play it more tomorrow.

Am I suppsed to be able to hold down space for INFINITE LAZ0RZ though?
Post Reply

Who is online

Users browsing this forum: No registered users and 35 guests