Page 55 of 91
Re: "Questions that don't deserve their own thread" thread
Posted: Mon Mar 14, 2016 8:24 pm
by s-ol
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)
Re: "Questions that don't deserve their own thread" thread
Posted: Mon Mar 14, 2016 9:25 pm
by rmcode
Ah yes that works. Thanks S0lll0s. The second pattern worked in Javascript and I tried to "blindly" port it to Lua.
Re: "Questions that don't deserve their own thread" thread
Posted: Mon Mar 14, 2016 10:54 pm
by zorg
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]
Re: "Questions that don't deserve their own thread" thread
Posted: Wed Mar 16, 2016 5:22 am
by XxHAMADEHxX
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
Re: "Questions that don't deserve their own thread" thread
Posted: Wed Mar 16, 2016 12:46 pm
by zorg
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.
Re: "Questions that don't deserve their own thread" thread
Posted: Wed Mar 16, 2016 12:47 pm
by Davidobot
XxHAMADEHxX wrote: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
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
Re: "Questions that don't deserve their own thread" thread
Posted: Wed Mar 16, 2016 1:15 pm
by zorg
But the default love.run already seeds love.math.random, only lua's math.random is not seeded. At least, to my knowledge...
Re: "Questions that don't deserve their own thread" thread
Posted: Wed Mar 16, 2016 1:16 pm
by Nixola
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.
Re: "Questions that don't deserve their own thread" thread
Posted: Wed Mar 16, 2016 7:01 pm
by eliasfrost
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.
Re: "Questions that don't deserve their own thread" thread
Posted: Wed Mar 16, 2016 7:33 pm
by airstruck
zorg wrote:lua's math.random is not seeded
It's pre-seeded with 0 in every implementation I've seen (and that can be changed with math.randomseed, of course). The manual doesn't make any note of this, though. But yeah, it's not automatically seeded with a timestamp or anything like that.