Saving

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.
Jordan4762
Prole
Posts: 13
Joined: Thu Oct 14, 2010 10:25 pm

Saving

Post by Jordan4762 »

How Would I Fix This?

Code: Select all


if love.keyboard.isDown("s") and love.keyboard.isDown("lctrl") then 
love.filesystem.setIdentity("4762games") 
success = love.filesystem.write( "4762games/platformer", highscore , 100 ) 
contents, size = love.filesystem.read( "4762games/platformer" , 100 ) 
end 

Yea, Ive Never Tried Saving Before
- Jordan4762
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Saving

Post by Robin »

1) You only need to use love.filesystem.setIdentity("4762games") once in your game, usually in love.load.

2) Try this: (untested)

Code: Select all

if love.keyboard.isDown("s") and love.keyboard.isDown("lctrl") then  -- assuming you set the identity in love.load
    love.filesystem.write( "platformer", tostring(highscore)) -- no need for the third parameter
    --  is highscore a number or a string?
end 
Hope this helps.
Help us help you: attach a .love.
Jordan4762
Prole
Posts: 13
Joined: Thu Oct 14, 2010 10:25 pm

Re: Saving

Post by Jordan4762 »

You Confused Me....

Heres A Download:
http://dl.dropbox.com/u/12564788/Love2D ... r/main.lua

Heres The Whole Code:

Code: Select all

function love.load() 
movingobject = "O" --love.graphics.newImageData("Explosion fire texture.png") 
x = 50 
y = 50 
speed = 100 
end 

score = 0 
highscore = score 

obj = "()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()" 
posx = -100 
posy = 600 
negativedistx = posx-(string.len(obj)/5) 
positivedistx = posx+(string.len(obj)*5) 
negativedisty = posy+10 
positivedisty = posy-10 
inactive = 5 
d = false 
t = {} 
pause = false 
help = false 

function love.update(dt) 

if love.keyboard.isDown("p") then 
if pause == false then 
pause = true 
end 
elseif 
pause == true then 
pause = false 
end 

if love.keyboard.isDown("c") and love.keyboard.isDown("lctrl" or "rctrl") then
score = score + 1000
highscore = score
end

--Highscore saving? Dont Know How...
--[[

if love.keyboard.isDown("s") and love.keyboard.isDown("lctrl") then
love.filesystem.setIdentity("4762games")
success = love.filesystem.write( "4762games/platformer", highscore , 100 )
contents, size = love.filesystem.read( "4762games/platformer" , 100 )
end

]]--

if love.keyboard.isDown("h") then 
if help == false then 
help = true 
end 
elseif 
help == true then 
help = false  
end 

if love.keyboard.isDown("right") or love.keyboard.isDown("d") then 
if pause == true then return end 
inactive = "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 
speed = 100 

for i,v in pairs(t) do 
collideplatforms = tonumber(string.len(string.sub(v,string.find(v,"|")+1,string.len(v)))) 
xpoint = tonumber(string.sub(v,4,string.find(v,"/")-1)) 
ypoint = tonumber(string.sub(v,string.find(v,"/")+1,string.find(v,"|")-1)) 
positivexpoint = xpoint+(collideplatforms*5) 
negativexpoint = xpoint-(collideplatforms*5) 
positiveypoint = ypoint-10 
negativeypoint = ypoint+10 

if y <= 800 and y >= 0 and x >= 800 then 
x = 10 
end 

if x >= negativedistx and x <= positivedistx and y >= positivedisty and y <= negativedisty or x >= negativexpoint and x <= positivexpoint and y >= positiveypoint and y <= negativeypoint then 
speed = 0 
if d == false then 
d = true 
end 
end 
end 

x = x + (speed * dt) 
movingobject = ">" 

elseif love.keyboard.isDown("left") or love.keyboard.isDown("a")then 
if pause == true then return end 
speed = 100 
inactive = "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 

for i,v in pairs(t) do 
collideplatforms = tonumber(string.len(string.sub(v,string.find(v,"|")+1,string.len(v)))) 
xpoint = tonumber(string.sub(v,4,string.find(v,"/")-1)) 
ypoint = tonumber(string.sub(v,string.find(v,"/")+1,string.find(v,"|")-1)) 
positivexpoint = xpoint+(collideplatforms*5) 
negativexpoint = xpoint-(collideplatforms*5) 
positiveypoint = ypoint-10 
negativeypoint = ypoint+10 

