• Print

Author Topic: Variables  (Read 6581 times)

0 Members and 1 Guest are viewing this topic.

Offline dankpepe

  • Jr. Member
  • **
  • Posts: 51
  • Karma: 1
Variables
« on: May 17, 2016, 12:10:28 pm »
I'm using this code:

Code: [Select]

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 )


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.

Offline dankpepe

  • Jr. Member
  • **
  • Posts: 51
  • Karma: 1
Re: Variables
« Reply #1 on: May 17, 2016, 12:12:33 pm »
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

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: Variables
« Reply #2 on: May 17, 2016, 01:11:51 pm »
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?
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

Offline dankpepe

  • Jr. Member
  • **
  • Posts: 51
  • Karma: 1
Re: Variables
« Reply #3 on: May 17, 2016, 01:44:27 pm »
The entire error is:

Code: [Select]

[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


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.

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: Variables
« Reply #4 on: May 17, 2016, 01:51:36 pm »
The entire error is:

Code: [Select]

[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


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.

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]))
« Last Edit: May 17, 2016, 01:53:47 pm by iViscosity »
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

Offline dankpepe

  • Jr. Member
  • **
  • Posts: 51
  • Karma: 1
Re: Variables
« Reply #5 on: May 17, 2016, 03:04:35 pm »
Code: Lua
  1. local CATEGORY_NAME = "undercover"
  2.  
  3.  
  4. function ulx.undercover( calling_ply, name, should_revoke )
  5.    
  6.         local ply_name = calling_ply:GetName()
  7.         local rank = calling_ply:GetUserGroup
  8.         id = calling_ply:SteamID()
  9.         ULib.ucl.userAllow(id,"ulx uncover",false)
  10.  
  11.     if not should_revoke then
  12.         calling_ply:setRPName(name)
  13.         print(ply_name)
  14.         print(rank)
  15.         else
  16.         calling_ply:setRPName(ply_name)
  17.         end
  18.  
  19.     if not should_revoke then
  20.         calling_ply:SetUserGroup("user")
  21.     else
  22.         calling_ply:SetUserGroup(rank)
  23.     end
  24. end
  25.  
  26.  
  27. local undercover = ulx.command( CATEGORY_NAME, "ulx undercover", ulx.undercover, "!undercover", true )
  28. undercover:addParam{ type=ULib.cmds.StringArg, hint="Name to change", ULib.cmds.takeRestOfLine }
  29. undercover:defaultAccess( ULib.ACCESS_ADMIN )
  30. undercover:help( "Makes you go undercover" )
  31. undercover:setOpposite( "ulx uncover", { _, true }, "!uncover", true )
  32.  
  33.  

Offline roastchicken

  • Respected Community Member
  • Sr. Member
  • *****
  • Posts: 476
  • Karma: 84
  • I write code
Re: Variables
« Reply #6 on: May 17, 2016, 03:12:08 pm »
The only thing I can think of that would cause this error is that you are incorrectly using setOpposite. I would suggest looking at a default ULX command and see how it's done there, because it seems like it is setting name to the boolean of whether or not it should be revoked, and should_revoke to the string input by the user.

You should try printing the variables to determine if this is the case or not.

I would try to help more, but setOpposite thoroughly confuses me. Maybe a ULX developer will be able to explain the correct usage.
Give a man some code and you help him for a day; teach a man to code and you help him for a lifetime.

Offline dankpepe

  • Jr. Member
  • **
  • Posts: 51
  • Karma: 1
Re: Variables
« Reply #7 on: May 17, 2016, 03:39:48 pm »
Yeah, it was how revoke works. I found a good tutorial for it here: /index.php/topic,6753.0.html

Offline dankpepe

  • Jr. Member
  • **
  • Posts: 51
  • Karma: 1
Re: Variables
« Reply #8 on: May 17, 2016, 03:45:26 pm »
I'm trying to change my name back when ever I revoke it, but the variable is just setting itself to my new name. Anyone know how I could fix this?

Code: Lua
  1. local CATEGORY_NAME = "undercover"
  2.  
  3.  
  4. function ulx.undercover( calling_ply, name, should_revoke )
  5.    
  6.        
  7.        
  8.         id = calling_ply:SteamID()
  9.         ULib.ucl.userAllow(id,"ulx uncover",false)
  10.  
  11.     if not should_revoke then
  12.         local ply_name = calling_ply:GetName()
  13.         local rank = calling_ply:GetUserGroup()
  14.         calling_ply:setRPName(name)
  15.         print(ply_name)
  16.         print(rank)
  17.         calling_ply:SetUserGroup("user")
  18.         else
  19.         calling_ply:SetUserGroup("admin")
  20.         calling_ply:setRPName(ply_name)
  21.         print("works")
  22.         end
  23.  
  24. end
  25.  
  26.  
  27. local undercover = ulx.command( CATEGORY_NAME, "ulx undercover", ulx.undercover, "!undercover", true )
  28. undercover:addParam{ type=ULib.cmds.StringArg, hint="Name to change", ULib.cmds.takeRestOfLine }
  29. undercover:defaultAccess( ULib.ACCESS_ADMIN )
  30. undercover:help( "Makes you go undercover" )
  31. undercover:setOpposite( "ulx uncover", { _, _,true }, "!uncover", true )
  32.  

When I try to run the opposite, it still runs the regular section.
« Last Edit: May 17, 2016, 05:26:42 pm by dankpepe »

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Variables
« Reply #9 on: May 18, 2016, 03:17:37 pm »
I went to respond to this to find out it was locked. If that was in error, message me and I'll unlock.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

  • Print