• Print

Author Topic: Modding the ULX MOTD to have a timer.  (Read 4666 times)

0 Members and 1 Guest are viewing this topic.

Offline FUImACat

  • Newbie
  • *
  • Posts: 2
  • Karma: 0
Modding the ULX MOTD to have a timer.
« on: January 16, 2017, 11:00:24 pm »
Hi, Im trying to prevent people from closing the ulx motd without reading it so i put a timer on it and i get this error and it doesn't seem to be working, i attached the LUA file if anyone can help, thank you!

This Is The error i get.

[ERROR] addons/ulx admin/lua/ulx/modules/cl/motdmenu.lua:10: attempt to index local 'button' (a nil value)
  1. unknown - addons/ulx admin/lua/ulx/modules/cl/motdmenu.lua:10

Timer Failed! [accepttimer][@addons/ulx admin/lua/ulx/modules/cl/motdmenu.lua (line 61)]
« Last Edit: January 16, 2017, 11:04:20 pm by FUImACat »

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: Modding the ULX MOTD to have a timer.
« Reply #1 on: January 17, 2017, 11:53:23 am »
Code: Lua
  1. timer.Create("accepttimer", 1, 11, accept, window)

You're "accept" function requires an argument, "button". You're passing this timer with the function, but it's not receiving any argument, so 'button' doesn't mean anything. (Aka, a nil value)

Also, timer.Create only accepts 4 arguments, the string name, number delay, number repetitions, and func function. However, you  have a fifth argument "window" which I'm assuming you were trying to send to the accept funtion? If that's the case you'd need to do

Code: Lua
  1. timer.Create("accepttimer", 1, 11, function() accept( window ) end)


Edit: Also, looking at your timer, you have "time = time - 1" in your accept function, this means the time is only going to go down by 1 every 11 seconds. You should have the timer repeat indefinitely until time == 0, then timer.Remove the timer.
« Last Edit: January 17, 2017, 12:11:10 pm by iViscosity »
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

Offline FUImACat

  • Newbie
  • *
  • Posts: 2
  • Karma: 0
Re: Modding the ULX MOTD to have a timer.
« Reply #2 on: January 17, 2017, 09:58:17 pm »
Code: Lua
  1. timer.Create("accepttimer", 1, 11, accept, window)

You're "accept" function requires an argument, "button". You're passing this timer with the function, but it's not receiving any argument, so 'button' doesn't mean anything. (Aka, a nil value)

Also, timer.Create only accepts 4 arguments, the string name, number delay, number repetitions, and func function. However, you  have a fifth argument "window" which I'm assuming you were trying to send to the accept funtion? If that's the case you'd need to do

Code: Lua
  1. timer.Create("accepttimer", 1, 11, function() accept( window ) end)

Edit: Also, looking at your timer, you have "time = time - 1" in your accept function, this means the time is only going to go down by 1 every 11 seconds. You should have the timer repeat indefinitely until time == 0, then timer.Remove the timer.

I did as much as i could under stand Lua/ code in general inst my strong point, I've got this and now there is no errors but the accept button never becomes active.

Code: Lua
  1. ulx.motdmenu_exists = true
  2.  
  3. local isUrl
  4. local url
  5.  
  6.     function accept(button)
  7.         if time == 1 then
  8.             button:SetText("1 second remaining")
  9.         else
  10.             button:SetText(string.format("%i more seconds", time))
  11.         end
  12.         if time == 0 then
  13.             button:SetText("I Agree")
  14.             button:SetDisabled( false )
  15.         end
  16.         time = time - 1
  17.              
  18.     end
  19.  
  20. function ulx.showMotdMenu()
  21.         local window = vgui.Create( "DFrame" )
  22.         if ScrW() > 640 then -- Make it larger if we can.
  23.                 window:SetSize( ScrW()*0.9, ScrH()*0.9 )
  24.         else
  25.                 window:SetSize( 640, 480 )
  26.         end
  27.         window:Center()
  28.         window:SetTitle( "Benders Villa" )
  29.     window:ShowCloseButton( false ) -- Show the close button?
  30.         window:SetVisible( true )
  31.         window:MakePopup()
  32.        
  33.         local panel = vgui.Create( "DPanel", window )
  34.         local html = vgui.Create( "HTML", panel )
  35.  
  36.         local button = vgui.Create( "DButton", window )
  37.         button:SetText( "10 seconds remaining" )
  38.             button.DoClick = function()
  39.                 window:Close();
  40.                     timer.Create("chat1", 1, 1, function() RunConsoleCommand("say", "I have read and agree to the rules listed in the motd.") end)
  41.                         timer.Create("chat2", 2, 1, function() RunConsoleCommand("say_team", "I have read and agree to the rules listed in the motd.") end)      
  42.     end
  43.         button:SetSize( 100, 40 )
  44.         button:SetDisabled( true )
  45.         button:SetPos( (window:GetWide() - button:GetWide()) / 3, window:GetTall() - button:GetTall() - 10 )
  46.        
  47.     local buttoncancel = vgui.Create( "DButton", window )
  48.         buttoncancel:SetText( "I Disagree" )
  49.         buttoncancel.DoClick = function()
  50.             timer.Create("leave", 1, 1, function() RunConsoleCommand("disconnect") end)
  51.            
  52.     end
  53.         buttoncancel:SetSize( 100, 40 )
  54.         buttoncancel:SetPos( (window:GetWide() - buttoncancel:GetWide()) / 1.5, window:GetTall() - buttoncancel:GetTall() - 10 )
  55.  
  56.         panel:SetSize( window:GetWide() - 20, window:GetTall() - button:GetTall() - 50 )
  57.         panel:SetPos( 10, 30 )
  58.         html:Dock( FILL )
  59.        
  60.         time = 10
  61.         timer.Create("accepttimer", 1, 1, function() accept( window ) end)
  62.         if( not ValidPanel( button ) )then return end
  63.         if not isUrl then
  64.                 html:SetHTML( file.Read( "ulx/motd.txt" ) )
  65.         else
  66.                 html:OpenURL( url )
  67.         end
  68. end
  69.  

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: Modding the ULX MOTD to have a timer.
« Reply #3 on: January 18, 2017, 03:59:01 am »
I just realized you're passing the entire window to the accept function when I think all you're trying to do is edit the button, am I correct? If that's the case, you should pass just the button, not the window. Also your timer only loops once, and then doesn't do anything to even if it worked you'd only get to 9 seconds. Make the timer run indefinitely, then when time == 0,  timer.Remove it.
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

  • Print