Tuesday, March 24, 2009

Java: CharSi Update #23

Saving the character information turned out to be easier than I first expected. JMenuItems were added to the File JMenu for saving purposes. One for simply saving the currently opened character and the other (Save As...) to assign a new name to the virtual character's save file.

When saving the character information all of it is saved to a text file with each component on a different line. For example part of a character's file could look like the following.

Paladin
1
20
1
1
20
1
1
20
0
0
1
1

The information is saved in a specific order. First the charType from the Skills class, followed by the values of all the skill point arrays, then each piece of equipment and finally with all of the user inputted values from the Stats panel (character level, user inputted Strength, difficulty level and so forth).

Saving a character takes only a second, opening one takes about 10-20 seconds due to all of the updates that occur every time a component's value is changed. Opening a character basically takes each line of the text file and assigns it to the appropriate variable. However when each variable is altered that prompts a re-evaluation of all the final character values. This re-evaluation works fine when altering a single value manually, such as adding 100 points into Vitality. But when it is run after each variable change it does slow down the opening of the character a bit. Not sure if there is a way around that, but I'll look into it.

I did have some issues when opening characters, all due to pretty basic mistakes on my part but they took quite a long time to track down. The main one was that they program wouldn't update the user inputted stat values correctly. Every time a character was loaded the values of vitality, energy, strength and dexterity revered back to their base values. Upon checking variables I did notice that the correct numbers were being saved into the variables that handle this information.

This meant that I had to find the spot in the code where things information was stopped from being applied correctly. I used a brute force method to do this. In the Open method code I broke the code up into 5-10 line sections and one at a time checked the desired variable before and after the code block. The variable value was output in the command prompt in each instance. If it's value was correct I moved onto the next code block, if it wasn't I took each line of code in that block one at a time to find where the problem was.

Eventually I found that the program wasn't saving the type of character correctly and as a result couldn't assign any values to the stat fields as the variables weren't being updated. The code that caused all the problem was this:

character = input.substring(index1, index2);
Skills.charBox.setSelectedItem(character);
Skills.charType = Skills.charType.substring(0,0);
Skills.charType = Skills.charType.concat(character);

It was the second two lines that were the problem. Worst part was they were completely unnecessary, the first two lines update the appropriate variables correctly so no other changes needed to have been made. Once the last two lines were removed everything worked correctly.

Now it's possible to save and open virtual characters and name them however desired. This coupled with all of the other changes I've made constitutes a significant alteration of the original program, and therefore means I posted an update in the DII forums. The new program can be downloaded here. My To-Do list is much smaller now and mostly contains checks to ensure the user input is valid or code cleanup. The only major component I'll be adding will be a new tab that will contain all of the breakpoint values for FCR, FHR, IAS and block speed. I intend this page to show where the current character's value is, which breakpoint they have hit and how many points are needed to hit the next breakpoint. It should be a fairly straightforward page, but I will have to think about how to make it available when the application is in Standalone mode.

1 comment:

古河渚 said...

Interesting how shoving Charsi + Java into google leads you here. Ahem. Anyway, looks like you are making very nice progress with this! *steals file* Thanks for your hard work.

~ Nagisa