I'm currently learning lua and I decided to try and make a chat filter that plays a sound when you swear it plays a sound. I keep getting
[ERROR] addons/ninjafilter/lua/autorun/core.lua:2: '=' expected near '<eof>'
1. unknown - addons/ninjafilter/lua/autorun/core.lua:0
in my console and I can't seem to figure out why. Any help? Here's my code:
sound.Add( {
name = "ninja",
channel = CHAN_STATIC,
volume = 1.0,
level = 80,
pitch = { 100 },
sound = "common/ninja.wav"
} )
swear = {}
swear[1] = "fuck"
swear[2] = "bitch"
swear[3] = "ass"
hook.Add( "OnPlayerChat", "test", function( ply, text, public )
for key , value in pairs(swear) do
if ( string.match( text , [%a_], 1) == value) then
ply:EmitSound( "ninja", 75, 100, 1, CHAN_AUTO ) else
print("epictime")
return ""
end
end )
I can tell you the fix right away, but that wouldn't be immediately helpful. Instead, let's paste the code in glualint-web:
https://files.facepunch.com/forum/upload/107070/803bd1a1-b244-4d91-9a8c-c753502300ba/chrome_2019-03-03_10-56-53.png
There are two major kinds of errors in Lua:
Syntax error
Runtime error
Lua has a "grammar", meaning you have to abide by certain "grammar" rules for some piece of code to be valid Lua. A syntax error happens when you break those rules. Some examples of trivial syntax errors are:
-- Missing ending "
a = "test
-- Missing closing }
b = {
-- missing end
if a then b = true
-- Missing )
print("yeah"
-- The return doesn't belong here
if return 3 then b = false end
A runtime error happens when the syntax (grammar) of a Lua file is correct, but something goes wrong while executing it. An example:
-- You can't add 1 to a table
a = {}
b = a + 1
You're dealing with a syntax error. The second argument of string.match, namely [%a_], is not valid Lua. You need to put that in string quotes, like "[%a_]"
Ok thank you! I appreciate the help!
The code you posted here never had the syntax error you gave. Please check whether you're posting the entire file, and that you've got the right file in the first place.
I am positive that's the code and that is the entire file.
I fixed the issue. There was a problem with the lua file it self and not its contents. I created a new lua file and pasted the code in and it worked. I appreciate the help you gave me.
Sorry, you need to Log In to post a reply to this thread.