Lua Error

OK, here is the original code:



 concommand.Add( "amg_start", function( ply, cmd, args, string )
	if AMG.UseTimer then
		print( "AMG.UseTimer must be set to false." )
	else
		StartMinigame( args[1], args[2] )
	end
end)


And I got the error of:

[ERROR] addons/aminigames/lua/autorun/fcp_autorun.lua:20: attempt to call global ‘StartMinigame’ (a nil value)

  1. unknown - addons/aminigames/lua/autorun/fcp_autorun.lua:20
  2. unknown - lua/includes/modules/concommand.lua:69

So I tried getting help and I changed the code up a little and got:



concommand.Add( "amg_start", function( ply, cmd, args, string )
	if AMG.UseTimer then
		print( "AMG.UseTimer must be set to false." )
	else
		StartMinigame( ply, cmd )
	end
end)


And got the same error. So I’m really lost here. Would appreciate some help.

I also tried:



StartMinigame( ply, cmd, args )


Can you post the StartMinigame function?



function StartMinigame( type, length )

	print( "Starting minigame!" )

	if not table.HasValue( gameTypes, type ) then return end
	mgType = table.Random( AMG.miniGames )
	theType = type
	mgActive = true
	for k, v in pairs( player.GetAll() ) do
		v.Earned = 0
		net.Start( "NotifyPlayers" )
		net.Send( v )
	end


I’m guessing I would change the code to:



concommand.Add( "amg_start", function( ply, cmd, args, string )
	if AMG.UseTimer then
		print( "AMG.UseTimer must be set to false." )
	else
		StartMinigame( type, length )
	end
end)


???

StartMinigame is probably a serverside function you’re trying to call clientside with the command. Make sure the concommand.Add is serverside. Your first code of



 concommand.Add( "amg_start", function( ply, cmd, args, string )
    if AMG.UseTimer then
        print( "AMG.UseTimer must be set to false." )
    else
        StartMinigame( args[1], args[2] )
    end
end)


Should work.

The filename which contains the StartMinigame function is sv_amg.lua.
Would that mean it’s a serverside command?

Yes. Where is the concommand.Add located?. Also, you shouldn’t have changed the function arguments, they were fine before.

The concommand is in fcp_autorun.lua

Is that being called clientside or serverside? What is the location?

Pretty sure it’s serverside. The location is minigames/lua/autorun/fcp_autorun.lua

[editline]26th August 2014[/editline]

Not really getting any solutions…

So it isn’t serverside, but shared. Wrap the concommand in a SERVER if statement.

The lua file already has a server if statement at the top. Do I have to make a separate one for the concommand?

No, just make sure that the concommand is inside the if statement still. If that checks out, then the only other issue would be that the function is being created after the concommand.

Still not working… Here’e the code:



if SERVER then
 concommand.Add( "amg_start", function( ply, cmd, args, string )
    if AMG.UseTimer then
        print( "AMG.UseTimer must be set to false." )
    else
        StartMinigame( args[1], args[2] )
    end
end
end)


[editline]26th August 2014[/editline]

I get the same error when I type it in console but when I restart I get this error from it:

[ERROR] addons/aminigames/lua/autorun/fcp_autorun.lua:24: ‘)’ expected (to close ‘(’ at line 17) near ‘end’

  1. unknown - addons/aminigames/lua/autorun/fcp_autorun.lua:0

You don’t need the last ‘)’ on the end to close the if SERVER statement.

I removed the ‘)’ but the command doesn’t work anymore…
Unknown command: amg_start

Put it on the end above it, this is why you need indentation so you can see which end corresponds to each part.

Put it back.

It seems as if the error isn’t even generating from the given code, considering there’s nowhere that needs a ) to close off that isn’t already there. Maybe there’s an error earlier on in the file

If I put it back I get the error of:

[ERROR] addons/aminigames/lua/autorun/fcp_autorun.lua:24: ‘)’ expected (to close ‘(’ at line 17) near ‘end’

  1. unknown - addons/aminigames/lua/autorun/fcp_autorun.lua:0

If I don’t have it, the command doesn’t work.
I’m really consused.
Here’s my current code:



	if SERVER then

 concommand.Add( "amg_start", function( ply, cmd, args, string )
    if AMG.UseTimer then
        print( "AMG.UseTimer must be set to false." )
    else
        StartMinigame( args[1], args[2] )
    end
		end
	end
end


Now you’re missing a ) at the end for the concommand.Add

What you posted earlier, you only had to move the bracket up one line.

[lua]if SERVER then
concommand.Add( “amg_start”, function( ply, cmd, args, string )
if AMG.UseTimer then
print( “AMG.UseTimer must be set to false.” )
else
StartMinigame( args[1], args[2] )
end
end)
end[/lua]