• Print

Author Topic: Cannot get this addon to work properly... is something gone wrong in my lua?  (Read 6799 times)

0 Members and 1 Guest are viewing this topic.

Offline ajzima32

  • Newbie
  • *
  • Posts: 5
  • Karma: 0
Code: Lua
  1. if SERVER then
  2.         AddCSLuaFile("autorun/voicecons.lua")
  3. end
  4.  
  5. if CLIENT then
  6.         print( "Chat Commands FNAF 2 Edition" )
  7.         print( "By Sakura" )
  8. end
  9.  
  10. USay = {} --Emoticons Start
  11.  
  12. USay.WordList = {
  13. ["music2"] = "fnaf2/musicbox2.wav";
  14. ["robot2"] = "fnaf2/robotamb2.wav";
  15. ["scream2"] = "fnaf2/scream2.wav";
  16. ["phone1"] = "phoneman/call1a.wav";
  17. ["phone2"] = "phoneman/call2a.wav";
  18. ["phone3"] = "phoneman/call3a.wav";
  19. ["phone4"] = "phoneman/call4a.wav";
  20. ["phone5"] = "phoneman/call5a.wav";
  21. ["phone6"] = "phoneman/call6a.wav";
  22. ["phonesound2"] = "phoneman/ring.wav";
  23. ["hello?"] = "other/bbhello.wav";
  24. ["hi"] = "other/bbhi.wav";
  25. ["bblaugh"] = "other/bblaugh.wav";
  26. ["manglestatic"] = "other/mangleradio.wav";
  27. }
  28.  
  29. function USay.ChatFunction( ply, text )
  30.    if ply:IsValid() then
  31.       for k,v in pairs(USay.WordList) do
  32.          if string.find( text, k ) then
  33. ply:EmitSound(USay.WordList[k])
  34.             return text
  35.          end
  36.       end
  37.    end
  38. end
  39. hook.Add("PlayerSay", "USay.ChatFunction_Hook", USay.ChatFunction) --Emoticons End

The purpose of this addon is to play a sound (globally) upon typing the keyword.

For some reason, the only ones that seem to work are
music2
robot2
scream2

The rest (i can hear my headphones crack and my game will lag a bit) but no sound will play.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
1) You're not setting up the table correctly.
You'd need commas for the way you're trying to split the table.
Example

Table.sub = {
["var1"] = "data1",
["var2"] = "data2",
}

2) Using your for pairs table loop, you probably want to emitsound the V of the loop, not K.
Your method would work, but might as well use the data instead of having lua engine look up what var is twice.
To make sure your code's working, try adding 'debug' "print" statements during your code and watch in console.

function USay.ChatFunction( ply, text )
  if ply:IsValid() then
print ("Looking in Text: " .. text )
     for k,v in pairs(USay.WordList) do
