"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
master both
Party member
Posts: 262
Joined: Tue Nov 08, 2011 12:39 am
Location: Chile

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

Post by master both »

Kibita wrote:I didn't get the part where I must update my android project for add ad support:
Adding google-play-services_lib without an IDE
For adding google-play-services_lib to your project you will first need to download it from the android-sdk by going to the "Android Sdk Manager" on "extras" and checking on "Google Play Services" then you can find the library folder on android_sdk/extras/google/google_play_services/libproject/google-play-services_lib. Now you have to paste it next to the project folder and execute "android update project -p 'dir/to/google-play-services_lib' " and you're done!
What I did was copy the google-play-services_lib folder into the love_android folder and use the command line, it worked, but when I do a ant debug it shows BUILD FAILED "/../google-play-services_lib resolve to path with no project file for project directory to my love_android project"

What should I do?
Try putting google-play-services_lib right outside of the love_android folder.
User avatar
pgimeno
Party member
Posts: 3674
Joined: Sun Oct 18, 2015 2:58 pm

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

Post by pgimeno »

XxHAMADEHxX wrote:

Code: Select all

<snip>
function love.load()



end
<snip>
Strange I did put love.math.random after love.load() and I still have to set a seed. Sorry for the caps I just put it so that it is easier to see.
Whether you put it before or after love.load doesn't matter. It should be inside love.load for it to work.

Maybe this helps you understanding. After conf.lua and the modules are loaded, LÖVE does this:
- Load and execute main.lua.
- Call love.run.
The default love.run in turn does the following:
- Initialize the random seed.
- Call love.load if defined.
- Initialize a couple more things and start the main loop (processing events and calling update / draw in succession).

So, unless you put the code inside love.load, the seed won't be initialized. Whether you put it before or after defining love.load is irrelevant; the important part is that it's executed after setting the seed, and for that purpose putting it inside love.load is ideal.

(I think S0lll0s meant love.load rather than love.run)
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 »

Skeiks wrote:
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.
Thanks for the reply! I'm working on a crafting system to check if ingredients match a recipe. Just been trying out the logic so far using strings (and sorting the tables before comparing), but I may eventually create some sort of inventory objects instead and your suggestion for the N level search will probably be very helpful with that!
User avatar
Phlimy
Prole
Posts: 7
Joined: Sat Mar 19, 2016 6:02 pm
Contact:

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

Post by Phlimy »

Very quick question:
Can someone explain to me why the code in this "if" is executed?
data[2] is equal to "position", but data[1] IS equal to id.
though I would like it not to execute only if data[1] is different than id...
https://i.gyazo.com/0b1581b3d1a54d45fcb ... 292c79.png

Thanks!
Don't panic and never forget your towel.
User avatar
pgimeno
Party member
Posts: 3674
Joined: Sun Oct 18, 2015 2:58 pm

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

Post by pgimeno »

Hard to say without access to debugging your program. A possible explanation is that they look equal but they aren't (e.g. if they are strings, one may have a space at the end, or if they are numbers with decimals, they may differ on a non-visible decimal). This works as expected for me (prints "condition false"):

Code: Select all

local id = "abc"
local data = {"abc", "position"}
if data[2] == "position" and data[1] ~= id then
  print("condition true")
else
  print("condition false")
end
Please paste the code inline rather than linking to an image next time.
User avatar
Phlimy
Prole
Posts: 7
Joined: Sat Mar 19, 2016 6:02 pm
Contact:

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

Post by Phlimy »

Thank you! Yes, I was actually comparing a string with a number :S
I will paste my code next time so it is more clear! :)
Don't panic and never forget your towel.
User avatar
Chad64
Prole
Posts: 5
Joined: Sun Mar 20, 2016 2:53 pm

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

Post by Chad64 »

Im using the android port of löve, and i have a problem with at least debugging simple things by touching the screen. i literally copied and pasted this onto main.lua:

function love.draw()
local touches = love.touch.getTouches()
 
for i, id in ipairs(touches) do
local x, y = love.touch.getPosition(id)
love.graphics.circle("fill", x, y, 20)
end
end

.. and i keep getting:

Error

Syntax error: main.lua:41: '=' expected near 'for'

reply me if u want the tracebacks, kinda tired to write em today.


I am new to löve but has an idea how to use any lua. trust me, i have made a windows screensaver like thingy but instead of the logo bouncing around, its a mario. ;)
i love dinosaurs :3
User avatar
unixfreak
Citizen
Posts: 82
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 »

I'll put this here as i'm pretty sure the solution is quite simple, however i am having sever issues of brain fog right now and can't seem to figure this out. Basically, how can i find the mouse position relative to a canvas internal coordinates?

This should show the issue:
package.love
(1.67 KiB) Downloaded 132 times
The most relevant part is probably in the collision check:

Code: Select all

if collision:check(love.mouse.getX(),love.mouse.getY(),0,0, tile.x,tile.y,tile.w,tile.h ) then
			love.graphics.setColor(200,190,180,255)
else
			love.graphics.setColor(100,100,100,255)
end
Basically, the grid is drawn to a canvas (which might be moved about) so the cursor collision is all over the place. :huh:
User avatar
Kibita
Prole
Posts: 31
Joined: Tue Dec 29, 2015 7:46 pm

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

Post by Kibita »

master both wrote:
Kibita wrote:I didn't get the part where I must update my android project for add ad support:
Try putting google-play-services_lib right outside of the love_android folder.
It worked! Thank you!
Another question: when will love2d-android support the leaderboard from Google Play?
User avatar
Vimm
Party member
Posts: 113
Joined: Wed Mar 16, 2016 8:14 pm

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

Post by Vimm »

How do I set an angle to an object? Basically I have a rectangle that, when the game starts, I want to make move in a random direction, how would I accomplish this?
Locked

Who is online

Users browsing this forum: No registered users and 2 guests