Thread: Loading char files?

Results 1 to 9 of 9
  1. #1 Loading char files? 
    Registered Member
    Join Date
    Aug 2011
    Posts
    211
    Thanks given
    17
    Thanks received
    19
    Rep Power
    17
    How would I load an integer from the character files and then divide it by an amount?
    Reply With Quote  
     

  2. #2  
    Banned

    Join Date
    Mar 2011
    Posts
    4,062
    Thanks given
    194
    Thanks received
    689
    Rep Power
    0
    you do know everything that's in PlayerSave class is an int that you had to declare before right? What int are you trying to divine?
    Reply With Quote  
     

  3. #3  
    Registered Member
    Join Date
    Aug 2011
    Posts
    211
    Thanks given
    17
    Thanks received
    19
    Rep Power
    17
    Quote Originally Posted by relex lawl View Post
    you do know everything that's in PlayerSave class is an int that you had to declare before right? What int are you trying to divine?
    I don't want the source to be related to PI.
    Reply With Quote  
     

  4. #4  
    Registered Member
    Join Date
    Aug 2011
    Posts
    211
    Thanks given
    17
    Thanks received
    19
    Rep Power
    17
    bump
    Reply With Quote  
     

  5. #5  
    Banned

    Join Date
    Mar 2011
    Posts
    4,062
    Thanks given
    194
    Thanks received
    689
    Rep Power
    0
    Quote Originally Posted by Billionaire View Post
    I don't want the source to be related to PI.
    Ummm this isn't just for PI, if you're going to save something in a file, you will (unless you're dumb or something) save an int that a class is holding, you're not gonna have something like bw.write("Character-Bank-Pin = 123"); (just an example), youre going to want to load it from a class like ("Character-Bank-Pin = " + player.getDefinition().bankPin);, etc
    Reply With Quote  
     

  6. #6  
    Registered Member
    Join Date
    Aug 2011
    Posts
    211
    Thanks given
    17
    Thanks received
    19
    Rep Power
    17
    Quote Originally Posted by relex lawl View Post
    Ummm this isn't just for PI, if you're going to save something in a file, you will (unless you're dumb or something) save an int that a class is holding, you're not gonna have something like bw.write("Character-Bank-Pin = 123"); (just an example), youre going to want to load it from a class like ("Character-Bank-Pin = " + player.getDefinition().bankPin);, etc

    Okay, so you have a random text file that looks like:
    Code:
    cat-lives = 9
    The 9 is an int, and the cat-lives is just a string, how would I load the int (the 9) from the random text file?
    Reply With Quote  
     

  7. #7  
    Banned

    Join Date
    Mar 2011
    Posts
    4,062
    Thanks given
    194
    Thanks received
    689
    Rep Power
    0
    These are just simple methods you can have to save/load text files

    Code:
    	public void makeTextFile(String fileName) {
    		File f = new File("./data/cat-lives/" + fileName + ".txt");
    		if (f.exists()) {
    			System.out.println("File already exists");
    			return;
    		}
    		saveInformation(fileName);
    	}	
    
    	public void saveInformation(String fileName) {
    		String filePath = "./data/cat-lives/" + fileName + ".txt";
    		BufferedWriter bw = null;
    		try {		
    			bw = new BufferedWriter(new FileWriter(filePath));
    			bw.write("Cat-lives = ", 0, 12);
    			bw.write(Integer.toString(Npc.getDefinition().catLives), 0, Integer.toString(Npc.getDefinition().catLives).length());
    			bw.flush();
    		} 
    		catch (IOException ioe) {
    			ioe.printStackTrace();
    		} finally {
    			if (bw != null) {
    				try {
    					bw.close();
    				} 
    				catch (IOException ioe2) {
    				}
    			}
    		}
    	}
    
    	public void loadInformation(String fileName) {
    		Properties p = new Properties();
    		File folder = new File("./data/cat-lives");
    		File[] files = folder.listFiles();
    		boolean ls = false;
    		for (int i = 0; i < files.length; i++) {
    			String currentFile = files[i].toString();
    			try {
    				if (files[i] != null && files[i].exists()) {
    					p.load(new FileInputStream(currentFile));
    					Npc.getDefinition().catLives = Integer.parseInt(p.getProperty("Cat-Lives"));
    				}
    			} catch (IOException ioe) {
    				ioe.printStackTrace();
    			}
    		}
    	}
    Reply With Quote  
     

  8. #8  
    Registered Member
    Join Date
    Aug 2011
    Posts
    211
    Thanks given
    17
    Thanks received
    19
    Rep Power
    17
    Quote Originally Posted by relex lawl View Post
    These are just simple methods you can have to save/load text files

    Code:
    	public void makeTextFile(String fileName) {
    		File f = new File("./data/cat-lives/" + fileName + ".txt");
    		if (f.exists()) {
    			System.out.println("File already exists");
    			return;
    		}
    		saveInformation(fileName);
    	}	
    
    	public void saveInformation(String fileName) {
    		String filePath = "./data/cat-lives/" + fileName + ".txt";
    		BufferedWriter bw = null;
    		try {		
    			bw = new BufferedWriter(new FileWriter(filePath));
    			bw.write("Cat-lives = ", 0, 12);
    			bw.write(Integer.toString(Npc.getDefinition().catLives), 0, Integer.toString(Npc.getDefinition().catLives).length());
    			bw.flush();
    		} 
    		catch (IOException ioe) {
    			ioe.printStackTrace();
    		} finally {
    			if (bw != null) {
    				try {
    					bw.close();
    				} 
    				catch (IOException ioe2) {
    				}
    			}
    		}
    	}
    
    	public void loadInformation(String fileName) {
    		Properties p = new Properties();
    		File folder = new File("./data/cat-lives");
    		File[] files = folder.listFiles();
    		boolean ls = false;
    		for (int i = 0; i < files.length; i++) {
    			String currentFile = files[i].toString();
    			try {
    				if (files[i] != null && files[i].exists()) {
    					p.load(new FileInputStream(currentFile));
    					Npc.getDefinition().catLives = Integer.parseInt(p.getProperty("Cat-Lives"));
    				}
    			} catch (IOException ioe) {
    				ioe.printStackTrace();
    			}
    		}
    	}
    There is no getDefinition() method
    Reply With Quote  
     

  9. #9  
    Banned

    Join Date
    Mar 2011
    Posts
    4,062
    Thanks given
    194
    Thanks received
    689
    Rep Power
    0
    Yh...I know, that's were you have to fill it in, you didn't tell me where your int was declared or anything so...
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

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


User Tag List

Similar Threads

  1. [ pi ] saved char files -1 -1
    By superbombet in forum Help
    Replies: 11
    Last Post: 11-04-2010, 08:27 PM
  2. [PI]Char files don't save
    By Shaqattack118. in forum Help
    Replies: 3
    Last Post: 10-22-2010, 09:58 PM
  3. Demise Source. Sorry, error loading char files
    By god demolish in forum Help
    Replies: 0
    Last Post: 09-12-2010, 05:32 PM
  4. Char Files
    By yummeh in forum Help
    Replies: 2
    Last Post: 12-15-2009, 01:26 AM
  5. Char files!!
    By Huey in forum Requests
    Replies: 0
    Last Post: 10-01-2009, 11:19 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •