General > Developers Corner

Problem running my command

(1/1)

jvicu_2001:
Hi, I'm trying to get my command running but I got this error.

--- Code: ---[ERROR] addons/ulx/lua/ulx/modules/sh/mycommands.lua:42: 'end' expected (to close 'if' at line 37) near '<eof>'
--- End code ---
and this one.

--- Code: ---[ERROR] addons/ulx/lua/ulx/modules/sh/mycommands.lua:48: bad argument #2 to ULib.cmds.TranslateCommand (function expected)
           1. error - [C]:-1
            2. checkArg - addons/ulib/lua/ulib/shared/misc.lua:520
             3. instantiate - addons/ulib/lua/ulib/shared/commands.lua:1078
              4. ulxCommand - addons/ulib/lua/ulib/shared/misc.lua:843
               5. command - addons/ulx/lua/ulx/sh_base.lua:43
                6. unknown - addons/ulx/lua/ulx/modules/sh/mycommands.lua:48
--- End code ---

Why this is happening? here is the code I'm trying to run.

--- Code: ---function roll ( diceSides )
local calling_ply
local rollResult
if diceSides < 2 then
timer.Simple (1, function() ULib.tsay( "The number has to be above 1", true ) end)

elseif diceSides > 128 then
timer.Simple(1, function() ULib.tsay( "The number has to be under 129", true ) end)
end
ulx.fancyLogAdmin( calling_ply, true, "#A throw the dice" )
rollResult = math.random(2, diceSides)
ulx.fancyLogAdmin( calling_ply, true, "#A got ", rollResult, " of ", diceSides)
end

local roll = ulx.command( CATEGORY_NAME, "ulx roll", ulx.roll, "!roll" )
roll:addParam{ type=ULib.cmds.NumArg, min=2, max=128, default=6, hint="number", ULib.cmds.round }
roll:defaultAccess( ULib.ACCESS_ALL )
roll:help( "Rolls the dice." )
--- End code ---

Zmaster:
Try changing your function's name to ulx.roll
In your "local roll = ulx.command..." line you reference ulx.roll despite your function being named roll

Navigation

[0] Message Index

Go to full version