Syntax error in code, stumped.

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.
Post Reply
PickledFerret
Prole
Posts: 1
Joined: Thu May 30, 2013 11:54 am

Syntax error in code, stumped.

Post by PickledFerret »

Hey, I'm pretty much brand new to using LOVE2D and LUA so my code is pretty horrible and all over the place. So the error that I get is:
Error
Syntax error: main.lua:101: 'then' expected near ','

Traceback
[C]: ?
[C]: in function 'require'
[C]: in function 'xpcall'
Here is some of my code:

Code: Select all

function love.load()
	genA, genB = math.random(1, 1028), math.random(1, 768)
	genTLX, genTLY = genA - 100, genB - 100
	genTMX, genTMY = genA, genB - 100
	genTRX, genTRY = genA + 100, genB - 100
	genMLX, genMLY = genA - 100, genB
	genMRX, genMRY = genA + 100, genB
	genBLX, genBLY = genA - 100, genB + 100
	genBMX, genBMY = genA, genB + 100
	genBRX, genBRY = genA + 100, genB + 100


	tiles.floor2 = {}
	genX = math.random(1, 3)
	genY = math.random(1, 3)
	if genX, genY = (1, 1) then   -- This is the affected line. Line 101.
		genTLX, genTLY = genTLX, genTLY
	elseif genX, genY == (1, 2) then
		genTMX, genTMY = genTMX, genTMY
	elseif genX, genY == (1, 3) then
		genTRX, genTRY = genTRX, genTRY
	elseif genX, genY == (2, 1) then
		genMLX, genMLY = genMLX, genMLY
	elseif genX, genY == (2, 2) then
		genMRX, genMRY = genMRX, genMRY
	elseif genX, genY == (2, 3) then
		genBLX, genBLY = genBLX, genBLY
	elseif genX, genY == (3, 1) then
		genBMX, genBMR = genBMX, genBMY
	elseif genX, genY == (3, 2) then
		genBRX, genBRY = genBRX, genBRY
	elseif genX, genY == (3, 3) then
		genZ = math.random(1, 8)
		if genZ == (1) then
		genTLX, genTLY = genTLX, genTLY
		elseif genZ == (2) then
		genTMX, genTMY = genTMX, genTMY
		elseif genZ == (3) then
		genTRX, genTRY = genTRX, genTRY
		elseif genZ == (4) then
		genMLX, genMLY = genMLX, genMLY
		elseif genZ == (5) then
		genMRX, genMRY = genMRX, genMRY
		elseif genZ == (6) then
		genBLX, genBLY = genBLX, genBLY
		elseif genZ == (7) then
		genBMX, genBMR = genBMX, genBMY
		elseif genZ == (8) then
		genBRX, genBRY = genBRX, genBRY
		end
	end
end
In my code, line #101 is: " if genX, genY = (1, 1) then "

I would very much appreciate it if somebody could help me fix this.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Syntax error in code, stumped.

Post by Robin »

Welcome!

Lua has no tuples. That's why you can't do genX, genY = (1, 1). Instead do genX == 1 and genY == 1.

Lua does have multiple assignment, but it's a bit of a vague thing that doesn't generalize to equality comparison.

EDIT: also, it seems like most of the code in the if-statements don't do anything, being mostly equivalent to a = a.
Help us help you: attach a .love.
Post Reply

Who is online

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