I'm new to Love2D

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
Programmer1500
Prole
Posts: 1
Joined: Wed Mar 02, 2016 11:30 pm

I'm new to Love2D

Post by Programmer1500 »

Hey guys. I recently installed Love2D, I really like the syntax and stuff. I'm trying to grow. But I'm not sure where to go next. I currently use Atom as my text editor with some Love and Lua extensions. Which make it really easy to program! But basically all the love concepts I know are the following:

Graphics SetColor
Graphics Draw
Loading Images
Drawing Images

And the basic love callbacks. Like update, draw, and load. Btw, I have a pretty good understanding of Lua. I've been down at Roblox for awhile and that's where my Lua knowledge came from. But yeah, I'd love to hear where I should go next to learn bigger concepts to put a game together. I just made a game where you controlled a character image with your keyboard. :)
User avatar
MadByte
Party member
Posts: 533
Joined: Fri May 03, 2013 6:42 pm
Location: Braunschweig, Germany

Re: I'm new to Love2D

Post by MadByte »

Hey,
welcome to the community!

Well, the most obvious thing to start with - the wiki tutorial section. Try to recreate and understand the examples - they should be a good starting point for everyone.

Personally I started by studying some projects made by others just to find out how they do certain things in their code. Best would be to pick out some simple examples - larger projects will most likely confuse you just because of their complexity. Keep an eye on the "Projects and Demos" section in the forums for some projects. Here are some good examples (imo):

LÖVE demos
Example Project

And if you're confident enough just try to start a really small game project like a pong game or a game where the player has to avoid stuff.

Here is a simple avoid game example:
AvoidGame.love
(1.19 KiB) Downloaded 173 times
(to see the code just extract the file like any other archive (zip, ..))

EDIT
There are three things I recommend to do a little research (if you dont know them already): "dt", "local" and "self"!

If you've any questions - feel free to ask!
Good luck and have fun!
Last edited by MadByte on Thu Mar 03, 2016 8:38 pm, edited 3 times in total.
bobbyjones
Party member
Posts: 730
Joined: Sat Apr 26, 2014 7:46 pm

Re: I'm new to Love2D

Post by bobbyjones »

I don't think self is a "keyword" in Lua. In the context of table:method() self is a table that is a arg. Syntax sugar hides that for us.
User avatar
MadByte
Party member
Posts: 533
Joined: Fri May 03, 2013 6:42 pm
Location: Braunschweig, Germany

Re: I'm new to Love2D

Post by MadByte »

bobbyjones wrote:I don't think self is a "keyword" in Lua. In the context of table:method() self is a table that is a arg. Syntax sugar hides that for us.
Sorry, the problem here is my bad english. Its not intended to be mentioned in one line with "keywords" like "if, else, break ..". I just meant that these are importent words regarding the usage of lua (imo). I've edited the post to make that more clear. Thanks for pointing out.
User avatar
zorg
Party member
Posts: 3444
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: I'm new to Love2D

Post by zorg »

bobbyjones wrote:I don't think self is a "keyword" in Lua. In the context of table:method() self is a table that is a arg. Syntax sugar hides that for us.
Or in other words, if you define a function inside a table with a colon (:) instead of a dot (.), lua will interpret that as if you created one with a dot, but also added an argument called self as the first argument in the argument list (inside the parentheses).
Relatedly, when calling a function using the colon syntax, then the table it houses it will be passed into it as the first parameter automatically, so that anything you pass in between the parentheses will start from after the self parameter.
The reason i worded it this verbosely is because i wanted to try and explain that this particular syntax sugar can be misleading, since there's no requirement for a function's declaration and call to use the same definition, making it possible to easily do things one didn't intend, hence it is error-prone.

Code: Select all

local t = {}
function t.foo(a,b) return a,b end -- equivalent to "t.foo = function(a,b) return a,b end"
function t:bar(a,b) return a,b end -- equivalent to "t.bar = function(self, a, b) return a,b end"; yes, self as a parameter is actually there, you don't have to list it in the argument list to use it.
t.foo(1,2) -- returns 1, 2
t:foo(3,4) -- returns table: 0x######, 3 (it printed self, since that forced itself into the first param. slot since our declaration didn't use the colon syntax, so the argument a got the address (value) of the table)
t.bar(5,6) -- returns 6, nil (because 5 went to the self parameter as it is the first one)
t:bar(7,8) -- returns 7, 8
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 259 guests