View Single Post
05-26-09, 12:37 PM   #12
playsatan
A Deviate Faerie Dragon
 
playsatan's Avatar
Join Date: Jun 2008
Posts: 18
ok i inserted the local function at the end of the addon so it now reads as:

Code:

if not FactDB then FactDB={" "} end 
local key = "fact"  -- whispered command to get current fact



function Facts_OnLoad()        
    SLASH_FACTS1 = "/fact"      
    SlashCmdList["FACTS"] = Facts_Command
    this:RegisterEvent("CHAT_MSG_WHISPER")
end

function Facts_Command(msg)    
    if IsInGuild() then
        local cmd,newFact = Facts_GetCommand(msg)
        if cmd == "reset" then    
            FactDB.Count = 1 
        end
        if cmd == "next" then 
            FactDB.Count = FactDB.Count + 1
            Facts_ShowFact()
        end
        if cmd == "new" then
            if newFact ~= "" then
                pos = table.getn(FactDB) + 1
                FactDB[pos] = newFact
            else
                message("Please add a new fact after new")
            end
        end
        if cmd == "" then
            Facts_ShowFact()
        end
        
    end
end

function Facts_ShowFact(sender)
    if FactDB.Count > table.getn(FactDB) then 
        FactDB.Count = 1
    end
    local FactOfTheDay = FactDB[FactDB.Count]
    if sender then
        SendChatMessage("RANDOM FACT OF THE DAY !: "..FactOfTheDay, "WHISPER", nil, sender)
    else
        SendChatMessage("RANDOM FACT OF THE DAY !: "..FactOfTheDay, "GUILD")  --  is the message printed before your fact
    end
end

function Facts_GetCommand(msg)  -- seperate the command and the following string
    if msg then
 		local a,b,c=strfind(msg, "(%S+)"); --contiguous string of non-space characters
 		if a then
 			return c, strsub(msg, b+2);
 		else	
 			return "";
 		end
 	end
end


function Facts_OnEvent(msg, sender)  -- has someone whispered me the key command?
    if msg == key  then
        Facts_ShowFact(sender)
        FactDB.Count = FactDB.Count + 1
    end
end

local function SendSplitMessages(message, player) --player is optional, name of the player to whisper -- assumes Guild chat if you don't send it anything
   message = strtrim(message)
   local msg, chan = strsplit(" ",message), player and "WHISPER" or "GUILD"
   for i=2, select(#, strsplit(" ",message)) do
       local new = select(i, strsplit(" ",message))
       if not new then
          SendChatMessage(msg, chan, nil, player)
          return
       end
       if strlen(msg) + strlen(new) > 254 then
          SendChatMessage(msg, chan, nil, player)
          msg = ""
       end
       msg = msg .. " " .. new
   end
   if msg and msg ~= "" and msg ~= " " then
       SendChatMessage(msg, chan, nil, player)
   end
end

However im getting the error
G:\Program Files\SciTE-WOWInterface\bin\luac.exe: Facts.lua:74: unexpected symbol near `#'
in my compiler and the following when i log into wow:

Code:
Date: 2009-05-26 19:34:53
ID: 1
Error occured in: Global
Count: 1
Message: ..\AddOns\Facts\Facts.lua line 74:
   unexpected symbol near ','
Debug:
   [C]: ?
AddOns:
  Zoom, v
  Swatter, v5.5.4254 (WombatII)
  WowheadLooter, v30100
  Ace2, v
  Ace3, v
  AucAdvanced, v5.5.4254 (WombatII)
  AucFilterBasic, v5.5.4254 (WombatII)
  AucFilterOutlier, v5.5.4254.2531
  AucMatchUndercut, v5.5.4254.2531
  AucStatClassic, v5.5.4254 (WombatII)
  AucStatHistogram, v5.5.4254 (WombatII)
  AucStatiLevel, v5.5.4254 (WombatII)
  AucStatSales, v5.5.4254.2842
  AucStatWOWEcon, v5.5.4254.2530
  AucUtilAHWindowControl, v5.5.4254.3311
  AucUtilAppraiser, v5.5.4254.2530
  AucUtilAskPrice, v5.5.4254.3175
  AucUtilAutoMagic, v5.5.4254.3142
  AucUtilCompactUI, v5.5.4254.2530
  AucUtilEasyBuyout, v5.5.4254.3583
  AucUtilItemSuggest, v5.5.4254.3108
  AucUtilPriceLevel, v5.5.4254.2545
  AucUtilScanButton, v5.5.4254.2530
  AucUtilScanFinish, v5.5.4254.2530
  AucUtilScanProgress, v5.5.4254.2530
  AucUtilSearchUI, v5.5.4254.3655
  AucUtilSimpleAuction, v5.5.4254.0
  AucUtilVendMarkup, v5.5.4254.2530
  AutoEmote, v
  Babylonian, v5.1.DEV.130
  BagnonForever, v1.1.1
  BagnonTooltips, v
  BankStack, vv13
  BeanCounter, v5.5.4254 (WombatII)
  Bejeweled, v1.03b
  Buffet, v3.0.9.27
  BulkMail2Inbox, v3.0.2
  Cartographer, v2.0
  Combuctor, v2.1.0
  CombuctorSets, v
  Configator, v5.1.DEV.130
  Cutup, v
  Deathstimator, v0.6
  DebugLib, v5.1.DEV.130
  DoTimer, v4.3.1
  DurabilityCount, v1.2
  Facts, v1.0
  SlideBar, v5.5.4254 (WombatII)
  Stubby, v5.5.4254 (WombatII)
  (ck=56c)
ok i changed
for i=2, select(#, strsplit(" ",message)) do
to
for i=2, select(i, strsplit(" ",message)) do
and the compiler has no problems with it but when i tried it with a fact that was over 254 characters long it behaved as normal.

Last edited by playsatan : 05-26-09 at 12:48 PM. Reason: Testing
  Reply With Quote