Author Topic: Trivia conversion error  (Read 2602 times)

0 Members and 1 Guest are viewing this topic.

Offline Tw?sT?d-d?v

  • Lord
  • ***
  • Posts: 436
  • Karma: +79/-2
    • EURO-OP
Trivia conversion error
« on: 20 October, 2007, 13:57:10 »
Trying to get triv ready for new api  ..  I got it almost ready ... R/C cmds all work and Triv runs in main ..
Only prob happens when i try to answer a question    i get this error

Code: [Select]
Syntax Trivia-Ex-V.0.68b [New API].lua:386: bad argument #1 to 'lower' (string expected, got nil)
Which is from this line   

Code: [Select]
if string.lower(sdata) == string.lower(v) then
Can i be pointed in where i gone wrong please

Here is rest of paragrahp from script if needed
Code: [Select]
-----------------------------------
function TrivEx:ParseData(mode,curUser,data)
self._datamode = mode
data = string.sub(data,1,string.len(data)-1)
local _,_,sdata = string.find( data, "^%b<>%s(.*)$")
local _,_,cmd = string.find( data, "^%b<>%s["..self._Sets.prefixes.."](%w+)")
if cmd then
cmd = string.lower(cmd)
if self._Cmds[cmd] then
self._Cmds[cmd](self,curUser,data)
return true
end
elseif sdata then
local corrans = for_,vin ipairs(curTriv.ans) do
if string.lower(sdata) == string.lower(v) then
return (v)
end
end
if corrans and (not curTriv:GetGetQues()) then
-- SetGetQues
curTriv:SetGetQues(1)
local ansTime = string.format("%.2f",(os.clock()-curTriv.start)) -- Get Answering Time in sec.
if (TrivEx._Sets.showcorrectanswer == 1) then
-- Show right answer
local talked = nil
if string.lower(sdata) == string.lower(corrans) then
talked = corrans
end
if talked then
if (self:GetPlayMode() == "pm") then
self:SendToPlayers(data,curUser)
else
if TrivEx._Sets.maintoall then
Core.SendToAll("<"..curUser.sNick.."> "..corrans)
else
self:SendToPlayers(corrans,curUser)
end
end
self:SendToPlayers("Correct "..curUser.sNick..", the answer is \""..corrans.."\". You get "..curTriv.points.." Point(s). Answer solved in "..ansTime.." sec.")
-- Update Scores
if self._Scores[curUser.sNick] then
self._Scores[curUser.sNick].Score = self._Scores[curUser.sNick].Score + curTriv.points
self._Scores[curUser.sNick].AvTime[1] = self._Scores[curUser.sNick].AvTime[1] + ansTime
self._Scores[curUser.sNick].AvTime[2] = self._Scores[curUser.sNick].AvTime[2] + 1
self._Scores[curUser.sNick].AvTime[3] = tonumber(string.format("%.2f",self._Scores[curUser.sNick].AvTime[1]/self._Scores[curUser.sNick].AvTime[2]))
else
self._Scores[curUser.sNick] = {}
self._Scores[curUser.sNick].Score = curTriv.points
self._Scores[curUser.sNick].Streak = 1
self._Scores[curUser.sNick].AvTime = { tonumber(ansTime),1,tonumber(ansTime) }
end
if (self._Sets.showcorrectanswer == 1) then
self:SendToPlayers(curUser.sNick.."'s Stats, Score: "..self._Scores[curUser.sNick].Score.." Point(s), Answered Questions: "..self._Scores[curUser.sNick].AvTime[2]..", Average Answering Time: "..string.format("%.2f",self._Scores[curUser.sNick].AvTime[3]).." sec.")
end
-- Show other answeres if present
if curTriv.availans > 1 then
curTriv:ShowAnswer()
end
-- Check for Streak
curTriv.streak:UpdStreak(curUser)
return true
end
elseif (TrivEx._Sets.showcorrectanswer == 2) then
-- Show right answer
local talked = nil
if string.lower(sdata) == string.lower(corrans) then
talked = corrans
end
if talked then
if (self:GetPlayMode() == "pm") then
self:SendToPlayers(data,curUser)
else
if TrivEx._Sets.maintoall then
Core.SendToAll("<"..curUser.sNick.."> "..corrans)
else
self:SendToPlayers(corrans,curUser)
end
end
self:SendToPlayers("Correct "..curUser.sNick..", the answer is \""..corrans.."\". You get "..curTriv.points.." Point(s).")
-- Update Scores
if self._Scores[curUser.sNick] then
self._Scores[curUser.sNick].Score = self._Scores[curUser.sNick].Score + curTriv.points
self._Scores[curUser.sNick].AvTime[1] = self._Scores[curUser.sNick].AvTime[1] + ansTime
self._Scores[curUser.sNick].AvTime[2] = self._Scores[curUser.sNick].AvTime[2] + 1
self._Scores[curUser.sNick].AvTime[3] = tonumber(string.format("%.2f",self._Scores[curUser.sNick].AvTime[1]/self._Scores[curUser.sNick].AvTime[2]))
else
self._Scores[curUser.sNick] = {}
self._Scores[curUser.sNick].Score = curTriv.points
self._Scores[curUser.sNick].Streak = 1
self._Scores[curUser.sNick].AvTime = { tonumber(ansTime),1,tonumber(ansTime) }
end
if (self._Sets.showcorrectanswer == 1) then
self:SendToPlayers(curUser.sNick.."'s Stats, Score: "..self._Scores[curUser.sNick].Score.." Point(s), Answered Questions: "..self._Scores[curUser.sNick].AvTime[2]..", Average Answering Time: "..string.format("%.2f",self._Scores[curUser.sNick].AvTime[3]).." sec.")
end
-- Show other answeres if present
if curTriv.availans > true then
curTriv:ShowAnswer()
end
-- Check for Streak
curTriv.streak:UpdStreak(curUser)
return true
end
end
end
end
end
--------------------
« Last Edit: 20 October, 2007, 14:55:19 by bastya_elvtars »