print (" for the word: " .. k "
        if string.find( text, k ) then
print (" FOUND: " .. k .."!" )
print (" I will next try to EmitSound: " .. v )
          ply:EmitSound(USay.WordList[v])
          return text
        end
     end
  end
end

"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline ajzima32

  • Newbie
  • *
  • Posts: 5
  • Karma: 0
Alright, well now my addon has stopped working completely.

[ERROR] addons/chat sounds - fnaf 2 edition/lua/autorun/voicecons.lua:33: unfinished string near '"'
  1. unknown - addons/chat sounds - fnaf 2 edition/lua/autorun/voicecons.lua:0

Code: Lua
  1. if SERVER then
  2.         AddCSLuaFile("autorun/voicecons.lua")
  3. end
  4.  
  5. if CLIENT then
  6.         print( "Chat Commands FNAF 2 Edition" )
  7.         print( "By Sakura" )
  8. end
  9.  
  10. USay = {} --Emoticons Start
  11.  
  12. USay.WordList = {
  13. ["music2"] = "fnaf2/musicbox2.wav",
  14. ["robot2"] = "fnaf2/robotamb2.wav",
  15. ["scream2"] = "fnaf2/scream2.wav",
  16. ["phone1"] = "phoneman/call1a.wav",
  17. ["phone2"] = "phoneman/call2a.wav",
  18. ["phone3"] = "phoneman/call3a.wav",
  19. ["phone4"] = "phoneman/call4a.wav",
  20. ["phone5"] = "phoneman/call5a.wav",
  21. ["phone6"] = "phoneman/call6a.wav",
  22. ["phonesound2"] = "phoneman/ring.wav",
  23. ["hello?"] = "other/bbhello.wav",
  24. ["hi"] = "other/bbhi.wav",
  25. ["bblaugh"] = "other/bblaugh.wav",
  26. ["manglestatic"] = "other/mangleradio.wav",
  27. }
  28.  
  29. function USay.ChatFunction( ply, text )
  30.   if ply:IsValid() then
  31. print ("Looking in Text: " .. text )
  32.      for k,v in pairs(USay.WordList) do
  33. print (" for the word: " .. k "
  34.        if string.find( text, k ) then
  35. print (" FOUND: " .. k .."!" )
  36. print (" I will next try to EmitSound: " .. v )
  37.          ply:EmitSound(USay.WordList[v])
  38.          return text
  39.        end
  40.     end
  41.  end
  42. end
  43. hook.Add("PlayerSay", "USay.ChatFunction_Hook", USay.ChatFunction) --Emoticons End


« Last Edit: December 08, 2014, 01:48:42 pm by ajzima32 »

Offline Avoid

  • Full Member
  • ***
  • Posts: 142
  • Karma: 42
Alright, well now my addon has stopped working completely.

[ERROR] addons/chat sounds - fnaf 2 edition/lua/autorun/voicecons.lua:33: unfinished string near '"'
  1. unknown - addons/chat sounds - fnaf 2 edition/lua/autorun/voicecons.lua:0

Code: Lua
  1. if SERVER then
  2.         AddCSLuaFile("autorun/voicecons.lua")
  3. end
  4.  
  5. if CLIENT then
  6.         print( "Chat Commands FNAF 2 Edition" )
  7.         print( "By Sakura" )
  8. end
  9.  
  10. USay = {} --Emoticons Start
  11.  
  12. USay.WordList = {
  13. ["music2"] = "fnaf2/musicbox2.wav",
  14. ["robot2"] = "fnaf2/robotamb2.wav",
  15. ["scream2"] = "fnaf2/scream2.wav",
  16. ["phone1"] = "phoneman/call1a.wav",
  17. ["phone2"] = "phoneman/call2a.wav",
  18. ["phone3"] = "phoneman/call3a.wav",
  19. ["phone4"] = "phoneman/call4a.wav",
  20. ["phone5"] = "phoneman/call5a.wav",
  21. ["phone6"] = "phoneman/call6a.wav",
  22. ["phonesound2"] = "phoneman/ring.wav",
  23. ["hello?"] = "other/bbhello.wav",
  24. ["hi"] = "other/bbhi.wav",
  25. ["bblaugh"] = "other/bblaugh.wav",
  26. ["manglestatic"] = "other/mangleradio.wav",
  27. }
  28.  
  29. function USay.ChatFunction( ply, text )
  30.   if ply:IsValid() then
  31. print ("Looking in Text: " .. text )
  32.      for k,v in pairs(USay.WordList) do
  33. print (" for the word: " .. k )
  34.         if string.find( text, k ) then
  35. print (" FOUND: " .. k .."!" )
  36. print (" I will next try to EmitSound: " .. v )
  37.           ply:EmitSound(USay.WordList[v])
  38.           return text
  39.         end
  40.      end
  41.   end
  42. end
  43. hook.Add("PlayerSay", "USay.ChatFunction_Hook", USay.ChatFunction) --Emoticons End

You forgot to close the brackets at line 33, also you put a quotation mark at the end. :)

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Yeah, I wasn't exactly meaning you copy/paste my example 100%. (It missed a closing parenthesis )
At this time of day for me, I'm within an hour of bedtime, with only 5-6 hours until time to get up for work.
(All you young college kids on a half hour nap between 'night' and 'classes' hush...I'm 1.8x-2x your age. :) )

Pro-Tip - learn to read the error codes Gmod lua presents.
It told you line 33 was expecting something.
Posted here, it's numbered, and, viola, us more experienced folks saw 33 was missing the )
We recommend you get a decent text editor that highlights code/punctuation.
I personally like Notepad++, but there are many others out there.
« Last Edit: December 08, 2014, 08:00:41 pm by JamminR »
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline ajzima32

  • Newbie
  • *
  • Posts: 5
  • Karma: 0
Yeah, I wasn't exactly meaning you copy/paste my example 100%. (It missed a closing parenthesis )
At this time of day for me, I'm within an hour of bedtime, with only 5-6 hours until time to get up for work.
(All you young college kids on a half hour nap between 'night' and 'classes' hush...I'm 1.8x-2x your age. :) )

Pro-Tip - learn to read the error codes Gmod lua presents.
It told you line 33 was expecting something.
Posted here, it's numbered, and, viola, us more experienced folks saw 33 was missing the )
We recommend you get a decent text editor that highlights code/punctuation.
I personally like Notepad++, but there are many others out there.


Yes, I have Note++pad  and I saw the gmod error, upon doing so I went to go find and do away with the error, yet everything I tried wasnt working..

"Hey, you cant judge me. I literally just got started with lua and wanted to know why the plugin wasnt working in general. Sounds werent playing."


I have no idea if it went from compressing the addon, or even if my sound files were up. Appearently not, they work fine while playing them in Windows Media Player.

And yes, I know it wasnt going to be as easy as copy/paste.


Offline ajzima32

  • Newbie
  • *
  • Posts: 5
  • Karma: 0
Wow... I said Note++pad. Maybe I should learn simple Kindergarten subjects first... ;-;

  • Print