So I've been trying to get this table to work, and so far it's consistently returning wrong numbers for one type of operation.
There are six values in the table, all stored as integers and all with a name equal to their value.
I'm running the following test triggers:
Trigger 1
Events
Game - Map initialization
Local Variables
Conditions
Actions
Data Table - Save 0 as "0" in the Global data table
Data Table - Save 1 as "1" in the Global data table
Data Table - Save 2 as "2" in the Global data table
Data Table - Save 3 as "3" in the Global data table
Data Table - Save 4 as "4" in the Global data table
Data Table - Save 5 as "5" in the Global data table
Trigger 2
Events
Game - Player Any Player types a chat message containing "check", matching Exactly
Local Variables
Conditions
Actions
UI - Display (Text((Name of value 1 in Global data table))) for (All players) to Subtitle area
UI - Display (Text((Name of value 2 in Global data table))) for (All players) to Subtitle area
UI - Display (Text((Name of value 3 in Global data table))) for (All players) to Subtitle area
UI - Display (Text((Name of value 4 in Global data table))) for (All players) to Subtitle area
UI - Display (Text((Name of value 5 in Global data table))) for (All players) to Subtitle area
UI - Display (Text((Name of value 6 in Global data table))) for (All players) to Subtitle area
UI - Display (Text(("0" from the Global data table))) for (All players) to Subtitle area
UI - Display (Text(("1" from the Global data table))) for (All players) to Subtitle area
UI - Display (Text(("2" from the Global data table))) for (All players) to Subtitle area
UI - Display (Text(("3" from the Global data table))) for (All players) to Subtitle area
UI - Display (Text(("4" from the Global data table))) for (All players) to Subtitle area
UI - Display (Text(("5" from the Global data table))) for (All players) to Subtitle area
What it is supposed to do is it returns the names of all the values 0/1/2/3/4/5, then it returns all the values of the names 0/1/2/3/4/5.
What actually happens is it returns this:
3
4
1
0
2
5
0
1
2
3
4
5
This means that the name is being returned wrong every time, but the value returns are working fine.
The table also wouldnt let me type in a value = 0 for returning its name, for some reason I could only enter positive numbers above 1, which seems like a bug to me.
Can anyone share and insight about what the hell is going on here? It seems to just be feeding me numbers in a random order.
You got all the numbers when you started from 1, so I guess they just decided not to index it from 0. That makes it more intuitive for people who are not used to programming.
About the order. I believe the data table is implemented as a hash map. This means that the text you give them are hashed to some integer. That integer should be seemingly random, and collisions should be rare (a collision are two strings that hash to the same thing). This means that whatever keys you add to the data table, don't expect them to have any logical order when read out like you do. When you ask for the name of the i't key, they just transverse the hash table and output the i'th key they come across (again, it's not sorted, just "randomly" ordered).
The benefit of a hash table is that when you ask for the value in a specific key "foo", they just have to hash "foo", and look at that entry of the hash table, which is pretty fast. When you add stuff to a hash map, you also just hash the string and insert at that index in the hash table (which is probably just an array).
Of course, I don't work at blizzard, so any comments about their implementation is purely speculation on my part, but it would make sense if that's how they implemented it.
When you post code to the forums, do it in <code>...</code> tags.
So I've been trying to get this table to work, and so far it's consistently returning wrong numbers for one type of operation. There are six values in the table, all stored as integers and all with a name equal to their value.
I'm running the following test triggers:
Trigger 1
Events
Game - Map initialization
Local Variables
Conditions
Actions
Data Table - Save 0 as "0" in the Global data table
Data Table - Save 1 as "1" in the Global data table
Data Table - Save 2 as "2" in the Global data table
Data Table - Save 3 as "3" in the Global data table
Data Table - Save 4 as "4" in the Global data table
Data Table - Save 5 as "5" in the Global data table
Trigger 2 Events
Game - Player Any Player types a chat message containing "check", matching Exactly
Local Variables
Conditions
Actions
UI - Display (Text((Name of value 1 in Global data table))) for (All players) to Subtitle area
UI - Display (Text((Name of value 2 in Global data table))) for (All players) to Subtitle area
UI - Display (Text((Name of value 3 in Global data table))) for (All players) to Subtitle area
UI - Display (Text((Name of value 4 in Global data table))) for (All players) to Subtitle area
UI - Display (Text((Name of value 5 in Global data table))) for (All players) to Subtitle area
UI - Display (Text((Name of value 6 in Global data table))) for (All players) to Subtitle area
UI - Display (Text(("0" from the Global data table))) for (All players) to Subtitle area
UI - Display (Text(("1" from the Global data table))) for (All players) to Subtitle area
UI - Display (Text(("2" from the Global data table))) for (All players) to Subtitle area
UI - Display (Text(("3" from the Global data table))) for (All players) to Subtitle area
UI - Display (Text(("4" from the Global data table))) for (All players) to Subtitle area
UI - Display (Text(("5" from the Global data table))) for (All players) to Subtitle area
What it is supposed to do is it returns the names of all the values 0/1/2/3/4/5, then it returns all the values of the names 0/1/2/3/4/5.
What actually happens is it returns this: 3 4 1 0 2 5 0 1 2 3 4 5
This means that the name is being returned wrong every time, but the value returns are working fine.
The table also wouldnt let me type in a value = 0 for returning its name, for some reason I could only enter positive numbers above 1, which seems like a bug to me.
Can anyone share and insight about what the hell is going on here? It seems to just be feeding me numbers in a random order.
You got all the numbers when you started from 1, so I guess they just decided not to index it from 0. That makes it more intuitive for people who are not used to programming.
About the order. I believe the data table is implemented as a hash map. This means that the text you give them are hashed to some integer. That integer should be seemingly random, and collisions should be rare (a collision are two strings that hash to the same thing). This means that whatever keys you add to the data table, don't expect them to have any logical order when read out like you do. When you ask for the name of the i't key, they just transverse the hash table and output the i'th key they come across (again, it's not sorted, just "randomly" ordered).
The benefit of a hash table is that when you ask for the value in a specific key "foo", they just have to hash "foo", and look at that entry of the hash table, which is pretty fast. When you add stuff to a hash map, you also just hash the string and insert at that index in the hash table (which is probably just an array).
Of course, I don't work at blizzard, so any comments about their implementation is purely speculation on my part, but it would make sense if that's how they implemented it.
When you post code to the forums, do it in
<code>...</code>
tags.