Page 58 of 91

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

Posted: Mon Mar 21, 2016 1:26 am
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.

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

Posted: Mon Mar 21, 2016 1:36 am
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

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

Posted: Mon Mar 21, 2016 2:05 am
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) :/

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

Posted: Mon Mar 21, 2016 2:30 am
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.

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

Posted: Mon Mar 21, 2016 3:45 pm
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.

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

Posted: Mon Mar 21, 2016 3:46 pm
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.

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

Posted: Tue Mar 22, 2016 1:37 am
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 ✌

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

Posted: Tue Mar 22, 2016 2:25 am
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?

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

Posted: Tue Mar 22, 2016 4:44 am
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..

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

Posted: Tue Mar 22, 2016 10:48 am
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).