×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    31

    RMS (groan) examples please...

    Hi All,

    One week in and my game is nearing completion! (after my initial problems I ended up rewriting everything from scratch to fix it)

    However now I have a quick question, in the morning I need to start looking into saving the last level number I completed so that when I re-run the game I can continue from that (or any level below) it.

    So my plan is to use recordstore, however it looks rather complicated for my needs. I only ever want to store just one Integer variable, no names etc never more than one record which I would like to read when the game launches and write everytime a level is completed.

    Does anyone have a simple example or know of a similar tutorial (ie not a big bloaty one) that I can look at?

    Thanks
    Jamie

  2. #2
    Nokia Developer Expert
    Join Date
    Jun 2005
    Posts
    923

    Re: RMS (groan) examples please...

    Well, I have not passed the code below through a compiler, so it can contain errors, but it looks like:

    Code:
    public void saveGame(int level) throws Exception {
      RecordStore rs = RecordStore.openRecordStore("MY_GAME",true);
      ByteArrayOutputStream baos = baos = new ByteArrayOutputStream();
      DataOutputStream dos = dos = new DataOutputStream(baos);
      dos.writeInt(level);
      byte[] data = baos.toByteArray();
      
      if(rs.getNumRecords() == 0) {
        rs.addRecord(data,0,data.length);
      }
      else {
        rs.setRecord(1,data,0,data.length);
      }
    }
    
    public int readGameLevel() throws Exception {
      RecordStore rs = RecordStore.openRecordStore("MY_GAME",true);
      
      if(rs.getNumRecords() == 0) throw new Exception("No level saved");
    
      byte[] data = rs.getRecord(1); //1 because there's only one record
      ByteArrayInputStream baos = baos = new ByteArrayInputStream(data);
      DataInputStream dos = dos = new DataInputStream(baos);
      int level = dos.readInt();
    
      return level;
    }
    Hope it helps.
    Daniel

  3. #3
    Registered User
    Join Date
    Sep 2004
    Posts
    31

    Re: RMS (groan) examples please...

    Quote Originally Posted by dcrocha
    Well, I have not passed the code below through a compiler, so it can contain errors, but it looks like:

    Hope it helps.
    Daniel
    Many, Many Thanks Daniel, This is great work and I cant wait to try it, I'll let you know how I get on.

    Thanks again.
    Jamie

  4. #4
    Registered User
    Join Date
    Sep 2004
    Posts
    31

    Re: RMS (groan) examples please...

    This code is perfect, and has provided me a provided me a straight forward and very understandable answer. I can now understand it well enough to go on and write my own routines. This forum is sometimes a little vague with its responses but this one was ace.

    Many thanks!
    Jamie

  5. #5
    Nokia Developer Expert
    Join Date
    Jun 2005
    Posts
    923

    Re: RMS (groan) examples please...

    Hi,

    I'm glad it helped

    Daniel

Similar Threads

  1. RMS data LOST problem in 3410!!!
    By bitsonic in forum Mobile Java General
    Replies: 6
    Last Post: 2009-03-27, 09:50
  2. rms, does it really saves?
    By ayanir in forum Mobile Java General
    Replies: 7
    Last Post: 2006-01-26, 12:57
  3. RMS not saved on Nokia 6225
    By franckspike in forum Mobile Java General
    Replies: 2
    Last Post: 2004-10-11, 07:42
  4. 7210 & 7250 RMS resetting problem
    By keithmcneill in forum Mobile Java General
    Replies: 1
    Last Post: 2003-11-13, 21:04
  5. Very Important RMS Issue
    By adywicaksono in forum Mobile Java General
    Replies: 6
    Last Post: 2003-07-11, 21:25

Posting Permissions

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