difference is???

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
elsalvador
Citizen
Posts: 54
Joined: Thu Oct 24, 2013 1:29 am

difference is???

Post by elsalvador »

for sure its a silly question but i just need to understand this:

whats the difference from . to : in programming or at least in love 2d?

love.load
menu:load

one its under love but than in menu we got two?
how does it works?
User avatar
CRxTRDude
Prole
Posts: 41
Joined: Sun Dec 15, 2013 3:03 am
Location: Some island in the archipelago

Re: difference is???

Post by CRxTRDude »

It depends on how the module is made.
Most libraries and modules use the ':' for module functions and '.' for the variables, since they stem from classes.

Yes, you may say that love.load is not a variable but a function, it stems from the LÖVE engine (i think).

It all then depends on you making the library, but the "':' for module functions and '.' for the variables" thing is more cleaner and organized (that's my opinion, which will be disputed eventually by someone who is more experienced than I am).

It may also be from Lua. You can search that on the internets too.
~ CRxTRDude || Will be out of touch for a wee longer than expected. Will keep in touch with soon enough. Sorry bout that.
pielago
Party member
Posts: 142
Joined: Fri Jun 14, 2013 10:41 am

Re: difference is???

Post by pielago »

are most program languages use . and : in the same way like love2d????
also you said LIBRARY..
can you tell me whats a LIBRARY exactly in programming? and in a library . is use more or : ????
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: difference is???

Post by Robin »

Okay, it is very simple: if you see function a:b(c), it is the same as function a.b(self, c). If you see a:b(c) it is the same as a.b(a, c).

Since there is only the global love table, love.load doesn't need to get that table passed in as its first argument.

Libraries are collections of code that don't do anything of themselves, but are used in another program. For example, LÖVE uses PhysFS to provide love.filesystem, Freetype to handle fonts, SDL to handle windows and stuff, and OpenGL for the actual drawing of things. Your game can use libraries too, those are generally written in Lua.
Help us help you: attach a .love.
User avatar
ivan
Party member
Posts: 1915
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: difference is???

Post by ivan »

pielago wrote:also you said LIBRARY..
can you tell me whats a LIBRARY exactly in programming?
A library is basically some (3-rd party) code that you include in your project.
In Lua, these are sometimes called "modules" or "packages".
pielago wrote:are most program languages use . and : in the same way like love2d????
Typically the "." operator means change in "scope".
So when you write: a.b You are saying "access variable b from scope a"

The ":" operator means a function call.
Like robin said a:c() is the same as a.c(a)
The ":" operator is basically syntactic sugar when working with "objects".
It basically passes the object reference(a) as the first parameter to the function(c).
pielago
Party member
Posts: 142
Joined: Fri Jun 14, 2013 10:41 am

Re: difference is???

Post by pielago »

ohh cool thanks..
so for library i can make one as well right???? to use it in the future?
User avatar
CRxTRDude
Prole
Posts: 41
Joined: Sun Dec 15, 2013 3:03 am
Location: Some island in the archipelago

Re: difference is???

Post by CRxTRDude »

pielago wrote:ohh cool thanks..
so for library i can make one as well right???? to use it in the future?
Well, you could. It's more organized to separate code that can be redundant to the entire game (eg. collisions, manipulation of stuff). There are many people who made such libraries for specific tasks that anyone can use and, with enough experience, you can as well.

Heck, I've been using other libraries for the thing I'm making right now, but if I see something to my liking (like attack calculations) and I can code something like that, I could make a library for those such calculations.

Objects are like libraries as well, only specific to your game. That can include your player and some obstacles.

(BTW, sorry that my other post seems confusing to you. I'll try to make it a little more easy for the eyes next time.)
~ CRxTRDude || Will be out of touch for a wee longer than expected. Will keep in touch with soon enough. Sorry bout that.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot], Semrush [Bot] and 10 guests