Page 48 of 91

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

Posted: Sat Feb 13, 2016 6:26 pm
by Ranguna259
bobbyjones wrote:Here is an example of an ffi binding. It will result in a faster binding and should be easier because libcrypto is part of openssl so it should be available everywhere. And if it's not it will have binaries for everywhere.
https://github.com/LPGhatguy/luajit-request

Edit: just in case it was unclear (I usually do make unclear posts) the example was not an example of libcrypto but just of ffi bindings in general.
That's out of my league, I'll just wait for the Devs to implement some kind of SSL API. Thanks for all the help :nyu:

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

Posted: Sat Feb 13, 2016 7:19 pm
by bobbyjones
You could try out luasec. I know people had some success with that. Iirc luasec is what will be added to 0.11.0 so you wouldn't have any migration issues if you use luasec.

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

Posted: Sat Feb 13, 2016 7:47 pm
by Ranguna259
bobbyjones wrote:You could try out luasec. I know people had some success with that. Iirc luasec is what will be added to 0.11.0 so you wouldn't have any migration issues if you use luasec.
I'll look into luasec, maybe I'll be able to find the binaries somewhere.

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

Posted: Sat Feb 13, 2016 9:25 pm
by binaryeye
Evine wrote:Ah now I see the mistake you made. When you're using shaders the color that is set with love.graphics.setColor() and the pixel color of an image is two different arguments passed into the shader. "vec4 color" being the love.graphics.setColor() color and "Image texture" being the image pixels.
Thanks so much! It works perfectly now.

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

Posted: Sun Feb 14, 2016 2:03 am
by unixfreak
Simple question. I've tried a few things, but unaware how to solve it;

I have some pickups dropped by enemies as they die, and want them to float in a random direction. So i have these added as part of a table entry.

Code: Select all

		xvel = math.random(-70,70),
		yvel = math.random(-70,70),
The problem is, i don't want the pickups to move at (for example); xvel = 1, yvel = -1. I don't want the smaller values.

Ideally i want to only get the values between, -70 to -20 and 20 to 70.
I tried looking at math.max and math.min, but can't seem to find a way.

I could always use a function like

Code: Select all

function getrandom()
    local rand = math.random(-70,70)
    if rand > -20 and rand < 20 then
        getrandom()
    end
    return rand
end
Although i'm wondering if there is a shorthand way to do this using math.random itself?

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

Posted: Sun Feb 14, 2016 2:18 am
by tuupakku
unixfreak wrote:Simple question. I've tried a few things, but unaware how to solve it;

I have some pickups dropped by enemies as they die, and want them to float in a random direction. So i have these added as part of a table entry.

Code: Select all

		xvel = math.random(-70,70),
		yvel = math.random(-70,70),
The problem is, i don't want the pickups to move at (for example); xvel = 1, yvel = -1. I don't want the smaller values.

Ideally i want to only get the values between, -70 to -20 and 20 to 70.
I tried looking at math.max and math.min, but can't seem to find a way.

I could always use a function like

Code: Select all

function getrandom()
    local rand = math.random(-70,70)
    if rand > -20 and rand < 20 then
        getrandom()
    end
    return rand
end
Although i'm wondering if there is a shorthand way to do this using math.random itself?
I'm afraid not. Another thing you could do is call math.random(20,70) then make a condition based on another math.random() where you multiply the result by -1.

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

Posted: Sun Feb 14, 2016 2:44 am
by unixfreak
I'm afraid not. Another thing you could do is call math.random(20,70) then make a condition based on another math.random() where you multiply the result by -1.
I had tried something similar to that. I guess just using a function to call itself again is probably the simplest way though. Thanks though.

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

Posted: Sun Feb 14, 2016 3:32 am
by bobbyjones
unixfreak wrote:
I'm afraid not. Another thing you could do is call math.random(20,70) then make a condition based on another math.random() where you multiply the result by -1.
I had tried something similar to that. I guess just using a function to call itself again is probably the simplest way though. Thanks though.
It is the simpler way but also potentially slow way. There is a great potential for that function to call itself recursively more than 3 to 5 times. And if you use it often(I assume you do not) then it could be a real performance hit. The solution offered by tuupaku won't impact your performance as much. If you do decide to continue to use your function at least use love.math.random() love.math.random is more random which should result in less "looping".

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

Posted: Sun Feb 14, 2016 5:17 am
by s-ol
untested:

Code: Select all

function clampabs(val, min)
  if val == 0 then val = min end
  local abs = math.abs(val)
  local s = val/abs
  return math.max(min, abs) * s
end

xvel = clampabs(math.random(-70, 70), 20)
clampabs should take a number val and a minimum value min and push everything between ]-min, min[ out to the closer one of those two.

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

Posted: Sun Feb 14, 2016 10:08 am
by pgimeno
That would give an uneven distribution where 20 and -20 are much more likely than any other number. There are many possible solutions. Apart from the ones already given, it's possible to do it in just one draw with something like this:

Code: Select all

function rand_abs(min, max)
  local rnd = love.math.random(min + min - max - 1, max)
  return rnd >= min and rnd or rnd - min - min + 1
end
That will return a number between -max and -min or between min and max. For example:

Code: Select all

xvel = rand_abs(20, 70)
yvel = rand_abs(20, 70)