"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
pgimeno
Party member
Posts: 3638
Joined: Sun Oct 18, 2015 2:58 pm

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

Post by pgimeno »

Chad64 wrote: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:

Code: Select all

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. ;)
(Added

Code: Select all

 tags around your code for clarity and as required by the forum rules. Please add them yourself next time).

Something's missing. That snippet is far less than 41 lines, yet the error says it happens in line 41.
User avatar
pgimeno
Party member
Posts: 3638
Joined: Sun Oct 18, 2015 2:58 pm

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

Post by pgimeno »

Vimm wrote: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?
Create a random angle with 2*math.pi*love.math.random() (that's a random number from 0 to twice pi, which is a whole circle in radians).

Then use the cosine and the sine of the angle times your speed (in pixels/s), to determine the velocity vector to apply each frame. And each frame, multiply it by dt and add the result to the position.

Something like:

Code: Select all

local vx, vy     -- velocity x, y
local speed = 5  -- 5 pixels/s

function love.load()
  local angle = 2*math.pi*love.math.random()
  vx = math.cos(angle)*speed
  vy = math.sin(angle)*speed
end

function love.update(dt)
  -- add vx*dt and vy*dt to the position x and y respectively
end
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 »

pgimeno wrote:
Vimm wrote: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?
Create a random angle with 2*math.pi*love.math.random() (that's a random number from 0 to twice pi, which is a whole circle in radians).

Then use the cosine and the sine of the angle times your speed (in pixels/s), to determine the velocity vector to apply each frame. And each frame, multiply it by dt and add the result to the position.

Something like:

Code: Select all

local vx, vy     -- velocity x, y
local speed = 5  -- 5 pixels/s

function love.load()
  local angle = 2*math.pi*love.math.random()
  vx = math.cos(angle)*speed
  vy = math.sin(angle)*speed
end

function love.update(dt)
  -- add vx*dt and vy*dt to the position x and y respectively
end
[Error] attempt to perform arithmetic on global 'vx'(a nil value) :/
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 »

Something's missing. That snippet is far less than 41 lines, yet the error says it happens in line 41.
im sorry, it was line 4. i must've typed too fast :awesome:

Ill do that code thingy soon, thanks for telling me!
EDIT:
Also that code was just an example in love.touch.getPosition wiki. So I'm not sure if it's the codes problem..

EDIT #2:
I found a fix! i used love.mouse to act as a touch. Sadly that makes it not multitouch.. But i don't need to worry about that right now! :D

The problem with ipairs on love android still lasts tho. And that needs an answer or fix.
i love dinosaurs :3
User avatar
pgimeno
Party member
Posts: 3638
Joined: Sun Oct 18, 2015 2:58 pm

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

Post by pgimeno »

Chad64 wrote:The problem with ipairs on love android still lasts tho. And that needs an answer or fix.
That's very weird. That's a very straightforward construct. Make sure no strange characters have slipped into the code.
User avatar
pgimeno
Party member
Posts: 3638
Joined: Sun Oct 18, 2015 2:58 pm

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

Post by pgimeno »

Vimm wrote:[Error] attempt to perform arithmetic on global 'vx'(a nil value) :/
My example is for you to see what I meant. You'll need to adapt it to your requirements.
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 »

pgimeno wrote: That's very weird. That's a very straightforward construct. Make sure no strange characters have slipped into the code.
Well, i did just copy the code from an example at love.touch.getPosition.. so it's not my fault ✌
i love dinosaurs :3
User avatar
s-ol
Party member
Posts: 1077
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 »

Chad64 wrote:
pgimeno wrote: That's very weird. That's a very straightforward construct. Make sure no strange characters have slipped into the code.
Well, i did just copy the code from an example at love.touch.getPosition.. so it's not my fault ✌
except I did just copy & paste that myself and it works... double check?

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
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 »

s-ol wrote:except I did just copy & paste that myself and it works... double check?
Still doesn't work. Reverted everything back, main.lua, pasted code, blahblahblah. What platform are you testing it on? it might be just my devices problem too tho..
i love dinosaurs :3
User avatar
s-ol
Party member
Posts: 1077
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 »

Chad64 wrote:
s-ol wrote:except I did just copy & paste that myself and it works... double check?
Still doesn't work. Reverted everything back, main.lua, pasted code, blahblahblah. What platform are you testing it on? it might be just my devices problem too tho..
if it's syntax error the platform doesn't (should not) matter. All platforms and recent versions embed the same luajit engine. I tried on my linux laptop and got no syntax error, which means that while I can't test the touching part here there is no syntax errors (either the whole file can be parsed or none of it).

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
Locked

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], Semrush [Bot] and 0 guests