Error: ')' expected (to close... has been clarified :)

Place to get help with not working mods / modding interface.
Post Reply
DevilOwnpag
Manual Inserter
Manual Inserter
Posts: 4
Joined: Wed Apr 27, 2016 9:24 pm
Contact:

Error: ')' expected (to close... has been clarified :)

Post by DevilOwnpag »

Hello, i am new here, i was testing my first mod, i tried to create a "super lab" which would cost twice as a normal lab but is twice as effective, but on the way of some searching back and forth, i tried to find what the error was but i can't seem to find it, this error occurs in the control.lua file.

When loading a save it shows the following error: __SuperLab__/control.lua:29:')' expected (to close ')' at line 1) near 'end'

Everything has been explained and clarified, thanks for all your help, cheers :)
Last edited by DevilOwnpag on Wed Apr 27, 2016 10:26 pm, edited 4 times in total.

seronis
Fast Inserter
Fast Inserter
Posts: 225
Joined: Fri Mar 04, 2016 8:04 pm
Contact:

Re: Error: ')' expected (to close '(' at line 1) near 'end'

Post by seronis »

You forgot to show the error itself

DevilOwnpag
Manual Inserter
Manual Inserter
Posts: 4
Joined: Wed Apr 27, 2016 9:24 pm
Contact:

Re: Error: ')' expected (to close '(' at line 1) near 'end'

Post by DevilOwnpag »

Its up, sorry forgot :P

User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

Re: Error: ')' expected (to close '(' at line 1) near 'end'

Post by prg »

Now we'd need the control.lua instead of the data.lua.
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!

DevilOwnpag
Manual Inserter
Manual Inserter
Posts: 4
Joined: Wed Apr 27, 2016 9:24 pm
Contact:

Re: Error: ')' expected (to close '(' at line 1) near 'end'

Post by DevilOwnpag »

I put the wrong file...
here it is

Code: Select all

game.onevent(defines.events.ontick,function(event)
  if game.player.character and game.player.character.insert and game.player.character.insert.name == "superlab" and game.player.character.insert.getinventory(2).getitemcount("superlab") >= 1 and event.tick-glob.superlab >=180 then
    local superlab = game.findentities{{game.player.character.insert.position.x-5,game.player.character.insert.position.y-5},{game.player.character.insert.position.x+5,game.player.character.insert.position.y+5}}
    local drop = false
    local biters = 0
    for k,v in pairs(superlab) do
      if v.force.equals(game.forces.enemy) then
        biters = biters + 1
        if biters < 5 then
          drop = false
        end
      end
    end
  end
  if drop then
    glob.superlab=event.tick
	  for k,c in pairs(superlab) do
	    if v.force.equals(game.forces.enemy) then
		  if v.health then
		    v.die()
	      else
	        v.destroy()
	      end
        end
      end
      game.player.character.insert.getinventory(2).remove{name="superlab", count=1}
    end
  end
end)

seronis
Fast Inserter
Fast Inserter
Posts: 225
Joined: Fri Mar 04, 2016 8:04 pm
Contact:

Re: Error: ')' expected (to close '(' at line 1) near 'end'

Post by seronis »

isnt findentities a function? You're just placing a multidimensional table after it. ie you use:

Code: Select all

game.findentities{{ stuff },{stuff}}
instead of (what i think you're supposed to use there)

Code: Select all

game.findentities({stuff},{stuff})
Thats not your error though. I think your error is caused by mismatched number of 'end's. You have one too many. This would be much easier to see at a glance if you properly indented your code. Right now your ends dont line up with the statement that opened the code block.

daniel34
Global Moderator
Global Moderator
Posts: 2761
Joined: Thu Dec 25, 2014 7:30 am
Contact:

Re: Error: ')' expected (to close '(' at line 1) near 'end'

Post by daniel34 »

This looks like it was written for 0.11.x and doesn't work in newer versions.

In particular:
  • Events are now declared as script.on_event, not game.onevent
  • defines now use underscore (_) in their names
    It should be defines.events.on_tick instead of defines.events.ontick
  • function names now use underscore (_) in their names
    getinventory --> get_inventory
    getitemcount --> get_item_count
    findentities --> find_entities
  • glob has been renamed to global
  • game.player.character.insert is a function, not a property (that is a scripting error, would also be wrong in 0.11.x I believe)
  • game.findentities is now surface.find_entities, where you need to get a surface from existing entities first or iterate through all surfaces
I probably forgot some, but that should get you started. Also, game.player only works in singleplayer, you'll get an error when using it in multiplayer.

I recommend you use the Factorio API located at http://lua-api.factorio.com/0.12.31/
quick links: log file | graphical issues | wiki

DevilOwnpag
Manual Inserter
Manual Inserter
Posts: 4
Joined: Wed Apr 27, 2016 9:24 pm
Contact:

Re: Error: ')' expected (to close '(' at line 1) near 'end'

Post by DevilOwnpag »

Oh wow, like i said, i was still testing to see how things work and stuff, plus its my first mod, i did a little copy paste and edit things as i learn what they do, but anyways, i will try to look more into the coding itself, thanks for the help

keyboardhack
Filter Inserter
Filter Inserter
Posts: 478
Joined: Sat Aug 23, 2014 11:43 pm
Contact:

Re: Error: ')' expected (to close '(' at line 1) near 'end'

Post by keyboardhack »

DevilOwnpag wrote:I put the wrong file...
here it is

Code: Select all

game.onevent(defines.events.ontick,function(event)
  if game.player.character and game.player.character.insert and game.player.character.insert.name == "superlab" and game.player.character.insert.getinventory(2).getitemcount("superlab") >= 1 and event.tick-glob.superlab >=180 then
    local superlab = game.findentities{{game.player.character.insert.position.x-5,game.player.character.insert.position.y-5},{game.player.character.insert.position.x+5,game.player.character.insert.position.y+5}}
    local drop = false
    local biters = 0
    for k,v in pairs(superlab) do
      if v.force.equals(game.forces.enemy) then
        biters = biters + 1
        if biters < 5 then
          drop = false
        end
      end
    end
  end
  if drop then
    glob.superlab=event.tick
	  for k,c in pairs(superlab) do
	    if v.force.equals(game.forces.enemy) then
		  if v.health then
		    v.die()
	      else
	        v.destroy()
	      end
        end
      end
      game.player.character.insert.getinventory(2).remove{name="superlab", count=1}
    end
  end
end)

You have an end too much. Here the code is with an end removed. I noticed that you are using the old api names. Look here for the new names or just place a _ between every word so "getitemcount" becomes "get_item_count".

Code: Select all

game.onevent(defines.events.ontick,function(event)
	if game.player.character and game.player.character.insert and game.player.character.insert.name == "superlab" and game.player.character.insert.getinventory(2).getitemcount("superlab") >= 1 and event.tick-glob.superlab >=180 then
		local superlab = game.findentities{{game.player.character.insert.position.x-5,game.player.character.insert.position.y-5},{game.player.character.insert.position.x+5,game.player.character.insert.position.y+5}}
		local drop = false
		local biters = 0
		for k,v in pairs(superlab) do
			if v.force.equals(game.forces.enemy) then
			biters = biters + 1
				if biters < 5 then
					drop = false
				end
			end
		end
	end
	if drop then
		glob.superlab=event.tick
			for k,c in pairs(superlab) do
				if v.force.equals(game.forces.enemy) then
					if v.health then
					v.die()
					else
					v.destroy()
					end
				end
			end
		game.player.character.insert.getinventory(2).remove{name="superlab", count=1}
	end
end)
Waste of bytes : P

Post Reply

Return to “Modding help”