How do i fix this syntax error i have?

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
Memer
Prole
Posts: 1
Joined: Thu Sep 01, 2022 10:18 pm

How do i fix this syntax error i have?

Post 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
User avatar
GVovkiv
Party member
Posts: 686
Joined: Fri Jan 15, 2021 7:29 am

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

Post by GVovkiv »

So, you give us code snippet with 24 lines, but error happens on line 63?
Do you provided full source or what?
User avatar
ReFreezed
Party member
Posts: 612
Joined: Sun Oct 25, 2015 11:32 pm
Location: Sweden
Contact:

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

Post 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.)
Tools: Hot Particles, LuaPreprocess, InputField, (more) Games: Momento Temporis
"If each mistake being made is a new one, then progress is being made."
Andlac028
Party member
Posts: 174
Joined: Fri Dec 14, 2018 2:27 pm
Location: Slovakia

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

Post by Andlac028 »

Also for better readibility, you can put your code to [code] [/code] tags in the forums
User avatar
pgimeno
Party member
Posts: 3674
Joined: Sun Oct 18, 2015 2:58 pm

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

Post by pgimeno »

edit: oops, missed the replies
Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests