• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Referring trigger name to a string variable?

Status
Not open for further replies.
Level 3
Joined
Jun 25, 2011
Messages
39
Hi everyone!

I am working on my custom map and for my system I need some help that I couldn't find on the internet!

The situation is the following:
I have a trigger which assorts the name of a spell by a character (actually i wrote a string.split trigger in gui LOL) and saves them in a string array. Is that possible, to use these "strings" to referr to a trigger as their name?

I mean I want to use the sbstr[x] as the name of the ran trigger in the way: Trigger - Run(sbstr[x]) or something like that.

Is that possible? I found out that I could use the hashtables as the reference, but I am not sure if it could work.

So many thanks,
Sincerely, Sarungar!
 
Level 3
Joined
Jun 25, 2011
Messages
39
Not even and thanksfully not even. :D

I found a way, although it still needs some predefining and some heed.

First of all I created the "core" triggers with simple one worded names. I have stored all of them in a hashtable and i stored their names in a string array with a same name.
Secondly I created the skills with the name trigger1_trigger2_trigger3_..._name so my split trigger can set them off. I store it in an adjunct variable just for the trigger itself.
Then running trough the new array and comparing its keywords to the stored array and if a match found, then call the inherent trigger from the hashtable with the same index.

It is 100% GUI and it is working fine without leaks. I implemented the damage detection system found on this site to my map and with my newly written spell secondary effect system I can create various spells with magic schools (eg.: elementary magic, divine magic etc.etc.) with common attributes like fire type magics do ignite creatures and do lesser damage to water type creatures.

The goals are in: To reach alpha state my spells should have use and apply secondary effect according to their elements and for the final release I want to repeat it with items and passive skills (for enchanting and so..).

I see a very huge possibility in this and setting up the system is quite easy, but takes some time.
 
Level 39
Joined
Feb 27, 2007
Messages
5,010
1. Why do you need to do this? It seems much easier to have individial events and conditions for each spell. The way you want it to work seems ass-backwards and convoluted for no reason. What functionality do you expect to gain?

2. In any case the easiest route is probably just to use 1 hashtable that stores each spell's associated triggers. Load the trigger handles from the hashtable and execute them. For storing the triggers (which you'd do in some map init trigger) you could use either the spell's integer ID as the key or just the spell's name. I think using the AbilityID would be much easier, and in fact it would also make it a much more direct approach than what you're doing. For example:

Name: Spell A
ID: A002
Number of associated triggers: 4
Trigger 1: Do Stuff
Trigger 2: Do Things
Trigger 3: Stop Dudes
Trigger 4: Punch Dudes
  • Set AID = (Ability Being Cast)
  • Custom script: set udg_ID = udg_AID //Both are integers but GUI won't let you 'typecast' from ability ID to integer
  • Set N = (Load Key("NumTrigs") of Key(ID) from YourHash) //in this case N=4
  • For each Integer A from 1 to N do (Actions)
    • Loop - Actions
      • Set TrigVar = (Load Key("Trig"+I2S(Integer A)) of Key(ID) from YourHash)
      • Trigger - Run TrigVar without checking conditions
3. I think ultimately even the method I suggested is going to become tedious to keep up with as you keep adding spells and items to the map. You will probably be better off storing booleans like IsFire, IsHoly, etc. in a hash with the ability ID as a key and then executing the appropriate triggers based on the boolean data you get for each casted spell.
 

EdgeOfChaos

E

EdgeOfChaos

Hmm? I don't think there's the need for any of that. The ExecuteFunc command takes a string, and runs the specified function. Of course, you need to do some minor JASS for this, but nothing tough.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
I mean I want to use the sbstr[x] as the name of the ran trigger in the way: Trigger - Run(sbstr[x]) or something like that.
Triggers do not have names... You will need to use hashtables to map an arbitrary name to a trigger.

Do be aware string hash is extremely collision prone. Professional grade hashing algorithms produce at least 160 bit digests. In contrast the string hash native of WC3 produces just 32 bit digests. After hashing 100 odd unique strings with WC3's string hash the probability that a collision has occurred is significant. Without appropriate collision detection and mitigation it is possible to run into some pretty serious and hard to diagnose bugs.

A simple collision detection and mitigation approach might be to use a hashtable with parent string hash and child index. Index is used to form a list of mappings, with a reference to the hashed string and the object mapped to it. Index is incremented until the mapped string matches the hashed string which is then used as the requested mapping, or until no more mappings exist in which case the requested mapping does not exist. Mostly only a single mapping exists per string hash so tests will be very fast.
 
Status
Not open for further replies.
Top