"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
User avatar
Ranguna259
Party member
Posts: 911
Joined: Tue Jun 18, 2013 10:58 pm
Location: I'm right next to you

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

Post by Ranguna259 » Sat Feb 13, 2016 6:26 pm

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:
LoveDebug- A library that will help you debug your game with an on-screen fully interactive lua console, you can even do code hotswapping :D

Check out my twitter.

bobbyjones
Party member
Posts: 712
Joined: Sat Apr 26, 2014 7:46 pm

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

Post by bobbyjones » Sat Feb 13, 2016 7:19 pm

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.
Check out my most recent medium post, please give feedback.
Link

User avatar
Ranguna259
Party member
Posts: 911
Joined: Tue Jun 18, 2013 10:58 pm
Location: I'm right next to you

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

Post by Ranguna259 » Sat Feb 13, 2016 7:47 pm

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.
LoveDebug- A library that will help you debug your game with an on-screen fully interactive lua console, you can even do code hotswapping :D

Check out my twitter.

binaryeye
Prole
Posts: 8
Joined: Wed Feb 03, 2016 2:58 pm

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

Post by binaryeye » Sat Feb 13, 2016 9:25 pm

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.

User avatar
unixfreak
Citizen
Posts: 72
Joined: Thu Oct 15, 2015 6:25 am
Location: Bristol, UK
Contact:

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

Post by unixfreak » Sun Feb 14, 2016 2:03 am

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?

User avatar
tuupakku
Prole
Posts: 21
Joined: Fri Feb 12, 2016 12:12 pm

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

Post by tuupakku » Sun Feb 14, 2016 2:18 am

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.

User avatar
unixfreak
Citizen
Posts: 72
Joined: Thu Oct 15, 2015 6:25 am
Location: Bristol, UK
Contact:

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

Post by unixfreak » Sun Feb 14, 2016 2:44 am

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.

bobbyjones
Party member
Posts: 712
Joined: Sat Apr 26, 2014 7:46 pm

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

Post by bobbyjones » Sun Feb 14, 2016 3:32 am

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".
Check out my most recent medium post, please give feedback.
Link

User avatar
s-ol
Party member
Posts: 1076
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

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

Post by s-ol » Sun Feb 14, 2016 5:17 am

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.

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

User avatar
pgimeno
Party member
Posts: 1629
Joined: Sun Oct 18, 2015 2:58 pm

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

Post by pgimeno » Sun Feb 14, 2016 10:08 am

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)

Locked

Who is online

Users browsing this forum: No registered users and 7 guests