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

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
ccde
Prole
Posts: 15
Joined: Sun Dec 29, 2013 10:47 pm

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

Post 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.
User avatar
CrackedP0t
Citizen
Posts: 69
Joined: Wed May 07, 2014 4:01 am
Contact:

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

Post 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
Attachments
track.love
(562 Bytes) Downloaded 113 times
/人 ◕‿‿◕ 人\
Here, have an umlaut. Ö
ccde
Prole
Posts: 15
Joined: Sun Dec 29, 2013 10:47 pm

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

Post 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!
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 73 guests