[LUA 5] need help with saving scores
 

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

[LUA 5] need help with saving scores

Started by ruler, 26 March, 2005, 22:43:54

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

ruler

hi
i have a Phrase-o-Rama game script and i have converted all eccept this one function...

function dowritescores()
   writeto("por/porscores.txt","w")
   write("1&"..topscores[1][2].."$"..topscores[1][1])
   writeto()
   for i = 2,table.getn(topscores),1 do
   appendto("por/porscores.txt")
   write("\n"..(i).."&"..topscores[2].."$"..topscores[1])
   writeto()
   end
end

can anyone convert this one section to work in LUA 5 please. Its a great script and would be a shame to lose it. i know its only just a function but i can post the rest if needed. any great scripters willing to take on the challenge  :D

best regards

The Direct Connect Global Banlist get protected.

Herodes

#1
try this one ...
function dowritescores()
	local f = io.open ( "por/porscores.txt", "w" )
	if f then
		local m = "1&"..topscores[1][2].."$"..topscores[1][1]
		for i = 2,table.getn(topscores),1 do
			m = m.."\n"..(i).."&"..topscores[i][2].."$"..topscores[i][1]
		end
		f:write(m)
		f:close()
	end
end

ruler

i gave that a go but was getting an error because of the ')' at the end of line...
m = m.."\n"..(i).."&"..topscores[2].."$"..topscores[1])

i tried it and got no errors but it still doesnt save the scores.

The Direct Connect Global Banlist get protected.

Herodes

I was using a wrong io way...

try grabbing it again,... it should work now..
above post edited

ruler

