DSLua Community
Welcome, Guest. Please login or register.
May 21, 2012, 08:35:23 PM
1371 Posts in 262 Topics by 33109 Members
Latest Member: Limewire Download
DSLua Community  |  DSLua - Best scripting language for Nintendo DS  |  Need Help?  |  Savegame « previous next »
Pages: [1]
Author Topic: Savegame  (Read 1452 times)
manu62300
Waxing Crescent
**
Posts: 89



« on: July 04, 2007, 04:17:07 PM »

yep help me for  savegame in my homebrew ,example Huh
Logged

XtreamLua.com
La Référence en programmation sur PSP & DS
xtreamlua.miniville.fr
Bon dev...;
Jeremysr
First Quarter
***
Posts: 215



WWW
« Reply #1 on: July 04, 2007, 07:43:05 PM »

You need to use the I/O library to save a file that contains the save information. I used this in Skydiver 3.0. Here is the code:

Save highscore:

Code:
highscorefile = assert(io.open("highscores", "r"))

currentScore = highscorefile:read("*line")

highscorefile:close()



position_of_slash = string.find( currentScore, "/" )

score = tonumber( string.sub( currentScore, position_of_slash + 1, string.len( currentScore ) ) )



if level > score then

BGTopText:PrintXY( 1, 1, "Congratulations!" )

BGTopText:PrintXY( 1, 2, "You have the best score!" )

BGTopText:PrintXY( 1, 4, "Type your name please." )

require( "keyboard.inc.lua" )

name = keyboard( 20 )

writetoscorefile = name .. "/" .. level

highscoresfile = assert(io.open("highscores", "w"))

highscoresfile:write( writetoscorefile )

highscoresfile:close()

end

Load highscore:

Code:
function highScores()

Screen.Initialize( SCREEN_BOTTOM, BGBotText, BGBotBackground )



highscorefile = assert(io.open("highscores", "r"))

score = highscorefile:read("*line")

highscorefile:close()



position_of_slash = string.find( score, "/" )

name = string.sub( score, 1, position_of_slash - 1 )

score = string.sub( score, position_of_slash + 1, string.len( score ) )



-- Print out name and score

BGBotText:PrintXY( 1, 1, name .. " - " .. score .. " points" )



BGBotText:PrintXY( 1, 14, "Press A to go back." )



while Pads.A() == false do

end



styluswasinX = Stylus.X()

styluswasinY = Stylus.Y()

end
Logged
manu62300
Waxing Crescent
**
Posts: 89



« Reply #2 on: July 05, 2007, 02:26:58 AM »

thanks i test it  Wink
Logged

XtreamLua.com
La Référence en programmation sur PSP & DS
xtreamlua.miniville.fr
Bon dev...;
TOAST
Waxing Crescent
**
Posts: 67



« Reply #3 on: July 07, 2007, 09:57:42 AM »

Also, it would be a good idea to make some encryption on the file to prevent people from cheating. Roll Eyes
Logged
daltonlaffs
First Quarter
***
Posts: 189


Freaking Insane


WWW
« Reply #4 on: July 08, 2007, 09:52:39 AM »

Yes, but encryption would:

- Be difficult.
- Slow down the saving and loading times.
- Involve some sort of annoying string.gsub technique.
- Suck.

Tongue
Logged

Code:
-- Bored? Read code line below.
-- Bored? Read code line above.



^^ That works, I SWEAR! ^^
TOAST
Waxing Crescent
**
Posts: 67



« Reply #5 on: July 08, 2007, 07:08:29 PM »

Yes, but encryption would:

- Be difficult.
- Slow down the saving and loading times.
- Involve some sort of annoying string.gsub technique.
- Suck.

Tongue

Not really... If you make your own encryption/decryption algo it won't be.
Logged
Pages: [1]
« previous next »
    Jump to: