General > Developers Corner

Variables

(1/2) > >>

dankpepe:
I'm using this code:


--- Code: ---
function ulx.undercover( calling_ply, name, should_revoke )
   
local ply_name = calling_ply:GetName()
local rank = calling_ply:GetUserGroup()
id = calling_ply:SteamID()
ULib.ucl.userAllow(id,"ulx uncover",false)

    if not should_revoke then
    calling_ply:setRPName(name)
    else
    calling_ply:setRPName(ply_name)
    end

    if not should_revoke then
    calling_ply:SetUserGroup("user")
    else
    calling_ply:SetUserGroup(rank)
    end
end


local undercover = ulx.command( CATEGORY_NAME, "ulx undercover", ulx.undercover, "!undercover", true )
undercover:addParam{ type=ULib.cmds.StringArg, hint="Name to change", ULib.cmds.takeRestOfLine }
undercover:defaultAccess( ULib.ACCESS_ADMIN )
undercover:help( "Makes you go undercover" )
undercover:setOpposite( "ulx uncover", { _, true }, "!uncover", true )


--- End code ---

Starting it works fine, but when I try to revoke I get an error. The error is 17 lines in a batch file so I'm not gonna type the whole thing out unless you need it. The first part says: [ERROR] gamemodes/darkrp/gamemode/modules/base/sv_data.lua:226: bad argument #1 to 'len' (string expected, got boolean)

I know what this means, it's trying to set my name to true or false, but I don't know why. In the code I used 1 =, not 2, so it should be setting the variable.

dankpepe:
I tried adding print(ply_name) and print(rank) after  if not should_revoke then calling_ply:setRPName(name), and it printed the data fine. I don't know why this isn't working

iViscosity:
Is that the paste of the entire code/the entire error? You just said the first part of the error said that, what about the rest?

dankpepe:
The entire error is:


--- Code: ---
[ERROR] gamemodes/gamemode/modules/base/sv_data.lua:226: bad argument #1 to 'len' (string expected, got boolean)
1. len - [C]:-1
2. storeRPName - gamemodes/darkrp/gamemode/modules/base/sv_data.lua:226
3.callback - gamemode/darkrp/gamemode/modules/base/sv_entityvars.lua:207
4.callback - gamemodes/darkrp/gamemode/modules/base/sv_data.lua:235
5. query - gamemode/darkrp/gamemode/libraries/mysqlite/mysqlite.lua:302
6.retrieveRPNames - gamemodes/darkrp/gamemode/modules/base/sv_data.lua:234
7.setRPName - gamemodes/darkrp/gamemode/modules/base/sv_entityvars.lua:191
8. call - addons/danker_commands/lua/ulx/modules/sh/undercover.lua:12
9.__fn - addons/ulib/lua/ulib/shared/commands.lua:943
10. unknown - addons/ulib/lua/ulib/shared/commands.lua:1296
11. Run - lua/includes/modules/comcommand.lua:54
12. unknown - addons/ulib/lua/ulib/shared/commands.lua:1211
13. unknown - lua/includes/modules/concommand.1


--- End code ---

Also worth noting, when I change back, which doesn't work, it says [my name] changed their name to true, but it stays the same.

iViscosity:

--- Quote from: dankpepe on May 17, 2016, 01:44:27 PM ---The entire error is:


--- Code: ---
[ERROR] gamemodes/gamemode/modules/base/sv_data.lua:226: bad argument #1 to 'len' (string expected, got boolean)
1. len - [C]:-1
2. storeRPName - gamemodes/darkrp/gamemode/modules/base/sv_data.lua:226
3.callback - gamemode/darkrp/gamemode/modules/base/sv_entityvars.lua:207
4.callback - gamemodes/darkrp/gamemode/modules/base/sv_data.lua:235
5. query - gamemode/darkrp/gamemode/libraries/mysqlite/mysqlite.lua:302
6.retrieveRPNames - gamemodes/darkrp/gamemode/modules/base/sv_data.lua:234
7.setRPName - gamemodes/darkrp/gamemode/modules/base/sv_entityvars.lua:191
[b]8. call - addons/danker_commands/lua/ulx/modules/sh/undercover.lua:12[/b] [b][i][u]here[/u][/i][/b]
9.__fn - addons/ulib/lua/ulib/shared/commands.lua:943
10. unknown - addons/ulib/lua/ulib/shared/commands.lua:1296
11. Run - lua/includes/modules/comcommand.lua:54
12. unknown - addons/ulib/lua/ulib/shared/commands.lua:1211
13. unknown - lua/includes/modules/concommand.1


--- End code ---

Also worth noting, when I change back, which doesn't work, it says [my name] changed their name to true, but it stays the same.

--- End quote ---

Number 8 is where it's being referenced to your code. Can you paste line 12 of your code? It's kind of difficult to tell which line is which when you have it pasted like that. (Next time, add =lua after the "code" in tag ([c ode=lua]))

Navigation

[0] Message Index

[#] Next page

Go to full version