I haven't used forum help for a while, so I believe I have the permission to do that!
)
Im trying to save a players progress, but the score isn't being displayed. It should show on the screen "Money:" but there aren't any type of text like that. Here is my code:
local function loadScore()
local file = io.open("|D|settings.txt","r")
if not file then
score = 0
else
score=tonumber(file:read("*line"))
file:close()
end
end
local function saveScore()
local file=io.open("|D|settings.txt","w+")
file:write(score .. "\n")
file:close()
end
local function initScores()
local score = 0
local scoreText = TextField.new(nil, "Money: " .. score)
scoreText:setPosition(10,10)
stage:addChild(scoreText)
end |
Why the problem occurs? It seems everything fine, there aren't any erros displayed on the output. So I was wondering, this problem occurs because of "local function initScores()". Because when I am creating a simple textField, it is displayed very well. And there are 1 more problem. Why does the text field is showed in the different places of the screen? For example, text field on 320x480 screen resolution is being displayed in the corner, on my LG K10 the text is being displayed in the different position. The main position is (10,10), but on my phone the text is being showed like (30,10).
Thank you for your time!
Comments
1-This forum's sole purpose is to share experience and ask questions. So you are more than welcome to ask any question here. But just to keep in mind that before asking any question a little forum search will be perfect
2-Have you tried to print the score parameter. Maybe it is coming empty from the loadscore function. Because in your explanation as far as i understand normal textfield is working.
3-About your position question. In the project properties 320x480 is your logical resolution. Which means that your ccordinates will change if your target device resolution is different from this one according to your chosen algorithm. (Pixel perfect, Stretch etc..)
If you want no change at all than you need to set Scale Mode to "No Scale".
By the way if you will read and experiment these you will understand better.
http://docs.giderosmobile.com/automatic_image_resolution.html
http://docs.giderosmobile.com/automatic_screen_scaling.html
Likes: tytadas
Maybe unrelated but a few comments:
- You will probably need to update the score at some point in the TextField, but since you declare it local in your 'initScores' function it will be difficult to retrieve its instance later on for a scoreText:setText()
- Could it be that something else is drawn over your TextField, for example a background added to the stage after initScores is called ?
Likes: tytadas
@talis, Yeah, I should definately read next time. Literally it's really complicated to me to understand these hard understandable words, but I'll make it out. Thank you for the explanation about the position question. I know how to scale images and until this point im doing it great. I haven't tried to print the score parameter, cause I don't know how to do that
@hgy29, I just declared it in initScores cause I have read the book and as I understood, it initalizats the score. How to make it simpler? Nop, the code is at the begining and it starts on line 1.
Maybe it's because I haven't declared when the score should be added? Cause I need to make a function when the bird is touched it gives +1 score and I havent called this function so maybe because of that the score isn't being showed?
if this is all of your code, i may guess that you're missing the call to
Basic fix is to remove local before scoreText, so you make it global and accessible from anywhere inside your code.
Likes: tytadas
If so you should at least call initScores() somewhere if you want your TextField to appear.
EDIT: @pie was faster
Likes: tytadas
When you write
the same applies to any function (ie. loadScore() and saveScore() )
Likes: tytadas