Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

rmcode wrote:...

Any ideas?
Your second pattern is all wrong.

You are probably looking for "^%s*([%g%s]*%g)%s*=%s*(.+)$": Code: Select all ^ -- start of the line %s* -- any leading space there might be ( -- capture [%g%s]* -- zero or more spaces or characters %g -- a last character (so the space before the '=' doesn't get captured ) %s* -- all the space up to the '=' %s* -- any space preceding the value (.+)$     -- the rest of the value (and force that there is something there)


s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
baby:hurt(me)
end

rmcode
Party member
Posts: 454
Joined: Tue Jul 15, 2014 12:04 pm
Location: Germany
Contact:

Ah yes that works. Thanks S0lll0s. The second pattern worked in Javascript and I tried to "blindly" port it to Lua.

zorg
Party member
Posts: 2804
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

rmcode wrote:(...) worked in Javascript and I tried to "blindly" port it to Lua.
I once ported code that created a song from js to lua... figuring out the math discrepancies was hell, and while it sounds decent i'm pretty sure i still messed it up somewhere
(If you're wondering, it was this; a cover of chaos theory by conspiracy:

Code: Select all

w=t>>9,k=32,m=2048,a=1-t/m%1,d=(14*t*t^t)%m*a,y=[3,3,4.7,2][p=w/k&3]*t/4,h="IQNNNN!!]]!Q!IW]WQNN??!!W]WQNNN?".charCodeAt(w/2&15|p/3<<4)/33*t-t,s=y*.98%80+y%80+(w>>7&&a*((5*t%m*a&128)*(0x53232323>>w/4&1)+(d&127)*(0xa444c444>>w/4&1)*1.5+(d*w&1)+(h%k+h*1.99%k+h*.49%k+h*.97%k-64)*(4-a-a))),s*s>>14?127:s
)[/size]
Me and my stuff True 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.

Prole
Posts: 19
Joined: Sun Mar 13, 2016 3:23 am

I'm really confused about math.random and love.math.random

Whenever I use something like this love.math.random(20,300)
I only get the first argument. Why is that?

Thanks friends

zorg
Party member
Posts: 2804
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

XxHAMADEHxX wrote:I only get the first argument.
What exactly do you mean by this? that the love.math.random(20,300) call returns 20 always, or that you only understand what the first argument is supposed to mean?

In any case, love.math.random has 3 "forms":

Code: Select all

love.math.random() -- returns a (real) number between 0 and 1, inclusive, uniformly distributed.
love.math.random(max) -- returns a (whole) number between 0 and max, inclusive, uniformly distributed.
love.math.random(min,max) -- returns a (whole) number between min and max, inclusive, uniformly distributed.
-- and if you want any other type, like, a real number between min and max, you might do it like this:
function myrandom(min, max)
min, max = math.min(min, max), math.max(min, max)
return -min + love.math.random() * (min+max)
end
I will guess i don't need to explain what real and whole numbers mean, inclusive is that it can return the numbers you gave it as limits (or 0 and 1 in the first case), and it being uniformly distributed just means there's an equal chance to get any value.

Just like lua's math.random, except löve's has more consistent output across platforms, and lua's is not seeded when the program starts up, so you're bound to get the same output always.
Me and my stuff True 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.

Davidobot
Party member
Posts: 1150
Joined: Sat Mar 31, 2012 5:18 am
Location: Game-Dev. Land
Contact:

Whenever I use something like this love.math.random(20,300)
I only get the first argument. Why is that?

Thanks friends
You will get the same result every time you run it.

Like:
Run #1, first time the function is called: 20
Run #1, second time the function is called: 64
Run #2, first time the function is called: 20
Run #2, second time the function is called: 64

To change this, do love.math.randomseed(os.time()) before you call love.math.random
My library:
LovelyMoon

Check out my current project:
Raycaster

Oh hey, I have a website now!

zorg
Party member
Posts: 2804
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

But the default love.run already seeds love.math.random, only lua's math.random is not seeded. At least, to my knowledge...
Me and my stuff True 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.

Nixola
Inner party member
Posts: 1940
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

That is correct. It only seeds it before love.load though, so you may want to only call love.math.random when you're sure it's seeded.
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
li = love.image
lg = love.graphics

eliasfrost
Prole
Posts: 2
Joined: Sun Nov 17, 2013 7:42 pm

Taehl wrote:
eliasfrost wrote:Hi! I'm currently getting into programming games again and I'm trying to make a breakout clone. I'm having trouble with calculating the reflecting angle when the ball bounces on a surface.
...
I've searched on google but the answers I've gotten seems like overkill. calculating velocity components with the normal of a surface or something, I'm not a physics graduate so I have no idea what they are talking about and finding comprehensible resources is hard.

Or maybe there's an even simpler way of doing things and I'm just on the wrong track? If someone feel like they can help me a bit please do.
As long as you don't have angled surfaces or anything fancy like that, there's a simple age-old trick you can use (heck, the original Breakout probably even did this). Whenever your ball hits something, check if it hit vertically or horizontally, and simply multiply your y-velocity or x-velocity (respectively) by -1.

So it your ball is moving right and touches a wall on the right, all it needs to do is travel left at the same speed now. Hence the *-1 of your x-velocity.
Thanks, I will try this out.

airstruck
Party member
Posts: 650
Joined: Thu Jun 04, 2015 7:11 pm
Location: Not being time thief.