love.audio.play(my_sound) vs my_sound:play()

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
sphyrth
Party member
Posts: 260
Joined: Mon Jul 07, 2014 11:04 am
Contact:

love.audio.play(my_sound) vs my_sound:play()

Post by sphyrth »

love.audio.play(my_sound)
my_sound:play()
-----
Alright, too much curiosity is striking me with these two codes:
Are there significant differences between them?
Are they used according to coders' preferences, or are they used according to their purpose?
Are there reasons why one is superior to the other, or are they both valid to use at the same time?
User avatar
veethree
Inner party member
Posts: 877
Joined: Sat Dec 10, 2011 7:18 pm

Re: love.audio.play(my_sound) vs my_sound:play()

Post by veethree »

Are there significant differences between them?
No.
Are they used according to coders' preferences, or are they used according to their purpose?
Coders preferences.
Are there reasons why one is superior to the other, or are they both valid to use at the same time?
Neither is superior, Both valid at the same time.

It's just a matter of preference, I personally prefer my_sound:play(), I find it more pleasing aesthetically.
User avatar
Positive07
Party member
Posts: 1014
Joined: Sun Aug 12, 2012 4:34 pm
Location: Argentina

Re: love.audio.play(my_sound) vs my_sound:play()

Post by Positive07 »

text:len()
string.len(text)

Yeah the same
for i, person in ipairs(everybody) do
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(github.com/pablomayobre)
User avatar
slime
Solid Snayke
Posts: 3166
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: love.audio.play(my_sound) vs my_sound:play()

Post by slime »

Positive07 wrote:text:len()
string.len(text)

Yeah the same
The length operator (#text) should probably be preferred for getting the length of a string - the official online edition of the Programming in Lua book was written for Lua 5.0 which didn't have the length operator, so it doesn't mention it unfortunately.
sphyrth
Party member
Posts: 260
Joined: Mon Jul 07, 2014 11:04 am
Contact:

Re: love.audio.play(my_sound) vs my_sound:play()

Post by sphyrth »

:awesome:
Thanks for the info guys. Now I can move on.
User avatar
Positive07
Party member
Posts: 1014
Joined: Sun Aug 12, 2012 4:34 pm
Location: Argentina

Re: love.audio.play(my_sound) vs my_sound:play()

Post by Positive07 »

slime wrote:
Positive07 wrote:text:len()
string.len(text)

Yeah the same
The length operator (#text) should probably be preferred for getting the length of a string - the official online edition of the Programming in Lua book was written for Lua 5.0 which didn't have the length operator, so it doesn't mention it unfortunately.
I should have used byte hahaha yeah I commonly use the length operator it is shorter... didnt know it was preferred, is it faster?
for i, person in ipairs(everybody) do
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(github.com/pablomayobre)
User avatar
Xgoff
Party member
Posts: 211
Joined: Fri Nov 19, 2010 4:20 am

Re: love.audio.play(my_sound) vs my_sound:play()

Post by Xgoff »

Positive07 wrote:
slime wrote:
Positive07 wrote:text:len()
string.len(text)

Yeah the same
The length operator (#text) should probably be preferred for getting the length of a string - the official online edition of the Programming in Lua book was written for Lua 5.0 which didn't have the length operator, so it doesn't mention it unfortunately.
I should have used byte hahaha yeah I commonly use the length operator it is shorter... didnt know it was preferred, is it faster?
technically, yes, it is faster

but the real reason it's preferred is because they added specific syntax for it
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 4 guests