Is there a way to increase a value when I run my game?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Is there a way to increase a value when I run my game?
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.
- 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?
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 120 times
/人 ◕‿‿◕ 人\
Here, have an umlaut. Ö
Here, have an umlaut. Ö
Re: Is there a way to increase a value when I run my game?
Exactly what I was looking for, thanks!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
Who is online
Users browsing this forum: Bing [Bot], Semrush [Bot] and 2 guests