1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still haven't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. Weave light to take you to your highest hopes - the 6th Special Effect Contest is here!
    Dismiss Notice
  4. Lead your forces to battle in the 15th Techtree Contest. The call is yours, commander!
    Dismiss Notice
  5. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

Referring trigger name to a string variable?

Discussion in 'World Editor Help Zone' started by Sarungard, Dec 22, 2016.

  1. Sarungard

    Sarungard

    Joined:
    Jun 25, 2011
    Messages:
    36
    Resources:
    0
    Resources:
    0
    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!
     
  2. Fruit Forest

    Fruit Forest

    Joined:
    May 16, 2016
    Messages:
    733
    Resources:
    1
    Maps:
    1
    Resources:
    1
    You can't run trigger by using a string variable, you have to write by hand all actions for all spells like if ability being cast is spell1 then run trig1 etc etc.
     
  3. Sarungard

    Sarungard

    Joined:
    Jun 25, 2011
    Messages:
    36
    Resources:
    0
    Resources:
    0
    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.
     
  4. Pyrogasm

    Pyrogasm

    Joined:
    Feb 27, 2007
    Messages:
    3,788
    Resources:
    1
    Spells:
    1
    Resources:
    1
    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.
     
  5. 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.
     
  6. Dr Super Good

    Dr Super Good

    Spell Reviewer

    Joined:
    Jan 18, 2005
    Messages:
    25,996
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    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.
     
  7. Pyrogasm

    Pyrogasm

    Joined:
    Feb 27, 2007
    Messages:
    3,788
    Resources:
    1
    Spells:
    1
    Resources:
    1
    That feel when you mean to suggest using ExecuteFunc in your post but then get sidetracked explaining other stuff and then forget.... xD