Save as key of Last created unit in hashtable

kingkwong92

Well-Known Member
Reaction score
25
I can't seem to save the variable that I want using the key of my last created unit.
Is this a limitation of the WE?
 

Accname

2D-Graphics enthusiast
Reaction score
1,462
Dont know what you are talking about, could you try to clarify? Maybe post the triggers as far as is possible for you and describe the situation.
 

kingkwong92

Well-Known Member
Reaction score
25
Trigger:
  • Hashtable - Save beam_angle as 1 of (Key (Last created unit)) in beam_hash


I tested it using this:
Trigger:
  • Set real = (Load 1 of (Key (Last created unit)) from beam_hash)
    • Game - Display to (All players) the text: (String(real))
 

Accname

2D-Graphics enthusiast
Reaction score
1,462
Do you use these 2 lines in the same trigger or in 2 different triggers?
Because (last created unit) will change over time and might be reset to "no unit" once the next trigger is started.
 

kingkwong92

Well-Known Member
Reaction score
25
Lol I just realised I forgot to create the hashtable. Sorry about the silly mistake. Thanks
BTW how do you guys organize your hashtables?
I saw one of you comments another post about string keys or something like that.
I currently sort them by spells but I saw others use a hashtable for each type of variable.
It would be good to get your opinion before my map got too big
 

vypur85

Hibernate
Reaction score
803
Essentially, if you know what you're doing, you probably only need one hashtable for the whole map.

But if you're a lil perfectionist, you can segregate your hashtables into different types of variables. This way you don't need to create one hashtable for every spell you do.

> It would be good to get your opinion before my map got too big
The map won't go too big with the amount of hashtables you have. It's just that there is a limit as to how many hashtables you can have in a map. Once you exceed the limit, they won't work as intended.

My advice:
Use one hashtable for each variable type.
 

kingkwong92

Well-Known Member
Reaction score
25
Do you know how to use the key string? Instead of using the numbers and having to remember them
 

Accname

2D-Graphics enthusiast
Reaction score
1,462
Use the method "Hashtable - Get String ID" to convert a string to an integer ID to be used in a hashtable.
By the way, whether you use integers directly or use strings does not matter. The performance and memory consumption should be equal. Its just that strings are easier to comprehend then raw numbers.
 

kingkwong92

Well-Known Member
Reaction score
25
I think I will use the one hashtable for my whole map. I used the get String ID it looks like this
Trigger:
  • Hashtable - Save beam_distance as (Key (String(beam_angle))) of (Key (Picked unit)) in beam_hash

I used get string ID and then converted real into a string. What happens if my real is the same number as another real? Does it return the same key string?


Im looking at tutorials and resources section but I can't get in. The link must be faulty or there is something wrong with my computer. So while we are still talking about hashtables, how do I remove leaks?
 
Last edited:

vypur85

Hibernate
Reaction score
803
> Im looking at tutorials and resources section but I can't get in.
It's not your problem. It's something wrong with the link itself. Since the site upgrade, many things are not well organised. It should be corrected soonish... I hope. Use this link: http://www.thehelper.net/forums/tutorials-and-resources.67/

To clean hashtable data, just clear the child hashtable of your desired key handle.
 

kingkwong92

Well-Known Member
Reaction score
25
I used the get Hashtable - string ID (angle) of key of (unit).
However when I use another ability that also uses the variable angle from the hashtable, its all messed up.
Are the get string ID of the same real variable overwriting each other?
 

Accname

2D-Graphics enthusiast
Reaction score
1,462
Converting a string to a hashCode might not return the same value for strings with equal content. If you want to use a real you are a little bit out of your luck, but on the other hand, you are probably using it wrong in the first place. There should never ever (or rather: very very rarely) be a reason to use a real for a key.
 

kingkwong92

Well-Known Member
Reaction score
25
Could you please help me with sotting out my hashtable?
I use Hashtable - save [angle] as key(string[angle]) of key[unit] in [Hash]
Is this right?
 

Accname

2D-Graphics enthusiast
Reaction score
1,462
why do you use the angle as both key and value? That does not make any sense.
 

kingkwong92

Well-Known Member
Reaction score
25
Im trying to save the angle which is a real. I read somewhere that instead of using integers like
save angle as 1 of key[unit]. I thought I could change the 1 to something else easier to understand.
Sorry, I didn't really understand how to do it.
 

Accname

2D-Graphics enthusiast
Reaction score
1,462
Look, a hashtable is a data structure you use to store your data in a way that you can easily access it.
You use 2 keys to identify 1 value.
In this case you want to store some kind of angle in the map. But if you also use the angle as a key it would mean that you need to know the angle before you can load it from the map again. This is kinda pointless. Because if you already know the angle you dont need to load the angle from the map again. Its redundant information.
 

jonas

You can change this now in User CP.
Reaction score
67
I think what you want is to use the string "angle", not the string String(angle).
The first one is "angle", the second one is, e.g., "0.04" or "34.0", depending on the angle.
You can also think of it like this: The keys are the name of the book and the chapter in which your data is written down.
 

jonas

You can change this now in User CP.
Reaction score
67
Use value and then type 'angle'. To be safer, use a string variable that you initialize accordingly.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top