if y <= 800 and y >= 0 and x <= 0 then 
x = 790 
end 

if x <= positivedistx and x >= negativedistx and y >= positivedisty and y <= negativedisty or x >= negativexpoint and x <= positivexpoint and y >= positiveypoint and y <= negativeypoint then 
speed = 0 
if d == false then 
d = true 
end 
end 
end 
x = x - (speed * dt) 
movingobject = "<" 
end 


if love.keyboard.isDown("down") or love.keyboard.isDown("s")then 
if pause == true then return end 
inactive = "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 
speed = 100 

for i,v in pairs(t) do 
collideplatforms = tonumber(string.len(string.sub(v,string.find(v,"|")+1,string.len(v)))) 
xpoint = tonumber(string.sub(v,4,string.find(v,"/")-1)) 
ypoint = tonumber(string.sub(v,string.find(v,"/")+1,string.find(v,"|")-1)) 
positivexpoint = xpoint+(collideplatforms*5) 
negativexpoint = xpoint-(collideplatforms*5) 
positiveypoint = ypoint-10 
negativeypoint = ypoint+10 

if x >= negativedistx and x <= positivedistx and y >= positivedisty and y <= negativedisty or x >= negativexpoint and x <= positivexpoint and y >= positiveypoint and y <= negativeypoint then 
speed = 0 
if d == false then 
d = true 
end 
end	
end 
y = y + (speed * dt) 
movingobject = "v" 
elseif love.keyboard.isDown("up") or love.keyboard.isDown("w") then 
if pause == true then return end 
inactive = "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 
speed = 100 

for i,v in pairs(t) do 
collideplatforms = tonumber(string.len(string.sub(v,string.find(v,"|")+1,string.len(v)))) 
xpoint = tonumber(string.sub(v,4,string.find(v,"/")-1)) 
ypoint = tonumber(string.sub(v,string.find(v,"/")+1,string.find(v,"|")-1)) 
positivexpoint = xpoint+(collideplatforms*5) 
negativexpoint = xpoint-(collideplatforms*5) 
positiveypoint = ypoint-10 
negativeypoint = ypoint+10 

if y <= 10 and x >= 0 and x <= 800 then 
y = 10 
end 

if x >= negativedistx and x <= positivedistx and y <= negativedisty and y >= positivedisty or x >= negativexpoint and x <= positivexpoint and y >= negativeypoint and y <= positiveypoint then 
speed = 0 
if d == false then 
d = true 
end 
end 
end 
y = y - (speed * dt) 
movingobject = "^" 
end 
if love.keyboard.isDown("r") then 
x = 50 
y = 50 
d = false 
score = 0 
movingobject = "O" 
inactive = "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 
end 
end 

function love.draw() 
love.graphics.print(movingobject, x, y) 
love.graphics.print(obj, posx, posy) 
love.graphics.print("Score: "..math.ceil(score), 600, 550) 
love.graphics.print("Highscore: "..math.ceil(highscore), 600, 500) 
love.graphics.print("Jordan4762's Platformer Game ... =D",500,580) 
if pause == true then return end 
if d == true then 
love.graphics.print([[You Died, press "R" to respawn.]], 200, 300) 
end 

inactive = string.sub(inactive,1,string.len(inactive)-1) 

love.graphics.print("Inactive-time: "..inactive, 100, 50) 

if inactive == "" then 
inactive = "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" 
d = true 
end 

love.timer.sleep(1) 

if d ~= true then 
score = score + 0.5 
if score >= highscore then 
highscore = highscore + 0.5 
end 
end 

love.timer.sleep(1) 
if d ~= true then 
a = "><" 
rand = math.random(0,800) 
b = string.rep(a,math.random(1,8)) 
table.insert(t,"num"..tostring(rand).."/".."800".."|"..b) -- Ex; "num352/800|()()()()() 

love.graphics.print(b, posx, posy) 


