• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

String to Region

Status
Not open for further replies.
Level 1
Joined
Dec 1, 2015
Messages
2
Is there any way to 'convert' a string variable into the region name?

Let me elaborate,
"Set TargetString to (Entered Chat string)"
"Pick every unit in Region - (Entered Chat string) and do Unit - Issue order of unit to move to a point"

This above, basically, is what I want to accomplish. But I have no idea how. I've thought of using Hashtables and Handles, but I have no experienced with using those whatsoever. Can anyone help?
 
Level 7
Joined
Nov 19, 2015
Messages
283
Not sure if you can change a string into a region name.

You could try save all possible strings to all regions

set string[1] = room1
set region [1] = region 1

Loop 1 to n
if entered chat string = sting[x]
Pick all units in region[x]
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,255
It converts a string to a unique id to be used as a parent or child key.
It converts a string to a mostly unique integer. Being an integer and strings having no reasonable limits means that more than 1 string maps to the same integer (a hash collision). Hence why in the real world hashing algorithms like SHA-1 create 160 bit (5 integer values) long hashes since that reduces the chance of collision. Even then SHA-1 has been determined unsafe due to collisions so many modern hashing algorithms use 256 bits or more.

It is important to note the WC3 string hash function is not case sensitive as well (unlike real hash algorthims) so "ABC" and "abc" return the same value. This is both good (often case sensitivity is stupid) and bad (sometimes you want it).

For the purpose of this task I agree it will suffice since the chance of a collision in a few hundred strings is low. However it is not safe to make assumptions that the value is always unique as chances of collisions in a few thousand or ten thousand strings start to become significant due to the small hash length.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,255
So they cannot be used for hashtables directly right...
Why would they not be able to take negative numbers?

I mean, (I havent tried it) I guess that you cannot use negative numbers in a hashtable.
As far as the table is concerned, it is likely treated as an unsigned integer internally for convenience. In any case the key itself goes through a function to produce a bucket index and producing such a function that can accept any integer value (positive and negative) is trivial.

Instead of speculating try for yourself. I know for a fact from testing strings that hashtables do accept any integer value as a key and still function correctly.
 
Status
Not open for further replies.
Top