Trivia conversion error
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

Trivia conversion error

Started by Tw?sT?d-d?v, 20 October, 2007, 13:57:10

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Tw?sT?d-d?v

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

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


Which is from this line   

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
-----------------------------------
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
--------------------

bastya_elvtars

Please give titles to topics that are informative.
Everything could have been anything else and it would have just as much meaning.

Tw?sT?d-d?v

Ok sorry for that     Thx for editing  :)

Naithif

Above that line mistype.

This one
local corrans = for_,vin ipairs(curTriv.ans) do


should be

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

Tw?sT?d-d?v

thx for the reply     i did change that but now i get this error on that line

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

CrazyGuy

-----------------------------------
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
--------------------

Tw?sT?d-d?v


SMF spam blocked by CleanTalk