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
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.
can't it be put into hubaddmessage.lua inside the lua folder of robo ? it's an editable lua file... ???
If that part is uncompiled then yes it should be able to be added. I thought that bit was compiled. My bad.
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 :
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 :
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 :)
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.
I have made this infoline in the hubaddmessage:
info = info.." ? Trivia Topscorer:\t\t"..GetTopScorer().."\r\n"
And I made this function:
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 ;) )
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.
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 } )
Is there actually a . in the score files table name?
The file looks like this:
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:
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 :)
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 ???
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.
Aha I copied one line too much ;D
Works great now :P Thanxxx Rincewind
Not a problem. Pleased you got sorted :)