Author Topic: [SOLVED] Chat Timer Error  (Read 3012 times)

0 Members and 1 Guest are viewing this topic.

Offline Organik

  • Newbie
  • *
  • Posts: 27
  • Karma: 1
    • Artifice Gaming Network
[SOLVED] Chat Timer Error
« on: July 03, 2013, 11:29:46 AM »
Hello everyone,

I seem to have a simple issue, yet I don't know why this is happening. Every once in a while, my chat timer will throw a lua error saying the timer was "broken". Can someone tell me if there is a problem with this code, or perhaps a better way to go about doing it?

Code: [Select]
local greencolor = Color( 25, 200, 25 )
local whitecolor = Color( 255, 255, 255 )
timer.Create( "my_timer", 300, 0, function()
chat.AddText(greencolor, "Enjoy playing on this server? Type ", whitecolor, "!donate ", greencolor, "in chat to ensure the server stays online.")
end)

Regards,
Organik
« Last Edit: July 09, 2013, 03:13:48 PM by Organik »

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Chat Timer Error
« Reply #1 on: July 03, 2013, 02:50:15 PM »
The error is more detailed than just saying the timer broke, can you give the full details?
Experiencing God's grace one day at a time.

Offline Organik

  • Newbie
  • *
  • Posts: 27
  • Karma: 1
    • Artifice Gaming Network
Re: Chat Timer Error
« Reply #2 on: July 05, 2013, 09:57:25 AM »
Here we go, finally happened again.

Line 23 is the chat.AddText line I have in the first post.
« Last Edit: July 05, 2013, 09:59:05 AM by Organik »

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Chat Timer Error
« Reply #3 on: July 05, 2013, 10:59:46 AM »
I see. The chat library is client side only, and it seems you're invoking it from the server.
Experiencing God's grace one day at a time.

Offline Organik

  • Newbie
  • *
  • Posts: 27
  • Karma: 1
    • Artifice Gaming Network
Re: Chat Timer Error
« Reply #4 on: July 05, 2013, 11:16:08 AM »
Megiddo,

What would you recommend to do in this case?

Thanks.

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Chat Timer Error
« Reply #5 on: July 05, 2013, 02:22:12 PM »
You need to invoke the chat library client side only.
Experiencing God's grace one day at a time.

Offline Organik

  • Newbie
  • *
  • Posts: 27
  • Karma: 1
    • Artifice Gaming Network
Re: Chat Timer Error
« Reply #6 on: July 05, 2013, 03:32:07 PM »
Megiddo,

I looked it the docs and such but can't find what I'm looking for. Is this as simple as adding another lua file with my timer code in it, and prefix that lua file with cl_  ?

EDIT: I looked through another addon I had, and they just added another folder inside modules called cl, and I created my timer in a file within that. Hopefully this works. However I've seem some addons that just prefix each file in a certain manner.. is this also acceptable?

Thanks,

Organik
« Last Edit: July 05, 2013, 03:47:12 PM by Organik »

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Chat Timer Error
« Reply #7 on: July 05, 2013, 08:05:50 PM »
Organik, there is no magic file name that makes a file or folder client side only.
We, and other mod writers, name our files in ways such as CL so we know those files include code, or are loaded in other files, as client side only.
Naming of files is often used in that manner for large projects, where huge blocks of code would be difficult to distinguish otherwise.

One quick way is to have something like "if SERVER then return" at the top of files (or functions) you want client side only.
http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index8e50.html gives a perfect example of if SERVER and if CLIENT.
(Yes, it's aimed at a first swep, but, the first bit of code block shows the server/client test.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Organik

  • Newbie
  • *
  • Posts: 27
  • Karma: 1
    • Artifice Gaming Network
Re: Chat Timer Error
« Reply #8 on: July 09, 2013, 03:13:30 PM »
Organik, there is no magic file name that makes a file or folder client side only.
We, and other mod writers, name our files in ways such as CL so we know those files include code, or are loaded in other files, as client side only.
Naming of files is often used in that manner for large projects, where huge blocks of code would be difficult to distinguish otherwise.

One quick way is to have something like "if SERVER then return" at the top of files (or functions) you want client side only.
http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index8e50.html gives a perfect example of if SERVER and if CLIENT.
(Yes, it's aimed at a first swep, but, the first bit of code block shows the server/client test.

That's very helpful. Thank you, JamminR.