yes, yes, yes it works  :D
cant thank you enough. great work.
here is the complete code of what i was editing (its the Phrase-O-Rama game...

Bot = frmHub:GetHubBotName()
phraselists = {
"Common Phrases",
"On The Map",
"horror movies",
"comedy movies",
"western movies",
"disaster movies",
"science-fiction movies",
"music",
"famous actors",
"famous actress",
"US Presidents",
"McDonalds Menu",
"Periodic Table",
--"Top 100 Movies",
"Top 100 Video Games",
--"Billboard Top 100 Of The 80s",
--"Billboard Top 100 Of The 90s",
"TV Shows",
--"Current Top 100 Scifi-Fantasy Books",
--"1997-2000 Licensed Anime",
--"Expanded Star Wars",
}
topscores = {}
timer = 5000
answer = ""
remainscore = 0
gameon = "off"
phrasenumbers = {}
startingphrase = 1

function Main()
SetTimer(timer)
doreadscores()
doreadphrases()
donewphrase()
if gameon == "on" then StartTimer() end
end
function ChatArrival(curUser, Data)
s,e,cmd = string.find(Data,"%b<>%s(%S+)")
s,e,scored = string.find(Data,"%b<>%s%S+%s+(%d+)")
s,e,mess = string.find(Data, "%b<>%s+(.*)")
   if cmd == "+startgame|" then
   dostartgame(curUser)
   elseif cmd == "+stopgame|" then
   dostopgame(curUser)
   elseif cmd == "+scores|" then
   displayscores(curUser)
   elseif cmd == "+porhelp|" then
   dohelp(curUser)
   elseif cmd =="+skip|" then
   doskipphrase(curUser)
   return 1
   elseif cmd == "+myscore|" then
   domyscore(curUser)
   end
   ---------
   if mess ~= nil and answer ~= "?" then
   mess = string.gsub(mess,"%A","")
   ants = string.gsub(answer,"%A","")
   if string.find(string.lower(mess),string.lower(ants)) ~= nil then
   addtoscore(curUser,remainscore)
   answer, startingphrase = donewphrase()
   end
   end
end
function OnTimer()
doreveal()
end

function donewphrase()
doreadphrases()
answer = phrases[math.random(1,table.getn(phrases))]
startingphrase = 1
remainscore = math.random(2,8)
bigscore = math.random(2,16) if bigscore == 14 then remainscore = 15 end
e,f = string.gsub(answer,"%a","")
timer = 120 / f * 1000
SetTimer(timer)
return answer,startingphrase
end

function doreveal()
if startingphrase == 1 then testing = string.gsub(answer,"%a","?"); startingphrase = 0; SendToAll(Bot,"This Phrase will be worth "..remainscore.." per unrevealed letter plus 5 points for solution. ANYONE CAN PLAY!") SendToAll(Bot, " Avalible Commands are +scores  and  +myscore"); end
t,p = string.gsub(testing,"?","")
if p < 2 then
SendToAll(Bot,"The Answer Was: "..answer)
donewphrase()
else
curnumber = burp()
testing = string.sub(testing,1,curnumber-1)..string.sub(answer,curnumber,curnumber)..string.sub(testing,curnumber+1,string.len(testing))
SendToAll(Bot,"[Category: "..phrasename.."]   "..testing)
end
end

function burp()
curnumber = math.random(1,string.len(answer))
if string.sub(testing,curnumber,curnumber) ~= "?" then burp() end
return curnumber
end


function dostartgame(curUser)
if gameon == "off" then
gameon = "on"
donewphrase()
StartTimer()
SendToAll(Bot, curUser.sName.." Has Started The Quiz!")
end
end

function dostopgame(curUser)
if gameon == "on" then
gameon = "off"
SendToAll(Bot, curUser.sName.." Has Ended the Quiz :(")
SendToAll(Bot,"The Answer Was: "..answer)
StopTimer()
answer = "?"
remainscore = 0
dowritescores()
end
end

function displayscores(curUser)
   curUser:SendData(Bot,"-----------------------------------------------")
   curUser:SendData(Bot,"Top 10 Phrase-O-Rama Player")
   curUser:SendData(Bot,"-----------------------------------------------")
   table.sort(topscores, function(a,b) return a[1]>b[1] end)
   total = 10
   if table.getn(topscores) < total then total = table.getn(topscores) end
      for i = 1,total,1 do
      curUser:SendData(Bot,"["..i.."] "..topscores[2].." - "..topscores[1])
      end
   curUser:SendData(Bot,"-----------------------------------------------")
end

function addtoscore(curUser,remainscore)
   dude = table.getn(topscores)+1
   oldscore = 0
   for i = 1,table.getn(topscores),1 do
   if topscores[2] == curUser.sName then
   dude = i
   oldscore = topscores[1]
   break
   end
   end
   a,b = string.gsub(testing,"?",".")
   topscores[dude] = {(b*remainscore)+oldscore+5,curUser.sName}
   dowritescores()
   table.sort(topscores, function(a,b) return a[1]>b[1] end)
      for i = 1,table.getn(topscores),1 do
      if topscores[2] == curUser.sName then
      place = ""
      SendToAll(Bot,curUser.sName.." Got It!! The Answer Was: "..answer)
      SendToAll(Bot,curUser.sName.." has been awarded "..((b*remainscore)+5).." points!")
      if i == 1 then place = "st champ!" end
      if i == 2 then place = "nd place" end
      if i == 3 then place = "rd place" end
      if i == 4 or i == 5 or i == 6 or i == 7 or i == 8 or i == 9 or i == 10 then place = "th place" end

      SendToAll(Bot,"[ "..i..place.." ] "..topscores[2].." - ".."Total score [ "..topscores[1].." ]")
      end
      end
end

function dowritescores()
   local f = io.open ( "por/porscores.txt", "w" )
   if f then
      local m = "1&"..topscores[1][2].."$"..topscores[1][1]
      for i = 2,table.getn(topscores),1 do
         m = m.."\n"..(i).."&"..topscores[2].."$"..topscores[1]
      end
      f:write(m)
      f:close()
   end
end

function doreadscores()
   A=1
   for line in io.lines("por/porscores.txt") do
   if line == nil then break end
   s,e,rank,unick,score = string.find(line,"(%S+)&(%S+)$(%S+)")
   topscores[tonumber(A)] = {tonumber(score),unick}
   A = A+1
   end
A = nil
end

function doreadphrases()
   phrases = {}
   phrasename = phraselists[math.random(1,table.getn(phraselists))]
   t = 1
   for line in io.lines("por/"..string.lower(phrasename)..".txt") do
      if line == nil then break end
               phrases[t] = line
      t = t+1
   end
end

function dohelp(curUser)
   curUser:SendData(Bot, "Phrase-O-Rama Help")
   curUser:SendData(Bot, "+scores         Displays Top 10 Phrase-O-Rama Scores")
   curUser:SendData(Bot, "+myscore      Displays your Phrase-O-Rama Rank/Score")
   curUser:SendData(Bot, "+porhelp      Displays Phrase-O-Rama Help")
   if curUser.bOperator then
   curUser:SendData(Bot, "+startgame      Begins Phrase-O-Rama Game")
   curUser:SendData(Bot, "+stopgame      Stops Phrase-O-Rama Game")
   curUser:SendData(Bot, "+skip         Skips the Current Phrase")
   return 1
   end
end

function domyscore(curUser)
   table.sort(topscores, function(a,b) return a[1]>b[1] end)
      for i = 1,table.getn(topscores),1 do
      if topscores[2] == curUser.sName then
      curUser:SendData(Bot,"Rank ["..i.."] "..topscores[2].." - "..topscores[1])
      break
      end
      end
end

function doskipphrase(curUser)
   if curUser.bOperator then
   SendToAll(Bot,curUser.sName.." has Skipped this phrase.")
   SendToAll(Bot,"No Points Awarded This Round.")
   SendToAll(Bot,"The Answer was: "..answer)
   donewphrase()
   end
end

obviously i havent included the text files needed but this is the heart of the script and now works 100% with your help.
thank you Herodes, great stuff

best regards

The Direct Connect Global Banlist get protected.

Herodes

QuoteOriginally posted by ruler
thank you Herodes, great stuff
best regards
you're welcome,.. although you should put your code inside ( no space after the '[' so it works.. )
[ code]
-- code here
[ /code]

and also more important dont leave out the credits of the script if you are modifying one ... this is frustrating to the creator, unless thats your intention, put the credits in there ;) ...

ruler

i dont actually know who wrote this script because there were no credits at the top when i first got it but it is a great script. i do have a few good scripts with no credits at the top and even i find this anoying cos sometimes i try to find if the creator has made a newer version.anyway, i'm sure they will be pleased to know that their work is still being used and enjoyed by many  :))
thanks again

The Direct Connect Global Banlist get protected.

Herodes

If you want to find the author of a script, you could search the board for a start:

--// Phrase-O-Rama Script
--// By Chaggydawg
--// Version 0.3b

this is what I got from digging in plop's site...

SMF spam blocked by CleanTalk