Loading and Saving problem in 2D space based rpg

I am implementing a system in which the game saves the offset of the default position of an object in space and the object's position when the game is saved and applying that to the objects when the game is loaded. I get a strange problem however where every other undock after loading the game is far far away in space. I think it has something to do with the saved position of the object you docked with. Here is the code involved in loading the game (it just calls IO.java via dataAgent and gets data from a file)
public void loadGame() throws FileNotFoundException, IOException {
        //load the game
        String[] tmpData = null;
        tmpData = dataAgent.loadGame();
        //interpet the data
        hud.currentDockedCelestialObject = Integer.parseInt(tmpData[0]) - 1;
        player.currentWallet = Integer.parseInt(tmpData[1]) - 1;
        player.currentSolarSystem = space[hud.currentDockedCelestialObject].solar;
        hud.renderMode = 1;
        hud.player = player;
        hud.space = space;
        hud.dPressed = true; //tell HUD we are docked at something
        //now we need to determine the position of all the celestial objects based on the saved position of the object in question
        int tmpx = Integer.parseInt(tmpData[2]) - 1;
        int tmpy = Integer.parseInt(tmpData[3]) - 1;
        //compare it to the docked celestial
        int changex = space[hud.currentDockedCelestialObject].positionX - tmpx;
        int changey = space[hud.currentDockedCelestialObject].positionY - tmpy;
        //apply the offset to all the objects in the current solar system
        for (int i = 0; i < space.length; i++) {
            if (space.solar.matches(player.currentSolarSystem)) {
space[i].positionX += changex;
space[i].positionY += changey;
//now we need to load the ship type
player.ship.type = Integer.parseInt(tmpData[4]);
//configure the shields and hulls
configureLoadedShip();
//finish up
hud.space = space;
hud.player = player;
Configureloadedship() just makes a call to apply the correct weapons and armor to the ship you have. Here is the saving code:public void saveGame() {
//saves the game
String[] toSave = new String[5];
toSave[0] = "" + (hud.currentDockedCelestialObject + 1);
toSave[1] = "" + (hud.player.currentWallet + 1);
toSave[2] = "" + (space[hud.currentDockedCelestialObject].positionX);
toSave[3] = "" + (space[hud.currentDockedCelestialObject].positionY);
toSave[4] = "" + (hud.player.ship.type);
try {
dataAgent.saveGame(toSave);
} catch (IOException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
Adding and subtracting 1 durring load and save solved the problem of the java file reader skipping the 0 values in the first few lines of the saved game file.
The game is loaded when the game starts and saved when you dock.
Ty in advance for your help.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

public String[] loadGame() throws FileNotFoundException, IOException /*should never be thrown*/ {
        String[] toReturn = null;
        //load the data
        FileReader read = new FileReader(data);
        BufferedReader buff = new BufferedReader(read);
        String tmp1 = "";
        String tmp2 = "";
        while((tmp1 = buff.readLine())!=null) {
            tmp2 = tmp2 + tmp1+"~";
        //break it into a usable form
        toReturn = tmp2.split("~");
        System.out.println(tmp2);
        return toReturn;
    }and
public void saveGame(String[] toSave) throws IOException {
        FileWriter write = new FileWriter(data);
        BufferedWriter buff = new BufferedWriter(write);
        //clear the old file
        data.delete();
        data.createNewFile();
        //zap the data to the file
        for(int i = 0; i < toSave.length; i++) {
            buff.write(toSave);
buff.newLine();
//write
buff.flush();
}They are basically just buffered readers and writers.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

Similar Messages

  • Problem with  whitespace  then loading and saving xml

    i do not know how to handle this problem. i modifed a texteditor to send XML to a server and load XML back to the container.
    but then i do changes to the Textlayout it shows up like this --->
    Text in Container not modifed
    Text in Container modifed ---> with space beween the colorchanged string
    Text inContainersend and loaded ---> i think this has something to to with the
    TextFilter.export(_textFlow,TextFilter.TEXT_LAYOUT_FORMAT,ConversionType.XML_TYPE)
    can someone give me a hint...

    Hi,
    the link is --->
    http://www.horstmann-architekten.de/contentmanagment/SimpleEditor.html
    its a modified example of the texteditor provided by Adobe. You can send a xml to the server. and also read it from the server. You just use the xml identifer to give the xml a name.
    Try it out:
    1.  change the text and
    2.  give a XML-Identifer
         and then send it to the server. --> send to server
    3.  type in the XML-Identifer you have used and
    4.   load it from the server ---> Load from Server Button
    evering works ok exept the columns formating.
    I Think the colums Formating is not embeded in the XML as it should be. I attached the Files. (Newbie programmer)
    With best regards
    Michael Sprinzl
    --- robin.briggs <[email protected]> schrieb am Do, 17.9.2009:
    Von: robin.briggs <[email protected]>
    Betreff: Problem with  whitespace  then loading and saving xml
    An: "Michael sprinzl" <[email protected]>
    Datum: Donnerstag, 17. September 2009, 2:12
    Sounds like you have two different issues going on: (1) inline graphics aren't coming out correctly when you use the TextLineFactory, and (2) columns aren't working correctly. It's difficult for me to tell by looking at the application you link what is going wrong. One of the examples does seem to have columns working -- can you be more specific about what you're doing, and what results you are seeing? As for the inline graphics, there is a timing issue involved with using URLs, due to the asynchronous loading. See this comment in the docs for TextFlowTextLineFactory:
    Note: When using inline graphics, the source property of the InlineGraphicElement object   must either be an instance of a DisplayObject or a Class object representing an embedded asset.   URLRequest objects cannot be used. The width and height of the inline graphic at the time the line   is created is used to compose the flow.
    - robin

  • Dock won't load, and associated problems

    I'm having some severe problems with my mac at the moment, and I've no idea how to even start fixing things. A while ago, I was browsing the web, when my mac seemed to freeze. My dock and desktop picture both disappeared, and to close down, I had to do a hard restart. Since then, I've not been able to load the dock at all. Finder loads, and the system recognises CDs when I put them in, but I can't load any other programs. If I try, I just get the spinning beach ball, and nothing happens at all. To turn the machine off, I have to use the power button, as nothing responds.
    I've not changed any hardware, installed any programs, or changed any settings for a long time before this happened. I've tried to boot from the installer disks, and nothing. Any suggestions?

    Welcome To Discussions papervolcano!
    "I've tried to boot from the installer disks, and nothing."
    Please clarify what you mean by nothing.
    After inserting the install CD, are you restarting while holding down the C key, as Donald Morgan posted?
    Are you using the original iMac G5 system disc?
    ali b

  • Problems loading and saving pdf files from sites with latest version.

    On my utilities I wish to download and save pdf files of my e-bill.
    Lately when I click on getting bill, Firefox opens new tab and stops.
    with a light message in url place saying "Type a web address".
    To get around this I must do a right click on the save bill and
    select open in new window, then it opens a new copy of Firefox,
    and two tabs, with the second one asking me to use Adobe to see
    pdf file. I tell it to open and then save it and print it from the tab
    that opens with the pdf file in it. This never happened before was
    always able to just click on link and it would open new tab with
    pdf file there.

    Thanks for the replies. I don't think I was clear enough with my question.
    What I want to be able to do is to click on a PDF file in my Firefox browser and be able to save it as an Adobe PDF file, not a Preview PDF file, in any folder on my computer, rather than just the specified default location for downloads. This way I can save, for example, phone bills in the phone bills folder and bank statements in the bank statements folder without having to save them to the desktop, "Get Info" on each, and change the "Open with:" box from Preview to Adobe Reader.
    Fortunately, thanks to Michael's post, I found an add-on from Firefox that allows me to do just that: https://addons.mozilla.org/en-US/firefox/addon/636
    Thanks for your help. Now, within my Firefox browser, I can choose whether to view or download PDF files, always in Adobe rather than Preview, and when I save them I get the option to choose the location each and every time.
    MacBook Mac OS X (10.4.9)
    MacBook Mac OS X (10.4.9)

  • Object loaded and saved with Read and Write Datalog are not compatible with packed library

    Hi all,
    I often use packed libraries to distribute my software.
    My problem is the following:
    I save a LabVIEW object of a class (MyClass) that is not included in a packed library using "Write datalog" (for example saved file is MyObject.dat).
    If I load MyObject.dat using "Read Datalog" but using "MyCLass" saved in packed library as "Record type", Read Datalog generates an error or anyway loaded data is inconsistent.
    In other word, if I save an object using as "Record Type" MyClass not included in a packed library and then I load saved file using the MyClass included in a packed library, file cannot be loaded.
    Can you help me?
    Thank all

    I think you are running into an issue created by namespacing.
    Point is, that lvlib as well as lvlibp create a level of namespacing:
    I would expect that level of namespaces being part of the datalog file.
    So essentially, if the class is not encapsulated in the very same namespace when reading in which it was written, it should fail with exactly the error you are describing.
    Norbert
    CEO: What exactly is stopping us from doing this?
    Expert: Geometry
    Marketing Manager: Just ignore it.

  • Loading and Saving Game

    I am doing a shooting game like a plane shooting aliens (like asteroids) for sch assignment. Very urgent coz deadline is Monday.
    I don't know how to save and load the game such that the image of my plane's position, score, stages etc. I don't know what class to use for saving and loading.....
    Thank you to those who read about my problem.

    If the game has levels you could simplify your saving by only saving between levels. with this you only need to save a small amount of info like highest level, player name and so on.
    if you want to save at any point of the game you will need to save all your info which is a bit complicated if you want to save images and such (in that case i recomend only saving image paths as strings and not the images themselfs).
    In an application i created i save Serializable objects in an xml format like this
    //lets call your object game which includes all the objects that make
    //up the game info
    private void save(Game game,String fileName) throws IOException
            //save the game in an ".xml" file
         if(!fileName.endsWith(".xml"))
              fileName=fileName+".xml";
            FileOutputStream out=new FileOutputStream(fileName);
            BufferedOutputStream outstream=new BufferedOutputStream(out);
            XMLEncoder encoder=new XMLEncoder(outstream);
            //write the data into the file
            encoder.writeObject((Game)game);
            encoder.close();
         outstream.close();
            out.close();

  • IMac - Slow load and wifi problems

    I have lion installed on my macbook pro and on my iMac. My macbook pro works GREAT...no problems. My iMac - I am ready to toss out a window. Here are the problems:
    INCREDIBLY slow boot up time - 5-10 minutes from off - 5-8 minutes from sleep
    The hard drive is constantly working. I can have nothing open and it sounds like the hard drive is constantly spinning
    Half the time my wifi hardware is not found on boot up and I have to reboot with slow load times - sometimes taking 20 minutes before I can get logged in to a 'working' computer
    A lot of my programs have become slow. Safari can be slow responsive but others that are not apple that have done 'lion updates'
    I have my activity monitor running and nothing seems to be hogging resources. My iMac specs are:
    2.8 intel core i5
    12 gb ram
    2 TB hard drive with about 1tb free
    I ran the lion update that came out and it did not seem to do much for me.
    Anyone have a solution? Anyone tried a clean format and did this work? Lion works great on my laptop and I just need it to work on my main computer as well.
    Reba

    i think part of the boot up time issue is the amount of windows you happen to have open when you put it to sleep
    other is lion upgrade slows it down due to this auto save function
    my wifi is also spotty and acts like it can't find itself at times
    and this is a brand new imac

  • Home Sharing: Half loading and skipping problems

    Hello all
    Firstly, thank you to those that are reading this with a view to helping, and to those that will, hopefully, reply.
    I am looking at getting my iTunes library shared in my home. My current set up is simple: 2011 MBP, iPhones, iPad, all music on the MBP and all devices using the same iTunes account (although, there are different iCloud accounts on the devices, but I assume this is not a problem). All devices up-to-date. Approx 80GB of ripped/iTunes purchased music. The first thing I want to acheive is my iPhone having access to my music library so I can plug the phone into a dock and play what I want.
    I believe I have set up Home Sharing correctly. When I use the Music app on any iOS device I can see the library on the MBP, but one of two things happens:
    - Mostly, the library half loads (exactly half, it quickly gets to half and stops), or
    - The library does eventually load but when i try to play a song it skips/cycles through every song without playing, until it comes to the end of the playlist/album
    Both of the above seem to be reasonably common problems, with no solution.
    As a troubleshoot, i set up the Remote app; this works flawlesly. I can control iTuines from an iPhone with no problems at all. "It just works." I therefore assume that I can mostly rule out router problems and me not setting things up properly.
    So, the question: Is there a real solution to the above?
    Many thanks

    Hi Christoffee,
    If you are having issues with your Home Sharing configuration, you may find the troubleshooting steps outlined in the following article helpful:
    Apple Support: Troubleshooting Home Sharing
    http://support.apple.com/kb/ts2972
    Regards,
    - Brenden

  • Office 2007 Long loading and saving times

    I have a small network with a PC unit running windows 7 HP acting as a fileserver with an attached external hard drive being the primary storage location. It is mapped to about 8 PC's all running windows 7 HP with MS Office enterprise 2007 The users are
    reporting and I have confirmed extremely long download/load times when opening excel spreadsheets. They have reported when saving a file to the shared drive extremely long wait times and sometimes the program crashes. I have not seen the saving issue or been
    able to recreate it. If the file is on the local PC then it opens normally. When its from the shared directory it says downloading at the bottom and has a progress bar. Biggest spreadsheet they work with is about 315kb and it sometimes takes upwards of
    a min to download. 
    I have gone through a dozen suggested solutions, gone through the shared settings with a fine tooth comb. Remapped the drive numerous times.  I have uninstalled Office validation, I have enable add ins, disabled all add ins, made registry changes to security
    keys. I have disabled the anti-virus on both ends. I have ensured that no old network printers or devices are still installed. All windows and office updates have been applied. I am at my whits end on this one. Anyone have any suggestions?

    To be honest with you, You will not get any better speed then this from a USB 2 hard drive. May be better to add extra HD in the server.

  • Loops and saving problems

    Hey,
    I am having a problem saving my data. I have a program that simulates a tap. Essentially a certain voltage will trigger the data to be collected. To present it to everyone in this forum I have just simulated this effect. If the button is turned on then it will pseudo randomly trigger the first inside loop. 
    Here starts the problem. When the first inside loop is triggered the graphs show the resulting data and a box pops up asking if you want to save this data. Well everything time I click yes it won't save.Then the next time the first inside loop is triggered the save dialog box pops up to save the current data. It is really weird. If you want to see what I am talking aobut please run the program and click yes you want to save a couple times and I think you will start to understand my problem. 
    Essentially I want to be able to see the results of the data and decide if I want to save it or not. If I choose yes then I would like to name the file path.
    I have looked at this for hours and can't come to any conclusion why this is happening. Maybe a flow or loop issue?
    Please note, the outside loop should always be on to keep the program continuous.
    Thanks for any help on this
    Solved!
    Go to Solution.
    Attachments:
    newtapsimulateddicussion.vi ‏285 KB

    Hova wrote:
    @ altenbach which inner loop are you referring to?
    There are only two while loops: the outer loop and the inner loop. Why are you confused?
    Hova wrote:
    ... in Labview flow moves top left to bottom right correct?
    NOOO!!! You are incorrect. The execution order is completely independent of the diagram coordinates.
    The important word is "data dependency". In your code, the dialog and the while loop can execute in parallel, because they do not depend on each other. If you would place any of the inputs to the dialog inside the inner loop (e.g. as in the picture), the dialog now depends on data from the while loop and thus cannot start until the loop has finished.
    Play around with execution highlighting to get a better feel for all that.
    You can un-mark the solution via the options menu of the post. Have you tried?
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    LoopDataDependency.png ‏7 KB

  • Loading and saving xml in coldfusion

    I'm pretty new to Flex and am trying to save a modified xml
    file to disk using coldfusion. I have figured out how to load the
    xml file into a Flex and modify it with various components, have
    tried to save it back to the server using <cffile>, but the
    file is empty. How do I extract the xml object that is sent back to
    CF from httpservice so I can save the flat xml file again?
    I'm sure the answer is simple but I just haven't found an
    easy tutorial to follow....

    I'm pretty new to Flex and am trying to save a modified xml
    file to disk using coldfusion. I have figured out how to load the
    xml file into a Flex and modify it with various components, have
    tried to save it back to the server using <cffile>, but the
    file is empty. How do I extract the xml object that is sent back to
    CF from httpservice so I can save the flat xml file again?
    I'm sure the answer is simple but I just haven't found an
    easy tutorial to follow....

  • HT2523 Word docx file conversion and saving problems

    I've recently switched back to Mac after many years as a Windows user. I was delighted to be able to open my Word documents in TextEdit, but have had to reformat certain parts of the documents (specifically, bullets, tabs, and wrap to page) EVERY TIME I open the document. These are not saved in the file. I'm happy to change the format of the documents to rtf or whatever to keep the changes, but can't figure out how to do that either. The ultimate format for these docs is PDFs, so I don't really wish to buy MS Office for Mac. I can't find anything about this in TextEdit help.

    In support of your advice ....
    Preview will open directly .doc/.docx Word files. The path to PDF can also be through the Export facility.
    Preview is only as good as Pages when attempting to open Word documents. If the OP has complicated Word documents that will not open with Preview, then a suggestion is to download and install the free LibreOffice 4.x (libreoffice.org) application. This will certainly open Word documents.
    Rather than learn LibreOffice just to convert PDF, the OP can use the following Terminal command:
    Terminal:
    /Applications/LibreOffice.app/Contents/MacOS/soffice --headless -convert-to pdf:writer_pdf_Export sample.docx
    This will write out a PDF of the input file to the current directory. Providing *.doc or *.docx on the command-line will convert all files matching this description to their PDF counter-parts. There is a --outdir argument that given a path to a directory, will place the resulting PDF there for improved organization.
    The above command does not visibly launch LibreOffice. The only output is a single line to the terminal indicating that the conversion has taken place.
    Cheers.

  • Illustrator CS6 opening and saving problem. Please help

    Hello
    I have Illustrator CS6 installed on windows 8.1. Every time I save a file as ai. format, it will automatically create a copy on the desktop. When I deleted the copy and try opening the original file, the error message "The file is an unknown format and cannot be opened" pops up. I've checked that the file is not "read only", deleted the pref files and even reinstalled Illustrator CS6 but none of these have solved the problem. I have also noticed that I cannot copy or rename the file as the same error message pops up. Any solutions? please help

    (1) When I go to open files, raw or jpeg, I now need to enter a value for 'enable' on the open dialog.  That never was necessary before.
    Could you please post a screenshot with the pertinent Panels/Dialogs visible?
    (2) When I go to save as jpeg, the file type defaults to eps. 
    So you select jpg from the dropdown list and it switches to eps?

  • Load and Trim Problems with IdeaTab A1000

    Lenovo IdeaTab A1000 16GB at work was a terrible device. Having spent two weeks hanging software. I had to give a warranty repairs.
    After a week of warranty repairs, the device worked for five hours and again hung software ...
    I'm beginning to think that was wrong with the choice of the device.

    I have to try this and I will let you.
              Thanks
              Jon Eagles wrote:
              > All,
              >
              > We have a simple servlet which looks up an RMI object from JNDI and invokes
              > one of its methods in a loop. The RMI object is the HelloClusterImpl
              > example provided by WebLogic. The servlet basically copies the code from
              > the HelloClusterClient. In the cluster property file, our load algorithm is
              > setup to be round-robin. We are using IIS as our web server. If we start
              > up both servers in the cluster and then use another machine as our client to
              > call the HelloClusterClient, we see that the calls to HelloClusterImpl
              > alternate between the two clustered servers. In fact, it is done perfectly
              > at 50% for each server. When we run the servlet from with the client's
              > browser, however, it seems as if which ever server in the cluster that
              > receives the servlet request then takes 100% of the calls to
              > HelloClusterImpl and there is never any alternating. Although we can verify
              > that different servers in the cluster receive the servlet request, it seems
              > as if there is never any altering between the servers during the method
              > invocations on the HelloClusterImpl servant. Does this seem right?
              > Shouldn't there be alternating between the servers? Any help would be
              > greatly appreciated.
              >
              > Thanks,
              >
              > -Jon
              

  • Premiere Pro 2014 Cross Fades don't save and or load and saved audio drops???

    For no apparent reason premiere pro 2014 will not save cross fades...  it saves them but wont load them
    Audio is dropping out ....
    I was given a project to make some changes to and every time I open it I need to recreate the cross fades and then export it and then check it and then recreate the cross fades that didn't export and then hope for the best!!
    this is so unstable and there seems to be no apparent reason
    any help would be magnificent

    Hi Vince,
    vince_email wrote:
    ...The only things that changed were an update to Yosemite, I started using Time Machine to make regular backups...
    Please check this blog post. Updating from Time Machine can cause this issue: Premiere Pro CC, CC 2014, or 2014.1 freezing on startup or crashing while working (Mac OS X 10.9, and later).
    Thanks,
    Kevin

Maybe you are looking for

  • Is there a way to force the cursor into a string control when a vi is called

    In a .vi I'm wrighting I need to input a new serail number at the beginning of each run. Is there a way to force the cursor into the string control box every time the start screen returns? eliminating the need for the operator to move the mouse aroun

  • Down saving from CS5 to CS4 in a batch

    Hello! I have a large volume of CS5 files to downsave to CS4 so they can be used on another machine. Is it possible to do this in a batch? I've tried a couple ways so far and I'm definitely doing something wrong as the new files still tell me they we

  • UTF-8 characters in database

    Hi there, I'm having problems with UTF-8 characters displaying incorrectly. The problem seems to be that the Content-Type HTTP headers have the character set as "Windows 1252" when it should be UTF-8. There is a demonstration of the problem here: htt

  • Hashtable locks after cgiscope.resolve in cfapplication tag

    Hi, Running (IIS 6, Windows 2003, coldfusion 7.02) I have been trying to tune our servers already for a while and fixed quite a few bottlenecks. At the moment i trying to solve a problem which delays (Running requests shoot up till maximum, requests

  • ICal Timezone support - Birthday off by one day.

    I always used iCal's timezone support. I had it on since day one I got my computer running. I have been using the birthday calendar function for all my address book contacts' birthdays as well. I have just moved from Vancouver (GMT -7) to Japan (GMT