Page 1 of 1
difference is???
Posted: Sat Jan 04, 2014 5:02 am
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?
Re: difference is???
Posted: Sat Jan 04, 2014 5:25 am
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.
Re: difference is???
Posted: Sat Jan 04, 2014 5:35 am
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 : ????
Re: difference is???
Posted: Sat Jan 04, 2014 5:54 am
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.
Re: difference is???
Posted: Sat Jan 04, 2014 8:46 am
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).
Re: difference is???
Posted: Sat Jan 04, 2014 5:06 pm
by pielago
ohh cool thanks..
so for library i can make one as well right???? to use it in the future?
Re: difference is???
Posted: Sun Jan 05, 2014 3:42 pm
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.)