PtokaX forum

Trivia conversion error
« on: 20 October, 2007, 13:57:10 »

Offline bastya_elvtars

  • Forum God
  • ****
  • Posts: 3 730
  • Karma: +173/-7
  • The rock n' roll doctor
    • The FreshStuff3 Site
Re: Script error
« Reply #1 on: 20 October, 2007, 14:55:03 »
Please give titles to topics that are informative.
Everything could have been anything else and it would have just as much meaning.

Offline Tw?sT?d-d?v

  • Lord
  • ***
  • Posts: 436
  • Karma: +79/-2
    • EURO-OP
Re: Trivia conversion error
« Reply #2 on: 20 October, 2007, 15:04:35 »
Ok sorry for that     Thx for editing  :)

Offline Naithif

  • Triple Ace
  • **
  • Posts: 199
  • Karma: +32/-13
Re: Trivia conversion error
« Reply #3 on: 20 October, 2007, 21:22:26 »
Above that line mistype.

This one
Code: [Select]
local corrans = for_,vin ipairs(curTriv.ans) do
should be

Code: [Select]
local corrans = for _,v in ipairs(curTriv.ans) do
Since sdata is a criteria to contain something (elseif sdata then), this should be the problem

Offline Tw?sT?d-d?v

  • Lord
  • ***
  • Posts: 436
  • Karma: +79/-2
    • EURO-OP
Re: Trivia conversion error
« Reply #4 on: 21 October, 2007, 14:02:00 »
thx for the reply     i did change that but now i get this error on that line

Code: [Select]
Syntax Trivia-Ex-V.0.68b [New API].lua:385: unexpected symbol near 'for'
I guess ill leave this script for some1 more advanced in LUA b4 i mess script up completely

Offline CrazyGuy

  • Viking
  • ****
  • Posts: 506
  • Karma: +83/-20
    • ?????=-_The NightHawk_-=?????
Re: Trivia conversion error
« Reply #5 on: 21 October, 2007, 19:28:06 »
Code: [Select]
-----------------------------------
function TrivEx:ParseData(mode,curUser,data)
self._datamode = mode
data = string.sub(data,1,string.len(data)-1)
local _,_,sdata = string.find( data, "^%b<>%s(.*)$")
local _,_,cmd = string.find( data, "^%b<>%s["..self._Sets.prefixes.."](%w+)")
if cmd then
cmd = string.lower(cmd)
if self._Cmds[cmd] then
self._Cmds[cmd](self,curUser,data)
return true
end
elseif sdata then

-- changed part
local corrans  = nil
for _,v in ipairs(curTriv.ans) do
if string.lower(sdata) == string.lower(v) then
corrans = v
end
end
-- end changed part

