help converting script plz - Page 2
 

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

help converting script plz

Started by Tw?sT?d-d?v, 04 March, 2005, 19:19:35

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Tw?sT?d-d?v

still geting the same error

Tw?sT?d-d?v

attempt to call global `GetTotalQues' (a nil value)

function Main() 
	for i,v in Scores do 
		if tonumber(Scores[i]) then 
		local num = Scores[i] 
			Scores[i] = {} 
		Scores[i].Score = num 
		Scores[i].Streak = 1 
		end 
			end 
			if TriviaConfig.TrivMainPM == 2 then 
			frmHub:RegBot(trivbot) 
				PMPlayers = {} 
				SendToAll(trivbotmyinfo) 
			dofile(TrivFolder.."/PMPlayers.txt") 
			table.table.foreach(PMPlayers,function(a,_) 
				if not GetItemByName(a) then 
				PMPlayers[a] = nil 
				end 
			end) 	
		else
		frmHub:UnregBot(trivbot)
		end
		curTriv.QuestionsTotal = GetTotalQues() 
		os.os.remove(TrivFolder.."/PMPlayers.txt") 
		SetTimer(10*1000) 
			if StartOnMain == 1 and (TriviaConfig.TrivMainPM == 1 or doCheckPlayers() == "PLAY") then 
			curTriv.GetQues = 1
			StartTimer() 
			GetQuestions(Max1) 
		end 
end


think it's this line

curTriv.QuestionsTotal = GetTotalQues()

6Marilyn6Manson6

#27
-- Converted the script into LUA 5 by 6Marilyn6Manson6
--------------------------------------------------------------------------------------- 
-- GLOBALS 
--------------------------------------------------------------------------------------- 
RevealChar = string.char(149) -- The revealchar: 149,164,1 
QFile = "TriviaEx.Questions-1.txt" -- The name of the Questionfile Questiondefaultstring.string.format = category$$questions$$answer)
TrivFolder = "TRIVIA" -- The name of the Folder, for the Questionfile. 
DivideChar = "%$%$" -- The Divied Char whitch divides the Category,Questions and Answer 
HowToGetQuestions = 1 -- Questions Mode 1 = Random, 2 = Linear (e.g. 1,2,3) 
-------------------------------------------- 
showPM = 1 -- 1 = Pm data from other players is seen, 2 = Pm data isn't seen 
-------------------------------------------- 
Max1 = 30 -- How many questions are loaded into Memory 
Max7 = 1 -- Trivia Break Time in math.minutes, between each question reload 
Trivbreak = 1 -- 1 = do a triviabreak between each reload, 2 == no triviabreak 
-------------------------------------------- 
Max2 = 30 -- Time between each hint in seconds 
Max4 = 15 -- Time in seconds between each question 
-------------------------------------------- 
Max3 = 100 -- The number of trivia scores shown 
Max9 = 10 -- Number of top trivias shown 
Max5 = 30 -- Time in math.minutes between each score and player saving 
-------------------------------------------- 
Max6 = 1 -- Smath.tands for how many chars are rvealed per hint. 
Max8 = 6 -- Smath.tands for how mayn Hints are displayed. This overruns Max6 (May not be totally accurate) 
-------------------------------------------- 
StartOnMain = 1 -- 1 = Trivia starts on Main(), 0 = Trivia doesn't start on Main() 
-------------------------------------------- 
TriviaConfig = { 
TrivMainPM = 1, -- 1 = Trivia is played in MainChat, 2 = Trivia is played in PM 
TrivSkip = 1, -- 1 = cmd11 enabled, 2 = disabled 
TrivHint = 1, -- 1 = cmd14 enabled, 2 = disabled 
TrivShowHint = 1, -- 1 = regular Hints, 2 = showing Maximal number of Hints (Max8) 
} 
dofile(TrivFolder.."/TriviaConfig.txt") 
----------------------------------------------------------------------------------------------------------------------
--// MAIN SCRIPT 
----------------------------------------------------------------------------------------------------------------------
tTrivQuestions = {} 
Scores = {} 
dofile(TrivFolder.."/Scores.dat") 
trivtimerset = { 0,0,0,0 } 
UnRevealed = {} 
curTriv = { 
GetQues = 0, 
Points = 0, 
curNum = 0, 
curCat = "", 
curQues = "", 
curAnswer = "", 
curHint = "", 
QuestionsTotal = 0, 
GetTotalQues = 0,
RevealHowMany = 0, 
LinearNum = 0, 
curStreak = { 
curNick = "", 
curStreak = 0, 
set = 0, 
}, 
} 
--------------------------------------------------------------------------------------- 
Max2 = Max2/10 
Max4 = Max4/10 
Max5 = Max5*6 
Max7 = Max7*6 
--------------------------------------------------------------------------------------- 
DisplTrivPrefix = string.gsub(TrivPrefix,"%%"," ") 
--------------------------------------------------------------------------------------- 
function Main() 
	for i,v in Scores do 
		if tonumber(Scores[i]) then 
		local num = Scores[i] 
			Scores[i] = {} 
		Scores[i].Score = num 
		Scores[i].Streak = 1 
		end 
			end 
			if TriviaConfig.TrivMainPM == 2 then 
			frmHub:RegBot(trivbot) 
				PMPlayers = {} 
				SendToAll(trivbotmyinfo) 
			dofile(TrivFolder.."/PMPlayers.txt") 
			table.table.foreach(PMPlayers,function(a,_) 
				if not GetItemByName(a) then 
				PMPlayers[a] = nil 
				end 
			end) 	
		else
		frmHub:UnregBot(trivbot)
		end
		curTriv.QuestionsTotal = GetTotalQues() 
		os.os.remove(TrivFolder.."/PMPlayers.txt") 
		SetTimer(10*1000) 
			if StartOnMain == 1 and (TriviaConfig.TrivMainPM == 1 or doCheckPlayers() == "PLAY") then 
			curTriv.GetQues = 1
			StartTimer() 
			GetQuestions(Max1) 
		end 
end 
--------------------------------------------------------------------------------------- 
function OnExit()
	WriteTable(Scores, "Scores", "Scores.dat") 
	if PMPlayers then 
	WriteTable(PMPlayers, "PMPlayers", "PMPlayers.txt") 
	end 
end 
--------------------------------------------------------------------------------------- 
function OnTimer() 
	if table.table.getn(tTrivQuestions) == 0 and Trivbreak == 1 and curTriv.GetQues == 1 then 
	GetQues = 3 
		trivtimerset[4] = 0 
			SendDataMP("Short Trivia break for "..(Max7/6).." math.min.") 
			end
			table.table.table.foreachi(trivtimerset, function(i,_) trivtimerset[i] = trivtimerset[i] + 1 end) 
				if trivtimerset[4] == Max7 and curTriv.GetQues == 3 then 
				curTriv.GetQues = 1 
				GetQuestions(Max1)
				end 
					if trivtimerset[3] >= Max5 then 
					trivtimerset[3] = 0 
					WriteTable(Scores, "Scores", "Scores.dat")
					end 
			if trivtimerset[2] >= Max4 and curTriv.GetQues == 1 then 
				trivtimerset[2] = 0 
				if table.table.getn(tTrivQuestions) == 0 then 
				GetQuestions(Max1)
			end 
				curTriv.curNum = tTrivQuestions[1][4] 
					curTriv.curCat = tTrivQuestions[1][1] 
						curTriv.curQues = tTrivQuestions[1][2] 
						curTriv.curAnswer = tTrivQuestions[1][3] 
						table.os.os.remove(tTrivQuestions,1) 
					curTriv.Points = 0 
						UnRevealed = {} 
			curTriv.curHint = string.gsub(curTriv.curAnswer,"(%S)",function (w) curTriv.Points = curTriv.Points + 1 return(RevealChar) end) 
			if TriviaConfig.TrivShowHint == 2 then 
				if ((curTriv.Points/Max8 - math.math.floor(curTriv.Points/Max8)) >= 0.5) then 
				curTriv.RevealHowMany = math.math.floor(curTriv.Points/Max8) + 1 
			elseif (math.math.floor(curTriv.Points/Max8) == 0) then 
				curTriv.RevealHowMany = 1 
			else 
					curTriv.RevealHowMany = math.math.floor(curTriv.Points/Max8) 
			end 
		else 
	curTriv.RevealHowMany = Max6 
end 
SendQuestion(curTriv.curCat,curTriv.curQues,curTriv.curHint,curTriv.Points,curTriv.curNum,curTriv.QuestionsTotal) 
	trivtimerset[1] = 0 
	curTriv.GetQues = 0 
end
	if trivtimerset[1] >= Max2 and curTriv.GetQues == 0 then 
		trivtimerset[1] = 0
		curTriv.curHint = RevealChars(curTriv.curAnswer,curTriv.curHint) 
		if curTriv.curAnswer ~= curTriv.curHint then 
	SendQuestion(curTriv.curCat,curTriv.curQues,curTriv.curHint,curTriv.Points,curTriv.curNum,curTriv.QuestionsTotal) 
			else 
			curTriv.GetQues,curTriv.curAnswer = 1,nil 
		SendDataMP("The right answer was: "..curTriv.curHint) 
				if curTriv.curStreak.curStreak >= 3 then 
				SendDataMP("There goes "..curTriv.curStreak.curNick.."'s streak of "..curTriv.curStreak.curStreak) 
				end 
					curTriv.curStreak.curNick,curTriv.curStreak.curStreak,curTriv.curStreak.set = "",0,0 
					trivtimerset = { 0,0,trivtimerset[3],0 } 
		end
	end
end

function DataArrival(curUser,data) 
	if (string.sub(data,1,1) == "<") then 
		if ParseData(curUser,data) == 1 then 
		return 1 
		end 
			elseif (TriviaConfig.TrivMainPM == 2 and string.sub(data,1,4) == "$To:") then 
			local _,_,whoTo,mes = string.find(data,"$To:%s+(%S+)%s+From:%s+%S+%s+$(.*)$") 
				if whoTo == trivbot then 
				ParseData(curUser,mes,1) 
				end 
			end 
end 

function NewUserConnected(curUser) 
	if TriviaConfig.TrivMainPM == 2 then 
	curUser:SendData(trivbotmyinfo) 
	end 
end 

OpConnected = NewUserConnected 

function UserDisconnected(curUser) 
	if TriviaConfig.TrivMainPM == 2 and PMPlayers[curUser.sName] then 
		PMPlayers[curUser.sName] = nil 
		if doCheckPlayers() ~= "PLAY" then 
			StopTimer() 
			curAnswer = nil 
				WriteTable(Scores, "Scores", "Scores.dat") 
		end 
	end 
end 

OpDisconnected = UserDisconnected 

function doCheckPlayers() 
	return(table.table.foreach(PMPlayers,function(a,_) 
		if a then 
			return("PLAY") 
		end 
	end)) 
end 

function ParseData(curUser,data,pm) 
	local _,_,sdata = string.find( data, "%b<>%s(.*)|$") 
	local _,_,cmd = string.find( data, "^%b<>%s["..TrivPrefix.."](%w+)") 
		if curTriv.curAnswer and string.lower(sdata) == string.lower(curTriv.curAnswer) then 
			SendDataMP("Correct "..curUser.sName.." the answer was \""..curTriv.curAnswer.."\", You get "..curTriv.Points.." Point(s).") 
			if Scores[curUser.sName] then 
				Scores[curUser.sName].Score = Scores[curUser.sName].Score + curTriv.Points 
			else 
				Scores[curUser.sName] = {} 
				Scores[curUser.sName].Score = curTriv.Points 
				Scores[curUser.sName].Streak = 1 
			end 
				SendDataMP("That gives you a total score of "..Scores[curUser.sName].Score.." Point(s).") 
					if (curTriv.curStreak.curNick ~= curUser.sName) then 
						if curTriv.curStreak.curStreak >= 3 then 
				SendDataMP("There goes "..curTriv.curStreak.curNick.."'s streak of "..curTriv.curStreak.curStreak) 
						curTriv.curStreak.curNick = curUser.sName 
						curTriv.curStreak.curStreak = 1 
						curTriv.curStreak.set = 1 
							else 		
						curTriv.curStreak.curNick = curUser.sName 
						curTriv.curStreak.curStreak = 1 
						curTriv.curStreak.set = 1 
						end 
							elseif (curTriv.curStreak.curNick == curUser.sName) then 
							curTriv.curStreak.curStreak = curTriv.curStreak.curStreak + 1 
								if curTriv.curStreak.curStreak > Scores[curUser.sName].Streak then 
									if curTriv.curStreak.set == 1 then 
				SendDataMP(curUser.sName..", you broke your current streak of "..Scores[curUser.sName].Streak..".") 
									curTriv.curStreak.set = 0 
								end 
									Scores[curUser.sName].Streak = curTriv.curStreak.curStreak 
							end 
						if curTriv.curStreak.curStreak >= 3 then 
						SendDataMP(curUser.sName..", that makes "..curTriv.curStreak.curStreak.." streaks in a row.") 
						end 
					end 
						trivtimerset = { 0,0,trivtimerset[3],0 } 
						curTriv.GetQues,curTriv.curAnswer = 1,nil 
						elseif cmd then 
							if TrivFuncs[string.lower(cmd)] then 
							SendDataMP(TrivFuncs[string.lower(cmd)](curUser),curUser) 
						return 1 
							elseif TrivConfs[string.lower(cmd)] then 
							local _,_,status = string.find( data, "^%b<>%s["..TrivPrefix.."]%w+%s+(%w+)") 
								if status and TrivConfs[string.lower(cmd)][string.lower(status)] then 
								SendDataMP(TrivConfs[string.lower(cmd)][string.lower(status)](curUser),curUser) 
								return 1 
						else 
							SendDataMP(TrivConfs[string.lower(cmd)].help,curUser) 
				return 1 
			end
		end 
		elseif pm and showPM == 1 then 
		SendDataMP(data,curUser,1) 
	end 
end 

function SendDataMP(data,curUser,sd) 
	if data then 
		if curUser then 
			if not sd then 
				if TriviaConfig.TrivMainPM == 2 then 
				curUser:SendPM(trivbot,data) 
			else 
			curUser:SendData(trivbot,data) 
		end 
		else 
			for i,_ in PMPlayers do 
				if i ~= curUser.sName and GetItemByName(i) then 
				GetItemByName(i):SendData("$To: "..i.." From: "..trivbot.." $"..data) 
				end 
			end 
		end 
			else 
				if TriviaConfig.TrivMainPM == 2 then 
				for i,_ in PMPlayers do 
				SendPmToNick(i,trivbot,data) 
			end 
			else 
				SendToAll(trivbot,data) 
			end 
		end 
	end 
end

Test it please, bye bye

Tw?sT?d-d?v

Hi m8  error again ......

68: bad argument #1 to `gsub' (string expected, got nil)

6Marilyn6Manson6

#29
Line 68 is ok i don't understand error.... because this line is LUA 4:

QuoteDisplTrivPrefix = gsub(TrivPrefix,"%%"," ")

and this in LUA 5:

QuoteDisplTrivPrefix = string.gsub(TrivPrefix,"%%"," ")

... but have error..... is it impossible

Tw?sT?d-d?v

no idea m8 .....    is there a hub i can get u in and ill give u all my triv folder (questions .ect...)

bastya_elvtars

TrivPrefix is nil. Post your file reading routine.
Everything could have been anything else and it would have just as much meaning.

remaster-it

?(
The script u r trying to convert to lua 5 is the

Trivia Ex   by chilla

Im getting simular probs  ?(

SMF spam blocked by CleanTalk