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
Error: ')' expected (to close... has been clarified :)
-
- Manual Inserter
- Posts: 4
- Joined: Wed Apr 27, 2016 9:24 pm
- Contact:
Error: ')' expected (to close... has been clarified :)
Last edited by DevilOwnpag on Wed Apr 27, 2016 10:26 pm, edited 4 times in total.
Re: Error: ')' expected (to close '(' at line 1) near 'end'
You forgot to show the error itself
-
- Manual Inserter
- Posts: 4
- Joined: Wed Apr 27, 2016 9:24 pm
- Contact:
Re: Error: ')' expected (to close '(' at line 1) near 'end'
Its up, sorry forgot
Re: Error: ')' expected (to close '(' at line 1) near 'end'
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!
-
- Manual Inserter
- Posts: 4
- Joined: Wed Apr 27, 2016 9:24 pm
- Contact:
Re: Error: ')' expected (to close '(' at line 1) near 'end'
I put the wrong file...
here it is
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)
Re: Error: ')' expected (to close '(' at line 1) near 'end'
isnt findentities a function? You're just placing a multidimensional table after it. ie you use:
instead of (what i think you're supposed to use there)
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.
Code: Select all
game.findentities{{ stuff },{stuff}}
Code: Select all
game.findentities({stuff},{stuff})
Re: Error: ')' expected (to close '(' at line 1) near 'end'
This looks like it was written for 0.11.x and doesn't work in newer versions.
In particular:
I recommend you use the Factorio API located at http://lua-api.factorio.com/0.12.31/
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 recommend you use the Factorio API located at http://lua-api.factorio.com/0.12.31/
-
- Manual Inserter
- Posts: 4
- Joined: Wed Apr 27, 2016 9:24 pm
- Contact:
Re: Error: ')' expected (to close '(' at line 1) near 'end'
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
-
- Filter Inserter
- Posts: 478
- Joined: Sat Aug 23, 2014 11:43 pm
- Contact:
Re: Error: ')' expected (to close '(' at line 1) near 'end'
DevilOwnpag wrote:I put the wrong file...
here it isCode: 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