"Questions that don't deserve their own thread" thread

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.
Locked
PrussianBlue
Prole
Posts: 2
Joined: Tue Mar 08, 2016 4:03 pm

Re: "Questions that don't deserve their own thread" thread

Post by PrussianBlue » Tue Mar 08, 2016 11:36 pm

Alright, thank you very much for the help. I tried using ... inplace of arg but unpack threw an error. I realize now that it's because ... is a tuple instead of a table - in other words, it is already unpacked.

User avatar
Skeiks
Citizen
Posts: 51
Joined: Wed Jan 28, 2015 1:51 pm

Re: "Questions that don't deserve their own thread" thread

Post by Skeiks » Wed Mar 09, 2016 2:29 pm

How much overhead does sending externs to a shader have? I'm working on a distortion effect for my game and I was sending a texture map to my shader almost every frame to do the effect. I didn't experience any slowdown, but I don't know if that's a bad practice or not.

Snowbadger
Prole
Posts: 9
Joined: Thu Jun 25, 2015 11:33 pm

Re: "Questions that don't deserve their own thread" thread

Post by Snowbadger » Fri Mar 11, 2016 8:42 am

Edit: Nevermind on that one. I finally figured out a fix. :awesome:

Another question, though: If I were to compare arrays of strings, would there be a more efficient way than concatenating both arrays and comparing those resulting strings?

For example, if I had something like this to populate an empty array with user input in order to compare it with an existing array.

Code: Select all

array = {	"apple", "banana", "pear"	}
userArray = {}

-- extra code here to insert user input into userArray

string1 = table.concat(array, " ")
string2 = table.concat(userArray, " ")

if string1 == string2 then
-- do something
Last edited by Snowbadger on Fri Mar 11, 2016 11:46 pm, edited 1 time in total.

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

Re: "Questions that don't deserve their own thread" thread

Post by eliasfrost » Fri Mar 11, 2016 8:51 pm

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.

What I'm currently doing is:

Code: Select all

ball.rads = ball.angle * math.pi / 180

ball.x = ball.x + math.cos(ball.rads)*(ball.speed*dt)
ball.y = ball.y + math.sin(ball.rads)*(ball.speed*dt)

if checkCollision(ball, v) then
	ball.angle = 180 - ball.angle
end
It works but only for vertical surfaces. can someone explain or point me towards the info I need to get this to work? 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. :)

User avatar
Skeiks
Citizen
Posts: 51
Joined: Wed Jan 28, 2015 1:51 pm

Re: "Questions that don't deserve their own thread" thread

Post by Skeiks » Sat Mar 12, 2016 2:56 am

Snowbadger wrote:Edit: Nevermind on that one. I finally figured out a fix. :awesome:

Another question, though: If I were to compare arrays of strings, would there be a more efficient way than concatenating both arrays and comparing those resulting strings?

For example, if I had something like this to populate an empty array with user input in order to compare it with an existing array.

Code: Select all

array = {	"apple", "banana", "pear"	}
userArray = {}

-- extra code here to insert user input into userArray

string1 = table.concat(array, " ")
string2 = table.concat(userArray, " ")

if string1 == string2 then
-- do something

Maybe concatenating the arrays wouldn't work 100% since tables could be in different orders. I dunno if concat handles sorting. If the strings are always going to be the same though I think that's actually a pretty efficient way of handling it.

It really depends on what you're comparing the tables for though. In some instances you may just have to do a 1 to 1 n^2 compare. In other instances, if you know the keys of a table, and the keys are irrelevant, set the keys to equal the string value and you could just look for keys. That way you could do N level search. Let's say you have a table array = {banana = "banana", apple = "apple", pear = "pear"}. You could do:

Code: Select all

match = true
array = {banana = "banana", apple = "apple", pear = "pear"}
userArray = {}
foreach key, value in userArray do
	if array[key] then
		continue;
	end
	match = false;
	break;
end
This won't work if you need the keys to have information about the data they contain, but it is a pretty fast way to handle comparing tables I think. Maybe someone else could give a more complete answer.

User avatar
Taehl
Dreaming in associative arrays
Posts: 1024
Joined: Mon Jan 11, 2010 5:07 am
Location: CA, USA
Contact:

Re: "Questions that don't deserve their own thread" thread

Post by Taehl » Mon Mar 14, 2016 12:38 am

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.
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.

User avatar
childonline
Prole
Posts: 15
Joined: Thu Dec 30, 2010 11:06 am

Re: "Questions that don't deserve their own thread" thread

Post by childonline » Mon Mar 14, 2016 5:01 pm

Hi!

How am I supposed to canvas:clear() since 0.10.1 ? Is there a generally fast good-practice I don't know about?

Thanks!

User avatar
Skeiks
Citizen
Posts: 51
Joined: Wed Jan 28, 2015 1:51 pm

Re: "Questions that don't deserve their own thread" thread

Post by Skeiks » Mon Mar 14, 2016 5:37 pm

childonline wrote:Hi!

How am I supposed to canvas:clear() since 0.10.1 ? Is there a generally fast good-practice I don't know about?

Thanks!
Set the canvas, then use love.graphics:clear()

Code: Select all

love.graphics.setCanvas(canvas);
love.graphics.clear();
love.graphics.setCanvas()

User avatar
childonline
Prole
Posts: 15
Joined: Thu Dec 30, 2010 11:06 am

Re: "Questions that don't deserve their own thread" thread

Post by childonline » Mon Mar 14, 2016 5:44 pm

Skeiks wrote: Set the canvas, then use love.graphics:clear()

Code: Select all

love.graphics.setCanvas(canvas);
love.graphics.clear();
love.graphics.setCanvas()
Thanks!

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

Re: "Questions that don't deserve their own thread" thread

Post by rmcode » Mon Mar 14, 2016 7:47 pm

I can't figure out how to extend

Code: Select all

^([%g]+)%s+=%s+(.+)
to also match strings with whitespace.

E.g.:

Code: Select all

FooBar = lalalalala -- works
Foo Bar = lalalalala -- doesn't work
I know you can wrap repeated captures in another capture in some languages, but this doesn't seem to work in lua:

Code: Select all

(([%g]+[%s]*)+)%s+=%s+(.+)
Any ideas?

Locked

Who is online

Users browsing this forum: mizza, Nelvin and 14 guests