if corrans and (not curTriv:GetGetQues()) then
-- SetGetQues
curTriv:SetGetQues(1)
local ansTime = string.format("%.2f",(os.clock()-curTriv.start)) -- Get Answering Time in sec.
if (TrivEx._Sets.showcorrectanswer == 1) then
-- Show right answer
local talked = nil
if string.lower(sdata) == string.lower(corrans) then
talked = corrans
end
if talked then
if (self:GetPlayMode() == "pm") then
self:SendToPlayers(data,curUser)
else
if TrivEx._Sets.maintoall then
Core.SendToAll("<"..curUser.sNick.."> "..corrans)
else
self:SendToPlayers(corrans,curUser)
end
end
self:SendToPlayers("Correct "..curUser.sNick..", the answer is \""..corrans.."\". You get "..curTriv.points.." Point(s). Answer solved in "..ansTime.." sec.")
-- Update Scores
if self._Scores[curUser.sNick] then
self._Scores[curUser.sNick].Score = self._Scores[curUser.sNick].Score + curTriv.points
self._Scores[curUser.sNick].AvTime[1] = self._Scores[curUser.sNick].AvTime[1] + ansTime
self._Scores[curUser.sNick].AvTime[2] = self._Scores[curUser.sNick].AvTime[2] + 1
self._Scores[curUser.sNick].AvTime[3] = tonumber(string.format("%.2f",self._Scores[curUser.sNick].AvTime[1]/self._Scores[curUser.sNick].AvTime[2]))
else
self._Scores[curUser.sNick] = {}
self._Scores[curUser.sNick].Score = curTriv.points
self._Scores[curUser.sNick].Streak = 1
self._Scores[curUser.sNick].AvTime = { tonumber(ansTime),1,tonumber(ansTime) }
end
if (self._Sets.showcorrectanswer == 1) then
self:SendToPlayers(curUser.sNick.."'s Stats, Score: "..self._Scores[curUser.sNick].Score.." Point(s), Answered Questions: "..self._Scores[curUser.sNick].AvTime[2]..", Average Answering Time: "..string.format("%.2f",self._Scores[curUser.sNick].AvTime[3]).." sec.")
end
-- Show other answeres if present
if curTriv.availans > 1 then
curTriv:ShowAnswer()
end
-- Check for Streak
curTriv.streak:UpdStreak(curUser)
return true
end
elseif (TrivEx._Sets.showcorrectanswer == 2) then
-- Show right answer
local talked = nil
if string.lower(sdata) == string.lower(corrans) then
talked = corrans
end
if talked then
if (self:GetPlayMode() == "pm") then
self:SendToPlayers(data,curUser)
else
if TrivEx._Sets.maintoall then
Core.SendToAll("<"..curUser.sNick.."> "..corrans)
else
self:SendToPlayers(corrans,curUser)
end
end
self:SendToPlayers("Correct "..curUser.sNick..", the answer is \""..corrans.."\". You get "..curTriv.points.." Point(s).")
-- Update Scores
if self._Scores[curUser.sNick] then
self._Scores[curUser.sNick].Score = self._Scores[curUser.sNick].Score + curTriv.points
self._Scores[curUser.sNick].AvTime[1] = self._Scores[curUser.sNick].AvTime[1] + ansTime
self._Scores[curUser.sNick].AvTime[2] = self._Scores[curUser.sNick].AvTime[2] + 1
self._Scores[curUser.sNick].AvTime[3] = tonumber(string.format("%.2f",self._Scores[curUser.sNick].AvTime[1]/self._Scores[curUser.sNick].AvTime[2]))
else
self._Scores[curUser.sNick] = {}
self._Scores[curUser.sNick].Score = curTriv.points
self._Scores[curUser.sNick].Streak = 1
self._Scores[curUser.sNick].AvTime = { tonumber(ansTime),1,tonumber(ansTime) }
end
if (self._Sets.showcorrectanswer == 1) then
self:SendToPlayers(curUser.sNick.."'s Stats, Score: "..self._Scores[curUser.sNick].Score.." Point(s), Answered Questions: "..self._Scores[curUser.sNick].AvTime[2]..", Average Answering Time: "..string.format("%.2f",self._Scores[curUser.sNick].AvTime[3]).." sec.")
end
-- Show other answeres if present
if curTriv.availans > true then
curTriv:ShowAnswer()
end
-- Check for Streak
curTriv.streak:UpdStreak(curUser)
return true
end
end
end
end
end
--------------------



Offline Tw?sT?d-d?v

  • Lord
  • ***
  • Posts: 436
  • Karma: +79/-2
    • EURO-OP
Re: Trivia conversion error
« Reply #6 on: 21 October, 2007, 19:43:24 »
Cool  nice 1 CG   

PtokaX forum

Re: Trivia conversion error
« Reply #6 on: 21 October, 2007, 19:43:24 »