Quick Questions- Entity Code, ConCommand on use

in the init.lua of my food_ent entity I have this:
[lua]function ENT:Use(activator, caller)
self:Remove()
if activator:IsPlayer() == true then
activator:ConCommand(“eatfood”, 100, 10)
end
end[/lua]

In the cl_init.lua of my gamemode code I have this:
[lua]concommand.Add(“eatfood”, function(ply, command, args, str)
print(table.ToString(args))
local FoodValue = args[1]
local RegenTime = args[2]
local previousmaxenergy = currentmaxenergy
print(“regenerating " …FoodValue… " energy over " …RegenTime… " seconds”)
if table.Count(args) == 2 then
timer.Create(“regeneratemaxenergy”, 1, 0, function()
if table.Count(vars)-1 < MaxNumOfBars then
energybar = energybar+(FoodValue/RegenTime)
print(previousmaxenergy)
print(FoodValue)
if excessenergy > 0 then
drawexcess = 1
else
drawexcess = 0
end
if excessenergy >= 100 then
excessenergy = 0
excessbar = nil
vars[#vars+1] = #vars+1
currentmaxenergy = currentmaxenergy+tempenergybar
highestvar = table.Count(vars)
print("currentmaxenergy " …currentmaxenergy)
end
if energybar >= 100 then
excessenergy = excessenergy+(energybar-100)
energybar= 100
print("excessenergy = " …excessenergy)
currentmaxenergy = (table.Count(vars)*100)+excessenergy
print("currentmaxenergy " …currentmaxenergy)
end
if currentmaxenergy >= previousmaxenergy+tonumber(FoodValue) or currentmaxenergy >= totalenergy then
print("bigger than " …previousmaxenergy+tonumber(FoodValue))
print("bigger than " …totalenergy)
if excessenergy > 0 then
drawexcess = 1
else
drawexcess = 0
end
if excessenergy >= 100 then
excessenergy = 0
excessbar = nil
vars[#vars+1] = #vars+1
currentmaxenergy = currentmaxenergy+tempenergybar
highestvar = table.Count(vars)
print("currentmaxenergy " …currentmaxenergy)
end
if energybar >= 100 then
excessenergy = excessenergy+(energybar-100)
energybar= 100
print("excessenergy = " …excessenergy)
currentmaxenergy = (table.Count(vars)*100)+excessenergy
print("currentmaxenergy " …currentmaxenergy)
end
if excessenergy >= 100 then
timer.Create(“convertexcessbars”, 0.1, 0, function()
if excessenergy >= 100 then
excessenergy = 0
excessbar = nil
vars[#vars+1] = #vars+1
currentmaxenergy = currentmaxenergy+tempenergybar
highestvar = table.Count(vars)
print("currentmaxenergy " …currentmaxenergy)
else
timer.Stop(“convertexcessbars”)
end
end )
end
timer.Stop(“regeneratemaxenergy”)
print(“stopping”)
end
end
end )
end
end )[/lua]

the files for this entity are located in garrysmod/lua/entities/food_ent. I can spawn the entity just fine, but when I press the use key on it, I get this error:



[ERROR] gamemodes/custom/gamemode/cl_init.lua:296: attempt to concatenate local 'RegenTime' (a nil value)
  1. unknown - gamemodes/custom/gamemode/cl_init.lua:296
   2. unknown - lua/includes/modules/concommand.lua:69



line 296 is this:
[lua] print(“regenerating " …FoodValue… " energy over " …RegenTime… " seconds”)[/lua]

My first question is how do I fix this error? My second question is how can I get the entity to function (to appear in game) by putting it in my gamemode folder, rather than in the gmod lua folder?

This is my first attempt at entity code, as until now I’ve mostly stuck with creating gamemodes.

If args[2] is nil you be concatenating a nil value. Put the print line inside the if statement, that way it won’t try and concatenate a nil value.

If I understand your second question correctly: put the entity folder in yourgamemodename/entities/entities

When i move the print line it stops the error message from appearing, but it still doesn’t pass the second arguement, it just does nothing. How would i be able to get the concommand to pass the third variable in the activator:ConCommand() function (10)?

Sorry - didn’t see that.

Player.ConCommand doesn’t take arguments then pass them through the cc, you’re thinking of RunConsoleCommand(command, arg1, arg2, etc…)