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,463
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,463
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,463
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,463
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,463
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,463
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.
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top