Page 1 of 1

How do i fix this syntax error i have?

Posted: Thu Sep 01, 2022 10:27 pm
by Memer
I am trying to make a clicks per second test application and im having a syntax error with my code so could anyone help me??

function love.load()
local buttons = {}
local texts = {}

table.insert(buttons, newButton(
"Click Me!",
function()
print("Button.... Yes...")
end))
end --- Loads in the button so it can be drawn

function love.draw()
width = 140
height = 64
local ww = love.graphics.getWidth()
local wh = love.graphics.getHeight()
b_width = ww - (1/3)
b_height = 200
love.graphics.rectangle(
"fill",
(ww * 0.75) - (b_width * 0.85)
(wh * 0.6) - (b_height * 0.5))
end
end --- Draws the button

The error is

Syntax error: main.lua:62: ambiguous syntax (function call x new statement) near '('

Traceback

[love "callbacks.lua"]:228: in function 'handler'
[C]: at 0x7ffa46de31d0
[C]: in function 'require'
[C]: in function 'xpcall'
[C]: in function 'xpcall'

also just to know im new to love2d so i still dont really understand the code too much

Re: How do i fix this syntax error i have?

Posted: Fri Sep 02, 2022 3:10 pm
by GVovkiv
So, you give us code snippet with 24 lines, but error happens on line 63?
Do you provided full source or what?

Re: How do i fix this syntax error i have?

Posted: Fri Sep 02, 2022 5:15 pm
by ReFreezed
You're missing a comma to separate the arguments at the end of this line:

Code: Select all

(ww * 0.75) - (b_width * 0.85)
The error happens because Lua doesn't know if the following is what you actually meant (if we append the next line):

Code: Select all

(ww * 0.75) - (b_width * 0.85)(wh * 0.6) - (b_height * 0.5))
-- This looks like a call: (whatever)(wh * 0.6)
(Also, this is specifically a Lua error, not a LÖVE related error, just to be clear.)

Re: How do i fix this syntax error i have?

Posted: Fri Sep 02, 2022 6:16 pm
by Andlac028
Also for better readibility, you can put your code to [code] [/code] tags in the forums

Re: How do i fix this syntax error i have?

Posted: Sat Sep 03, 2022 1:22 am
by pgimeno
edit: oops, missed the replies