Hey @dave1707 - you’re right in that I found what was ‘nil’
I checked the variable and it is correct. No ‘nil’ or undefined in the score or highscore.
But where the problem is, is in the code that takes the highscore and breaks it down into the individual numbers. it is the ‘.’ as the highscore code doesn’t have something to deal with the ‘.’ Character. By writing in a piece to detect the decimal place I’ve substituted it with a zero character and it shows no problem. The full stop was the ‘nil’ part as scores never used to save with a decimal.
So what I need now is for the number not to write the decimal place and the number below a full number or not to read it as it is a whole score. Or I need to leave off the last two characters.
So a score like 32000 needs to stay 32000 and not 32000.0 as is currently being saved.
So currently this adding two zeroes to the score - so 32000.0 is becoming 3200000 and I don’t want that.
Is the decimal a new thing in a recent version of codea? I have to admit the score code was last run two years ago and so the numbers then were either whole or they were ignored previously.
Below is my code and I’ve annotated the bit I corrected
Scoretime = class()
function Scoretime:init(typ)
--note how you have to set each of the ten key-value pairs in this case
-- no need to put the Documents:num prefix on all of them
-- we can do it later, below
--check I have all the quotes correctly placed
self.typ=typ
self.va=score
self.pos=scalerX*45
self.Num = {["0"]="Zero",["1"]="One",["2"]="Two",["3"]="Three",
["4"]="Four",["5"]="Five",["6"]="Six",["7"]="Seven",
["8"]="Eight",["9"]="Nine",
["."]="Zero" -- this is the part I added to correct the 'nil'
}
end
function Scoretime:draw()
if self.typ==1 then self.va=score
self.pos=scalerX*-5
else self.va=highscore
self.pos=scalerX*50
end
for i=1,string.len(self.va)do
local d=string.sub(self.va,i,i) --d contains a digit like "4"
--now we add the Documents:num prefix to the number
if sz==0 then
scoreplace=scalerX*22
--[[if score<10 then scoreplace=scalerX*25
elseif score>9 and score<100 then scoreplace=scalerX*35
elseif score>99 and score<1000 then scoreplace=scalerX*35
elseif score>999 and score<10000 then scoreplace=scalerX*35
elseif score>9999 and score<100000 then scoreplace=scalerX*35
end]]--
sprite("Project:num"..self.Num[d],scoreplace+i*scalerX*3.75+self.pos,scalerY*95+yyy,scalerX*5,scalerY*5)
else
if self.va<10 then scoreplace=scalerX*13+self.pos
elseif self.va>9 and self.va<100 then scoreplace=scalerX*11+self.pos
elseif self.va>99 and self.va<1000 then scoreplace=scalerX*9+self.pos
elseif self.va>999 and self.va<10000 then scoreplace=scalerX*7+self.pos
elseif self.va>9999 and self.va<100000 then scoreplace=scalerX*5+self.pos
end
sprite("Project:num"..self.Num[d],scoreplace+i*scalerX*2.5+self.pos,soy+yyy,scalerX*10,scalerY*10)
end
end
end
Thanks