[Solved] Hash Table Named Keys Randomness

For questions about using Classic.

Post » Wed Sep 07, 2011 2:14 pm

I Have been trying now for a very long time to create a system that loads information from a .txt file (called "Dwarf.txt" in the example) and adds it into a Hash table.

How

The .txt file is made so that each line represents a value, ex:

Race
Dwarf
Agility
100
Strength
105
Intelligence
100
Charisma
90

and so on...

I have successfully added all even line number values to 1 ListBox object, and all Odd line number values to another ListBox object. This has created 2 lists, one with the name of the attribute, and one with the value of that number (so to speak).

I Now Play a loop 27 times,

Each Time the loop plays, I
Insert a key equal to ListBox1's Line Text on the Line equal to LoopIndex. That Key is given the value of ListBox2's Line Text on the Line equal to Loopindex.

Now I don't find anything wrong with the events/actions, and keys are added as I said.

THE PROBLEM] is that the keys are all messed up. Several keys may be OK, but some of them are really strange, named after all sort of code and other keys...

I Included a .cap and a .txt object for testing. Its .Zip

http://www.yourfilelink.com/get.php?fid=711071Nifl2011-09-07 23:08:42
B
6
S
1
G
2
Posts: 18
Reputation: 711

Post » Wed Sep 07, 2011 4:59 pm

What about using the INI object/file instead? Its kinda setup for this sorta thing.

Add the INI object to your layout, and make it global. Then you will need to Set the INI file to be loaded from.

[Dwarf]
Race=Dwarf
Agility=100
Strength=105
Intelligence=100
Charisma=90

Then use an INI.ItemString (for letters/strings) or INI.ItemValue (for Numbers)

So just to load the values above you would do the following:
INI.ItemString("Dwarf", "Race")
INI.ItemValue("Dwarf", "Agility")
INI.ItemValue("Dwarf", "Strength")
INI.ItemValue("Dwarf", "Intelligence")
INI.ItemValue("Dwarf", "Charisma")

This way rather than a file for each race, you could have a file for all of the races, just put them into a different group. With an INI file the keys should never be messed up.

B
6
G
1
Posts: 23
Reputation: 921

Post » Wed Sep 07, 2011 8:19 pm

Thanks for the response Sandcrawler, I have thought about using an INI file. I have never done so, but figured it wouldn't be a problem to learn. The thing is though that I have a very hard time to let go of a problem that is unsolved, and that I believe can be solved. If its a bug then fine, I will move on. But if it's not and Im just doing something wrong, well the thought of that frustrates me beyond description. I feel that I need to solve this problem or I will never use Hash tables again. With is sad...
B
6
S
1
G
2
Posts: 18
Reputation: 711

Post » Wed Sep 07, 2011 10:04 pm

The keys appear to be fine to me. Each name has the correct value. What language do you use with windows? If the language uses 2 bytes per letter then perhaps the listbox is causing the corruption?

This cap doesn't use the listbox object:
http://dl.dropbox.com/u/5426011/examples6/txtToHash.cap
run in debug mode to see the populated hashtable.
B
79
S
24
G
54
Posts: 4,746
Reputation: 40,755

Post » Wed Sep 07, 2011 11:00 pm

[QUOTE=R0J0hound] The keys appear to be fine to me. Each name has the correct value. What language do you use with windows? If the language uses 2 bytes per letter then perhaps the listbox is causing the corruption?

This cap doesn't use the listbox object:
http://dl.dropbox.com/u/5426011/examples6/txtToHash.cap
run in debug mode to see the populated hashtable.[/QUOTE]

Thanks R0J0hound
Well, that application sure worked a lot smoother. Seams Im using Swedish. (though not sure how Windows figured that one out as absolutely nothing in the system is displayed in Swedish) Never the less, the explanation that its the system (and not I) who messed up is very comforting. Ill just have to work around the Listbox object as a means of storing data in any manner and just use it for displaying.

That's some brilliant coding there by the way. Ill need to customize it a lot, but I will use it to fall back to if something happened. Thanks again for the help. Now (soon) I can finally start working with the actual game and not just the engine for it.
B
6
S
1
G
2
Posts: 18
Reputation: 711


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 5 guests