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:
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.
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.
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.
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
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.
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) :/
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
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!
The problem with ipairs on love android still lasts tho. And that needs an answer or fix.
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..
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).