Page 1 of 1

Is there a way to increase a value when I run my game?

Posted: Fri Jun 26, 2015 5:16 pm
by ccde
Is there a way I can increase a variable in my game each time I run the game? I want to add a kind of dynamic build number for each time I run the game, but I can't find out a way to increase the value by x amount each time I run the game.

Re: Is there a way to increase a value when I run my game?

Posted: Fri Jun 26, 2015 5:58 pm
by CrackedP0t
Each variable in your game will be reset each time you launch it, so you'll have to keep track in a file. Something like this:

Code: Select all

function love.load()
	timesRun = love.filesystem.read("track.txt") or 0
	timesRun = timesRun + 1
	love.filesystem.write("track.txt", timesRun)
end

function love.draw()
	love.graphics.print(timesRun)
end

Re: Is there a way to increase a value when I run my game?

Posted: Fri Jun 26, 2015 7:06 pm
by ccde
CrackedP0t wrote:Each variable in your game will be reset each time you launch it, so you'll have to keep track in a file. Something like this:

Code: Select all

function love.load()
	timesRun = love.filesystem.read("track.txt") or 0
	timesRun = timesRun + 1
	love.filesystem.write("track.txt", timesRun)
end

function love.draw()
	love.graphics.print(timesRun)
end
Exactly what I was looking for, thanks!