I have an item-type array that I want triggers (pick up and drop) to be automatically defined by the name of the item, for exampleMight as well ask why you specifically need to do that, for what purpose.
I do run them from one single pick up and drop trigger and that's why I need them, to know which trigger to run. The "problem" is that I have to set the triggers manually as variables, instead of having a system that does that for me. It's just because I'm lazy.Why do you need separate triggers instead of just having a series of if blocks in a single pick up/drop trigger? What do you even need the triggers specifically for anyway? They should just work on their own.
Hashtable or Table object with the item’s rawcode as a key to store and retrieve the trigger is the best option here.
A string is not a trigger. What you are asking is to dynamically resolve the value of a trigger variable from a variable name string.
Yes this is possible. If one uses Lua. One can look up the string as a key inside the root/global table.
This is not possible with JASS since one cannot dynamically resolve trigger variables.
Thanks, this is exactly what I was wondering.A string is not a trigger. What you are asking is to dynamically resolve the value of a trigger variable from a variable name string.
Yes this is possible. If one uses Lua. One can look up the string as a key inside the root/global table.
This is not possible with JASS since one cannot dynamically resolve trigger variables.
Infinitely more reliable, faster and requires less work. Key from string might produce collisions due to the nature of hashes which would result in a hard to diagnose bug. However for JASS this is probably the best one can do, especially if one adds mitigations for collisions.What's the difference between this and @IcemanBo s suggestion of a trigger hashtable?
The difference would be to how to get to the string key for a trigger. In JASS, one defines a string, in Lua DSG said, it could be looked up in the root table. Filling a (hash)table needs to be done in both cases.You would have to manually populate a JASS hashtable with data but Lua accessing the root table would already have that data in it.
Well I need to know which the matching trigger is, since:@Sk0gsHu[GG]arN the concept seems a bit off, honestly. I believe an other solution can be found. Running a trigger by an item's type would be superious, but even this should not be needed.
You don't need to convert any strings or triggers to strings or triggers. Simple If-statement will do just fine.
In your Map Initialization trigger just pair up the trigger and the item-type:
Then make a trigger to check which item is being picked up:
Set ItemType[0] = Crown of Kings +5
Set ItemTrigger[0] = YourTrigger <gen>
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Item-type of (Item being manipulated)) Equal to ItemType[0]
Then - Actions
Trigger - Turn on ItemTrigger[0]
Else - Actions
Yes that's what I'm doing already, I just wanted to know if I could convert a string to a trigger because it would simplify, not having to add it manually. As I said before it's not a problem, it's already working.You're overcomplicating something fairly trivial for no reason. All of that can be done in 2 triggers. With or without a system, you have to do it manually. You can match the item type to the trigger by matching the array: e.g. MyItemType[1], ItemTrigger[1].
This is it, nothing else to it. I just want to reduce the amount of variables needed to be set manually.But I'm not even sure why there needs to be a sperate trigger for each item type... maybe the intention could be elaborated some more.
Both JASS and Lua use a hash table structure internally to resolve variables dynamically at run time. The difference is Lua allows one access to this global hash table as a normal table and perform normal table operations on it while JASS only allows access to it via staticly compiled code.The difference would be to how to get to the string key for a trigger. In JASS, one defines a string, in Lua DSG said, it could be looked up in the root table. Filling a (hash)table needs to be done in both cases.
The same as the trigger variable name always looks. The only difference is that one can create it and resolve it dynamically.How does the string key for a trigger from the Lua root table looks like exactly?
Except in Lua where it can be done from a string. As long as naming is consistent (another source of error) it will work.You're overcomplicating something fairly trivial for no reason. All of that can be done in 2 triggers. With or without a system, you have to do it manually. You can match the item type to the trigger by matching the array: e.g. MyItemType[1], ItemTrigger[1].
If statements are also a lot slower. O(n) complexity as opposed to O(1).You don't need to convert any strings or triggers to strings or triggers. Simple If-statement will do just fine.
For maintainability. If an item needs triggered code then a trigger can be made, the trigger will be found, the trigger will run and effectively it will automatically be fed into the system for use. If the item does not need a trigger then no trigger will be made, no trigger will be found and no trigger will be run. Each trigger is functionally separate from each other so modifying the mechanics of 1 item will not touch the code of any other item.But I'm not even sure why there needs to be a sperate trigger for each item type... maybe the intention could be elaborated some more.
I knew I was right.For example a trigger called "Test Trigger" will automatically create a trigger variable called "gg_trg_Test_Trigger". One could convert the trigger name to its resulting variable by prefixing with "gg_trg_" and then substituting all white spaces ' ' with '_'. One could then look this up in the global root table and resolve the trigger object, from a string. No manual assignment required.
Ah ok, it sounds cool then.Yes the global root table still has the value assigned explicitly. However that is done with code automatically generated by World Editor, and not manually entered.