Results 1 to 5 of 5

Thread: Saving?

                  
   
  1. #1
    DCEmu Newbie
    Join Date
    Sep 2005
    Posts
    4
    Rep Power
    0

    Default Saving?

    I'm having a lot of trouble getting my game to save. I read a tutorial about it, but couldn't get any results.

    Could anyone tell me what code to add to save my state to the file save.txt when I press pad:r()?

    Here's a little sample code to work with:

    --COLOR
    white = Color.new(255,255,255)

    --IMAGE
    Player = Image.createEmpty(12,12)
    Player:clear(white)

    --PLAYER ARRAY
    player = {}
    player = {48,80,130}
    player.x=player[1]
    player.y=player[2]

    --PAD
    oldpad=Controls.read()

    --MAIN LOOP

    while true do
    pad = Controls.read()
    screen:clear()

    screen:blit(player.x,player.y,Player)

    --PLAYER MOVEMENT
    if pad:left() then
    player.x = player.x - 2
    end
    if pad:up() then
    player.y = player.y - 2
    end
    if pad:right() then
    player.x = player.x + 2
    end
    if pad:down() then
    player.y = player.y + 2
    end

    screen.waitVblankStart()
    screen.flip()
    oldpad=pad
    end

  2. #2

    Default

    Do you know what tutorial it was? And if so could you post a link for me to see.

  3. #3
    PSP Coder
    Join Date
    Mar 2006
    Location
    America
    Age
    32
    Posts
    25
    Rep Power
    0

    Thumbs up

    what is it supposed to do(yes, it matters)?? and if ur going to put oldpad and pad then u should put also oldpad:x() ~= pad:x().
    E.G. "if pad:left() and oldpad:left() ~= pad:left() then"
    otherwise, it's just useless and will get people confused. And, if i'm right, that is from evilmania.com, PSPMillionairre's site.

  4. #4

    Default

    Hm, that does look like a lot of Charlie's code, did you just copy and paste it? Cause thats your first mistake right there, you should be typing it out. And about that code for saving, here it is:

    So frist create a save.txt file.

    This is a little program a made, so don't give me hell if my codes a bit sloppy.

    __________________________________________________ _____________
    white = Color.new(255, 255, 255)

    while true do

    screen:print(10, 10, "writing to file...", white)

    file = io.open("save.txt","w")
    file:write("writing sucessful")
    file:close()

    file = io.open("save.txt","r")
    save = file:read()
    file:close()

    screen:print(10,20,save,white)

    screen:flip()

    screen.waitVblankStart()

    end
    __________________________________________________ _____________

    This code works, I tested it with the windows lua player.

  5. #5
    DCEmu Newbie
    Join Date
    Sep 2005
    Posts
    4
    Rep Power
    0

    Default

    Thank you very much, and yes, I copied those bits from evilmana.com in an effort to make a simple, easy to test program. That code isn't in my program.

    As for 'what is it supposed to do?' I know the basics of it, so I'll try to figure out the rest on my own, that way I'll remember it (and know why it's done that way). But thanks anyway.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •