• Print

Author Topic: attempt to index global 'ULib' (a nil value) help please  (Read 14862 times)

0 Members and 1 Guest are viewing this topic.

Offline atomic-cruncher

  • Newbie
  • *
  • Posts: 7
  • Karma: 0
attempt to index global 'ULib' (a nil value) help please
« on: January 12, 2014, 02:34:13 am »
Someone told me this execute command: ULib.ucl.addUser( ply:SteamID(), nil, nil, "donator" ) but i get this error when running server[ERROR] lua/autorun/donationkeys.lua:15: attempt to index global 'ULib' (a nil value)1. unknown - lua/autorun/donationkeys.lua:15 ulx and ulib is installed anyways so i don't know the clue

Offline Neku

  • Hero Member
  • *****
  • Posts: 549
  • Karma: 27
Re: attempt to index global 'ULib' (a nil value) help please
« Reply #1 on: January 12, 2014, 02:59:26 am »
Code: [Select]
ULib.ucl.addUser( ply:SteamID(), nil, nil, "donator" )
What're those "nil"s doing there?
Out of the Garry's Mod business.

Offline atomic-cruncher

  • Newbie
  • *
  • Posts: 7
  • Karma: 0
Re: attempt to index global 'ULib' (a nil value) help please
« Reply #2 on: January 12, 2014, 03:21:33 am »
Code: [Select]
ULib.ucl.addUser( ply:SteamID(), nil, nil, "donator" )
What're those "nil"s doing there?
something for allowed and refused but I don't need those so I just fill in nil

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: attempt to index global 'ULib' (a nil value) help please
« Reply #3 on: January 12, 2014, 07:08:05 am »
Are you calling module() in donationkeys.lua on an earlier line?

Or are you calling ULib from the global scope, before it has a chance to load?
Experiencing God's grace one day at a time.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: attempt to index global 'ULib' (a nil value) help please
« Reply #4 on: January 12, 2014, 10:24:48 am »
Easiest quickest way to make sure ULib has loaded first..imo, is not use autorun folder for Ulib needed code.
Use addons\<your_addon>\lua\ulib\modules\<your file>

As the \addons\ulib\lua\ulib\modules\what_is_this.txt states
Quote
This folder is similar to the lua/autorun folder, except all scripts in this folder are loaded after ULib.
Scripts in this directory are shared ( loaded both server and client side ).
Scripts in the client and server sub-folders are loaded only on the client and server respectively.

Same for ULX (if using ulx functions), but replace ulib with ulx in the addon folder path.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline atomic-cruncher

  • Newbie
  • *
  • Posts: 7
  • Karma: 0
Re: attempt to index global 'ULib' (a nil value) help please
« Reply #5 on: January 12, 2014, 01:25:11 pm »
ERROR:

[ULIB] Loading SHARED module: donationkeys.lua

[ERROR] addons/ulib/lua/ulib/modules/donationkeys.lua:15: attempt to index global 'ply' (a nil value)
1. unknown - addons/ulib/lua/ulib/modules/donationkeys.lua:15
2. include - [C]:-1
3. unknown - addons/ulib/lua/ulib/init.lua:68
4. include - [C]:-1
5. unknown - addons/ulib/lua/autorun/ulib_init.lua:3

[ULIB] Loading SHARED module: ulx_init.lua

using this: ULib.ucl.addUser( ply:SteamID(), nil, nil, "donator" )

EDIT: also when trying this execute command: RunConsoleCommand( "ulx", "adduserid", "" .. ply:SteamID() .. "", "vip")
getting same thnig
« Last Edit: January 12, 2014, 01:26:44 pm by atomic-cruncher »

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: attempt to index global 'ULib' (a nil value) help please
« Reply #6 on: January 12, 2014, 04:19:12 pm »
Errors are pretty obvious.
During startup, you have the Ulib command running outside of a function...or running before a player is defined in ply.
During run of the command, your not passing the command the right info.
Attach your file for review.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline atomic-cruncher

  • Newbie
  • *
  • Posts: 7
  • Karma: 0
Re: attempt to index global 'ULib' (a nil value) help please
« Reply #7 on: January 13, 2014, 06:41:37 am »
Errors are pretty obvious.
During startup, you have the Ulib command running outside of a function...or running before a player is defined in ply.
During run of the command, your not passing the command the right info.
Attach your file for review.
It's attached in the spoiler
Code: Lua
  1. local DONATIONTYPES = {}
  2.  
  3. if SERVER then
  4.  
  5.         DONATIONTYPES["1"] = function(ply)
  6.                 --code to apply reward for donation of type 1
  7.                 ply:PrintMessage(HUD_PRINTTALK, "You received donation type 1")
  8.         end
  9.  
  10.         DONATIONTYPES["2"] = function(ply)
  11.                 --code to apply reward for donation of type 2
  12.                 ply:PrintMessage(HUD_PRINTTALK, "You received donation type 2")
  13.         end
  14.  
  15.         ULib.ucl.addUser( ply:SteamID(), nil, nil, "donator" )["3"] = function(ply)
  16.                 --code to apply reward for donation of type 3
  17.                 ply:PrintMessage(HUD_PRINTTALK, "You received Donator!")
  18.         end
  19.        
  20.         DONATIONTYPES["4"] = function(ply)
  21.                 --code to apply reward for donation of type 3
  22.                 ply:PrintMessage(HUD_PRINTTALK, "You received donation type 3")
  23.         end
  24.  
  25. end
  26.  
  27.  
  28.  
  29.  
  30.  
  31. if CLIENT then
  32.  
  33.         function jaooeDonationKeyEnter()
  34.                 local frame = vgui.Create("DFrame")
  35.                 frame:SetPos(ScrW()/2-200,ScrH()/2-100)
  36.                 frame:SetSize(400,100)
  37.                 frame:SetTitle("Enter Donation Key")
  38.                 frame:SetVisible(true)
  39.                 frame:ShowCloseButton(true)
  40.                 frame:MakePopup()
  41.                 frame.Paint = function()
  42.                         draw.RoundedBox(4,0,0,frame:GetWide(),frame:GetTall(),Color(0,0,0,170))
  43.                 end
  44.                
  45.                 local label = vgui.Create("DLabel", frame)
  46.                 label:SetText("Enter your key and press enter: ")
  47.                 label:SetPos(10,40)
  48.                 label:SizeToContents()
  49.                
  50.                 local textbox = vgui.Create("DTextEntry", frame)
  51.                 textbox:SetPos(15+label:GetWide(),40)
  52.                 textbox:SetSize(200,20)
  53.                 textbox:SetEnterAllowed(true)
  54.                 textbox.OnEnter = function()
  55.                         if(textbox:GetValue() == "") then return end
  56.                         net.Start("cl_sendDonationKey")
  57.                                 net.WriteString(textbox:GetValue())
  58.                         net.SendToServer()
  59.                 end
  60.         end
  61.        
  62.         concommand.Add("enterdonationkey",jaooeDonationKeyEnter)
  63.  
  64. end
  65.  
  66. if SERVER then
  67.         require("tmysql4")
  68.        
  69.         local host = "YOU MAY NOT KNOW XD"              //use this instead of locahost
  70.         local user = "YOU MAY NOT KNOW XD"
  71.         local pass = "YOU MAY NOT KNOW XD"
  72.         local dbname = "YOU MAY NOT KNOW XD"
  73.         local port = YOU MAY NOT KNOW XD
  74.         local db = {}
  75.         local err = ""
  76.        
  77.         function jaooeConnectDatabase()
  78.                 db, err = tmysql.initialize( host,user,pass,dbname,port)
  79.         end
  80.  
  81.         hook.Add("Initialize", "jaooeConnectDatabase", jaooeConnectDatabase)
  82.  
  83.         util.AddNetworkString("cl_sendDonationKey")
  84.  
  85.         net.Receive("cl_sendDonationKey", function(len,ply)
  86.                 local key = net.ReadString()
  87.                 jaooeProcessKey(ply,key)
  88.         end)
  89.  
  90.         function jaooeProcessKey(ply,key)
  91.  
  92.                 db:Query("SELECT * FROM activationkeys WHERE activationkey='"..tmysql.escape(key).."' AND used=0", function(result,status,error)
  93.                         if status then
  94.                                 if #result > 0 and #result < 2 then
  95.                                         if DONATIONTYPES[result[1]["type"]] then
  96.                                                 DONATIONTYPES[result[1]["type"]](ply)
  97.                                                 db:Query("UPDATE activationkeys SET used=1 WHERE activationkey='"..tmysql.escape(key).."' AND used=0", function(res,stat,err)
  98.                                                         if stat then
  99.                                                                 print(ply:Nick().."'s key was used, updated database")
  100.                                                         else
  101.                                                                 print(ply:Nick().."'s key could not be updated, something went wrong: "..err)
  102.                                                         end
  103.                                                 end,1)
  104.                                         else
  105.                                                 ply:PrintMessage(HUD_PRINTTALK,"Key found but no code exists, contact administrator")
  106.                                         end
  107.                                 elseif #result > 0 then
  108.                                         ply:PrintMessage(HUD_PRINTTALK, "Multiple keys exist, contact administrator")
  109.                                 else
  110.                                         ply:PrintMessage(HUD_PRINTTALK, "Nothing found")
  111.                                 end
  112.                         else
  113.                                 ply:PrintMessage(HUD_PRINTTALK, "Could not contact server, contact administrator")
  114.                         end
  115.                 end, 1)
  116.                 db:Poll()
  117.  
  118.         end
  119.  
  120. end
  121.  

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: attempt to index global 'ULib' (a nil value) help please
« Reply #8 on: January 13, 2014, 02:05:20 pm »
Line 15, Ulib.ucl.Adduser is a function, not a table. It expects all those variables to be filled when the server starts up. It's running when the server starts up.
Looks as though your trying to treat it as a table entry like you did previously for keys 1 and 2.
Can't be done the way you're trying (you're treating it as a table key 3)

What, exactly, are you trying to do?
I could spend time reading all the code, but, I'd rather have your explanation of what you're attempting to do.
And, is this your own code you're trying to modify?
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline atomic-cruncher

  • Newbie
  • *
  • Posts: 7
  • Karma: 0
Re: attempt to index global 'ULib' (a nil value) help please
« Reply #9 on: January 13, 2014, 11:05:20 pm »
Well I have generated keys with a value (1, 2, 3) each stand for another rank.
For example: JsjajaJusjjwbs is for rank 3. What it has to do is when I fill the key in the program it should give me donator

Offline Neku

  • Hero Member
  • *****
  • Posts: 549
  • Karma: 27
Re: attempt to index global 'ULib' (a nil value) help please
« Reply #10 on: January 13, 2014, 11:11:29 pm »
Line 73 is not in string format.
Out of the Garry's Mod business.

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: attempt to index global 'ULib' (a nil value) help please
« Reply #11 on: January 14, 2014, 05:21:39 am »
Code: Lua
  1. DONATIONTYPES["3"] = function(ply)
  2.    ULib.ucl.addUser(...)
  3. end
  4.  

I think that's what you're looking for.

Experiencing God's grace one day at a time.

  • Print