for i,v in pairs(t) do 
posxnumcut = string.sub(v,4,string.find(v,"/")-1) 
posynumcut = string.sub(v,string.find(v,"/")+1,string.find(v,"|")-1) 
platforms = string.sub(v,string.find(v,"|")+1,string.len(v)) 
love.graphics.print(platforms, tonumber(posxnumcut), tonumber(math.ceil(posynumcut))) 
newy = tonumber(posynumcut) 
newy = newy - 2 
table.remove(t,i) 
table.insert(t,"num"..tostring(posxnumcut).."/"..tostring(newy).."|"..platforms) 
if newy <= 0 then 
table.remove(t,i) 
end 
end 
end 
helpmsgtab = {} 
if help == true then 
helpmessage = "The goal of this game is not hitting the moving platforms, " 
helpmessage2 = "and stay as long alive as you can. But keep moving, " 
helpmessage3 = "else your 'inactive-time' gets too low and you die. " 
helpmessage4 = "The controls are the arrow keys to move, or AWSD. " 
helpmessage5 = "Press 'P' to pause the game. Anyway, enjoy this game! :D -- Jordan4762" 

table.insert(helpmsgtab,helpmessage) 
table.insert(helpmsgtab,helpmessage2) 
table.insert(helpmsgtab,helpmessage3) 
table.insert(helpmsgtab,helpmessage4) 
table.insert(helpmsgtab,helpmessage5) 

love.graphics.print(tostring(helpmsgtab[1]), 200,400) 
love.graphics.print(tostring(helpmsgtab[2]), 200,410) 
love.graphics.print(tostring(helpmsgtab[3]), 200,420)	
love.graphics.print(tostring(helpmsgtab[4]), 200,430) 
love.graphics.print(tostring(helpmsgtab[5]), 200,440) 

--table.remove(helpmsgtab,1) 
end 

end 
- Jordan4762
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Saving

Post by Robin »

Wow, that's... some very messy code.

What didn't you get?

What I meant was:

Code: Select all

function love.load()
love.filesystem.setIdentity("4762games") -- INSERT THIS HERE
movingobject = "O" --love.graphics.newImageData("Explosion fire texture.png")
x = 50
y = 50
speed = 100
end
-- SNIP: keep the rest the same

--Highscore saving? Dont Know How...
if love.keyboard.isDown("s") and love.keyboard.isDown("lctrl") then
success = love.filesystem.write( "platformer", highscore , 100 ) -- CHANGE THIS LINE
contents, size = love.filesystem.read( "platformer" , 100 ) -- CHANGE THIS LINE
end

--And keep the rest the same.
Hope that helps. :)
Help us help you: attach a .love.
Jordan4762
Prole
Posts: 13
Joined: Thu Oct 14, 2010 10:25 pm

Re: Saving

Post by Jordan4762 »

It Wont Work
- Jordan4762
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Saving

Post by Robin »

Hm. Could you be more specific? Do you get an error message or something? What is your current code?
Help us help you: attach a .love.
Jordan4762
Prole
Posts: 13
Joined: Thu Oct 14, 2010 10:25 pm

Re: Saving

Post by Jordan4762 »

I Give Up On This Project For Now
- Jordan4762
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Saving

Post by Robin »

Aw, don't give up so soon! :(

It'll be hard first, but that's everything in life.
Help us help you: attach a .love.
Jordan4762
Prole
Posts: 13
Joined: Thu Oct 14, 2010 10:25 pm

Physics Engine

Post by Jordan4762 »

I Wanna Work On Something ELSE That I Need Help On, Hopefully Easier... My Physics Engine
Look Out For Another Thread By Me Within 5 Min
- Jordan4762
User avatar
Ryne
Party member
Posts: 444
Joined: Fri Jan 29, 2010 11:10 am

Re: Saving

Post by Ryne »

This thread made me laugh because it seemed like it progressed very quickly to the point where he quit :) Like this:
Jordan4762 wrote:How Would I Fix This?
Robin wrote: Try this: (untested)
Jordan4762 wrote:You Confused Me....
Robin wrote: What didn't you get?
Jordan4762 wrote:It Wont Work
Robin wrote:Hm. Could you be more specific?
Jordan4762 wrote:I Give Up On This Project For Now
@rynesaur
Post Reply

Who is online

Users browsing this forum: Bing [Bot], slime and 50 guests