Well it seems that I was beeing stupid, and thought it was writting the data to the data.txt that is inside my game's folder, beeing a custom path
after reading the return of love.filesystem.getSaveDirectory(), the data.txt is just there, in appdata/roaming/LOVE/Balloon_adventure ; and successfuly wrote on...
i t w o r k e d a l l a l o n g....................
well now that It works it was just me beeing stupid, to read the data.txt and assign the values to their respective variables (bestscore, coins)
i just gotta use love.filesystem.read() right?
Anotther difficulty
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: Anotther difficulty
A coding begginer that is migrating from 8 years of Scratch... yea yikes.
- BrotSagtMist
- Party member
- Posts: 612
- Joined: Fri Aug 06, 2021 10:30 pm
Re: Anotther difficulty
If you have the \n part in table.concat you can use readline for each entry.
obey
Re: Anotther difficulty
Oh thanks! and yes I used your method without any libraries, im gonna tinker things around and if it works I'm gonna post my solution here, so other people that may have my problem have the solution
A coding begginer that is migrating from 8 years of Scratch... yea yikes.
Re: Anotther difficulty
Code: Select all
local highscores={}
for line in love.filesystem.lines("data.txt") do
table.insert(highscores, line)
end
bestscore=highscores[1]
coins=highscores[2]
Code: Select all
function newGameState(x)
if x == "Menu" then
GameState = "Menu"
score = 0
coins = 0
scoretimer = 0
elseif x == "Play" then
GameState = "Play"
elseif x == "Death" then
GameState = "Death"
Player.x = 300
Player.y = 500
if score > bestscore then
bestscore = score
saveScore()
end
end
end
A coding begginer that is migrating from 8 years of Scratch... yea yikes.
- BrotSagtMist
- Party member
- Posts: 612
- Joined: Fri Aug 06, 2021 10:30 pm
Re: Anotther difficulty
table.insert(highscores, tonumber(line))
Sometimes lua can use strings as they where numbers or vise verca, sometimes it can not.
When in doubt you need to explicitly call tonumber/tostring on values.
Sometimes lua can use strings as they where numbers or vise verca, sometimes it can not.
When in doubt you need to explicitly call tonumber/tostring on values.
obey
Re: Anotther difficulty
]Thanks to all of you, my saving and loading system works perfectly.
codes:
loads the save in love.load()
saves the game
in my gamestates.lua, if you die, it checks if you did a best score, and proceeds to save
The priority in my score system is seconds, you may have 5 coins in a 50seconds run, but if you have a 55 seconds run with 0 coins, that 55seconds run will be the one saved
codes:
loads the save in love.load()
Code: Select all
local highscores={}
for line in love.filesystem.lines("data.txt") do
table.insert(highscores, tonumber(line))
end
bestscore=highscores[1]
coins=highscores[2]
Code: Select all
function saveScore()
local ScoreData={bestscore, coins}
love.filesystem.write("data.txt", table.concat(ScoreData,"\n"))
end
Code: Select all
function newGameState(x)
if x == "Menu" then
GameState = "Menu"
score = 0
coinsCollected = 0
scoretimer = 0
elseif x == "Play" then
GameState = "Play"
elseif x == "Death" then
GameState = "Death"
Player.x = 300
Player.y = 500
if score > bestscore then
bestscore = score
coins = coinsCollected
saveScore()
end
end
end
A coding begginer that is migrating from 8 years of Scratch... yea yikes.
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot] and 58 guests