Ulysses

General => Developers Corner => Topic started by: Organik on July 03, 2013, 11:29:46 AM

Title: [SOLVED] Chat Timer Error
Post by: Organik 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
Title: Re: Chat Timer Error
Post by: Megiddo 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?
Title: Re: Chat Timer Error
Post by: Organik 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.
Title: Re: Chat Timer Error
Post by: Megiddo 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.
Title: Re: Chat Timer Error
Post by: Organik on July 05, 2013, 11:16:08 AM
Megiddo,

What would you recommend to do in this case?

Thanks.
Title: Re: Chat Timer Error
Post by: Megiddo on July 05, 2013, 02:22:12 PM
You need to invoke the chat library client side only.
Title: Re: Chat Timer Error
Post by: Organik 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
Title: Re: Chat Timer Error
Post by: JamminR 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.
Title: Re: Chat Timer Error
Post by: Organik 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.