) expected to close ( near end, but it's already closed it?

Status
Not open for further replies.

SSG3

Oh, THAT Youtuber...
yeah... HUGE problem with an LUA script in my wad... an error occurs, but there's no error?
Code:
addHook("ThinkFrame", do
	for player in players.iterate
		if player.mo and player.mo.skin == "metroidsonic" then
			if not (player.charflags & SF_SUPER)
				player.charflags = $1 + SF_SUPER
			end
			
			if player.screwjumps == nil
				player.screwjumps = 0
			end
			
			if player.superfly == nil
				player.superfly = 0
			end
			
			if not (player.cmd.buttons & BT_CUSTOM2) then
				player.screwjumpready = true
				player.screwjumping = false
			elseif player.screwjumpready then
				player.screwjumping = true
				player.screwjumpready = false
			else
				player.screwjumping = false
			end
 
			if player.canscrew ~= 2 and player.jumping
			and (player.screwjumps ~= 5) then
				player.canscrew = 1
			end
			
			if P_IsObjectOnGround(player.mo) and (player.mo.eflags & MFE_ONGROUND)
				player.canscrew = 0
				player.isscrewing = 0
				player.screwjumps = 0
				player.stillscrewing = false

			end
 
			if not (P_IsObjectOnGround(player.mo))
			and (player.canscrew ~= 2)
			and not (player.canscrew == 0)
			and (player.isscrewing ~= 2)
			and (player.screwjumps ~= 5)
			and (player.screwjumping)
			and not (player.powers[pw_super])
			and not (player.spectator)
			and not (player.pflags & PF_NIGHTSMODE)
			and not (player.mo.tracer and player.mo.tracer.type == MT_TUBEWAYPOINT)
			and not (player.mo.state == S_PLAY_DIE) then
				if (player.mo.eflags & MFE_UNDERWATER)
					P_SetObjectMomZ(player.mo, 5*FRACUNIT, false)
				else
					P_SetObjectMomZ(player.mo, 10*FRACUNIT, false)
					end
				S_StartSound(player.mo, sfx_fre800)
					player.screwjumps = $1 + 1
				player.isscrewing = 1
				if player.screwjumps >= 5
					player.canscrew = 2
					player.isscrewing = 2
				end
				player.stillscrewing = true
			end
			
			if (player.stillscrewing == true)
				P_SpawnGhostMobj(player.mo)
			end
			
			if (player.screwjumping)
			and (player.powers[pw_super])
			and not (player.spectator)
			and not (player.pflags & PF_NIGHTSMODE)
			and not (player.mo.tracer and player.mo.tracer.type == MT_TUBEWAYPOINT)
			and not (player.mo.state == S_PLAY_DIE) then
				if player.superfly == 0
					player.superfly = 1
					player.mo.flags = $1|MF_NOGRAVITY|MF_SLIDEME
				else
					player.superfly = 0
					player.mo.flags = $1 & ~(MF_NOGRAVITY|MF_SLIDEME)
				end
		
			if not (player.cmd.buttons & BT_CUSTOM1) then
				player.shootmissile = true
				player.shootingmissile = false
			elseif player.shootmissile then
				player.shootingmissile = true
				player.shootmissile = false
			else
				player.shootingmissile = false
			end
			
			if not (player.cmd.buttons & BT_CUSTOM3) then
				player.shootlaser = true
				player.shootinglaser = false
			elseif player.shootlaser then
				player.shootinglaser = true
				player.shootlaser = false
			else
				player.shootinglaser = false
			end
 
			if player.shootingmissile
			and not (player.mo.state == S_PLAY_DIE)
			and not (player.spectator)
			and (player.mo.health > 1)
			and not (player.pflags & PF_NIGHTSMODE) then
				P_GivePlayerRings(player, -1)
				local spawnedmissile = P_SPMAngle(player.mo, MT_JETTBULLET, player.mo.angle, 1)
				S_StartSound(player.mo, sfx_s3k4d)
				if not (spawnedmissile == nil)
					spawnedmissile.flags2 = $1 + MF2_SUPERFIRE
				else
				end
			end
			
			if player.shootinglaser
			and not (player.mo.state == S_PLAY_DIE)
			and not (player.spectator)
			and (player.mo.health > 5)
			and not (player.pflags & PF_NIGHTSMODE) then
				P_GivePlayerRings(player, -5)
				local laser = P_SPMAngle(player.mo, MT_TORPEDO, player.mo.angle, 1)
				S_StartSound(player.mo, sfx_rlaunc)
				if not (laser == nil)
					laser.flags2 = $1 + (MF2_SUPERFIRE|MF2_RAILRING)
				else
				end
			end
		end
	end
end
end
end)
... returns in SRB2 "WARNING: METROIDSV5.WAD/LUA_METR: 137: ')' expected to close '(' at line 4 near end"

If anyone can help fix this, I'll credit them in the LUA script. (The addhook starts at line 4, if you were wondering)
 
The code block starting with "if (player.screwjumping)" doesn't have an "end" for itself, and you put TWO unnecessary "end"s at the bottom.

By the way, there are times when you go "else" and then immediately put "end". You don't need to put an else for everything.
 
Last edited:
Thanks. It works perfectly now. Also, I changed the else end to "else return end", just in case there was any problems...
 
You do not need to do "else return end", and in fact that could cause more unwanted behaviour. In the case where you use "end" instead, and the if statement's conditions are not met, it will skip to the next conditional statement, command or function in the script. "return" should only be used if you want to break out of a function entirely. Because of your implicitly defined function, it will bring your entire hook to a halt for the rest of the frame. This is undesirable, as you have code after the first "else end" which would otherwise be skipped.

Also, your indentation standard for the screwjump handler portion of the code isn't very good. Indents are not supposed to be random; they are designed to improve code readability, and represent how sections of your code are grouped at a glance. If you add an indent for each conditional statement (if, for, etcetera), and remove it for every end (as the section of the code at the end of the code you've provided shows) that will go a long way towards making it easier to sort out problems with your code.
 
Last edited:
"return" should only be used if you want to break out of a function entirely.

Whoops... I've amended that now. Thanks for pointing that out. (I'm new-ish to LUA, so any mistake corrections like what you stated above will help me to not do that again.)
 
Status
Not open for further replies.

Who is viewing this thread (Total: 1, Members: 0, Guests: 1)

Back
Top