Trivia topscorer in hubaddmessage
 

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 topscorer in hubaddmessage

Started by Pieter, 04 November, 2006, 17:13:42

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Pieter

Hi everyone,
I'm using robocop 10.023 and trivia-ex 0.68 and i'd like to put the best trivia player into robo's hubaddmessage.
It should look inside the scorefile and take the nick of the player with the highest score from there, but I don't know enough about lua to make this piece of script by myself, can someone please help ?

Greetz Pieter

Rincewind

you'll not be able to get this into Robocop's hub add message as robocop is a compiled bot. What you could do is replicate the hub add message and disabl'e Robocops and then script the replacement o get your trivia top scorer.

Pieter

can't it be put into hubaddmessage.lua inside the lua folder of robo ? it's an editable lua file...  ???

Rincewind

If that part is uncompiled then yes it should be able to be added. I thought that bit was compiled. My bad.

Pieter

#4
QuoteIf that part is uncompiled then yes it should be able to be added.
I'm glad to hear that it's at least possible Rincewind ;)

Do you also know how i should make the piece of script ?

The robo hubaddmessage.lua looks like this :

Code: lua
SendAdMessage = function()
	local weeks,days,hours,minutes,seconds = GetUptimeSeconds(frmHub:GetUpTime())
	local name,version = getHubVersion()
	local info = "\r\n\r\n"
	info = info.."  ================================\r\n"
	info = info.."  ? Hub Information:\r\n"
-- shortened it a little ;-)
	info = info.."  ================================\r\n"
	SendToAll(tSettings.sBot, info)
end


The scorefile TriviaExScores.txt looks like this :

Code: lua
TrivEx._Scores = {
	["Pieter"] = {
		["Streak"] = 1,
		["Score"] = 19,
		["AvTime"] = {
			[2] = 2,
			[1] = 18,
			[3] = 9,
		},
	},
--here are the other players
}


Hope you (or someone else) can help  :)

Rincewind

Adding something like
dofile("topscorer.txt")
local topscore,topscorer = 0,""
for i,v in pairs(TrivEx_Scores) do
	if v.Score > topscore then
		topscore = v.Score
		topscorer = i
	end
end

would get the top scorer that you can then add into the info string.

Pieter

I have made this infoline in the hubaddmessage:
Code: lua
info = info.."	? Trivia Topscorer:\t\t"..GetTopScorer().."\r\n"

And I made this function:
Code: lua
GetTopScorer = function()
	dofile("C:\\Ptokax\\scripts\\TRIVIA\\TriviaExScores.txt")
	local topscore,topscorer = 0,""
	for i,v in pairs(TrivEx_Scores) do
		if v.Score > topscore then
			topscore = v.Score
			topscorer = i
		end
	end
end


Now I get a syntax error : TriviaExScores.txt:38: attempt to index global 'TrivEx' (a nil value)
Line 38 is the line "for i,v in pairs(TrivEx._Scores) do"

What have I done wrong  ???  (don't know much about it so it can be a very stupid mistake  ;) )

Rincewind

It would look from the error line
Quote"for i,v in pairs(TrivEx._Scores) do"
that the code you posted is not quite right. The ipairs in the code did not have a . after TrivEx but the error line does.

Pieter

Made a typing fault in my post, sorry  ;) 
It's without the dot, same as in the piece of code I posted above it
Posted on: 09 November 2006, 22:51:13
I see I said something wrong  :-[
TriviaExScores.txt:38: attempt to index global 'TrivEx' (a nil value)
The error in line 38 is not from the lua file but from the score file, it is the last line of the file.
In my previous post you can see how the file ends ( with a } )

Rincewind

Is there actually a . in the score files table name?

Pieter

#10
The file looks like this:
Code: lua
TrivEx._Scores = {
	["Pieter"] = {
		["Streak"] = 1,
		["Score"] = 19,
		["AvTime"] = {
			[2] = 2,
			[1] = 18,
			[3] = 9,
		},
	},
--here are the other players
}


I guess TrivEx._Scores is the table name, and that's with a . indeed

Posted on: 12 November 2006, 10:34:21
I tried a few things this weekend ;D
To prevent the previous error i've added a few lines from the trivia script. ( is this correct ?)
Also I changed the table name, added the .  (same as in the scoresfile)

I've made this script now:

Code: lua
TrivEx = {}
TrivEx._Scores = {}

GetTopScorer = function()
dofile("C:\\Ptokax\\scripts\\TRIVIA\\TriviaExScores.txt");
	local topscore,topscorer = 0,""
	for i,v in pairs(TrivEx._Scores) do
		if v.Score > topscore then
			topscore = v.Score
			topscorer = i
		end
	end
end


But now it gives syntax error hubaddmessage.lua:22: attempt to concatenate a nil value
I guess this means that the function does not give any output  :(
How do I get output from the function ?

Posted on: 13 November 2006, 21:33:33
Just found out that return topscorer works  :)

Code: lua
TrivEx = {}
TrivEx._Scores = {}

GetTopScorer = function()
dofile "C:\\Ptokax\\scripts\\TRIVIA\\TriviaExScores.txt");
	local topscore,topscorer = 0,""
	for i,v in pairs(TrivEx._Scores) do
		if v.Score > topscore then
			topscore = v.Score
			topscorer = i
		end
	end
	return topscorer
end


It gives the correct topscorer now but there is one problem:
it deletes everybody from the trivia scorefile when I exit ptokax   :o ???

Rincewind

#11

TrivEx._Scores = {}
is blanking the score table and I assume that there is a write of the table on script exit which is why your table gets blanked.

Pieter

Aha I copied one line too much  ;D

Works great now  :P  Thanxxx Rincewind

Rincewind

Not a problem. Pleased you got sorted  :)

SMF spam blocked by CleanTalk