• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[vJASS] Trigger with multiple events

Status
Not open for further replies.
Level 5
Joined
Oct 2, 2013
Messages
95
So I decided to learn vJASS and now, in order to get some skills, I'm converting some of the main spells on my map ( that are GUI ) to vJASS. I was using multiple triggers per spell when I found out that on vJASS, i would only need a single trigger per spell.

So lets suppose I've got a spell that first triggers when spell is cast, displaying the message "It's cast!" and then, on a periodic event, damages the target of that spell by x.

On GUI, I would use 2 triggers - One with "Unit casts a spell" event and other on a "Every 1 seconds of game time".

How It is possible to achieve such effect in vJASS with a single trigger?

Also, another lil question : On vJASS, I wouldn't need to use indexing for MUI spells right? I could use private vars inside a scope for the same purpose?
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
GUI merges the trigger leaf with the trigger object. In jass, you can create triggers from script. So you may stuff all of your code into a single trigger leaf if you wanted. Trigger leaves however feature an initializer function that is called "InitTrig_TriggerName" that you can use as an entry point and thus might consider less/more splitting.

For the code just convert some triggers from GUI, then you will see the build of the trigger object.

Of course you need indexing if you want to allocate parts of data structures ingame. Making vars private within scopes in vJass separates them from other scopes but that is static. You want to create new spell instances ingame, so you need new variables/memory for each. vJass provides structs that give you a nice object oriented feeling, so indexing becomes standardized and rather simple.
 
Level 5
Joined
Oct 2, 2013
Messages
95
Ok...

But how could it be possible for me to create a spell such as the one I mentioned at my first post? As I said, in GUI I would simply use two triggers, one with an event that fires when the unit castes the spell, and the other every 1 second.

I mean, I get it that it CAN be done, i wanna know how.

And why would I need indexing when i've got private vars?
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
Private, in the sense of vJass, means you limit some variable or other feature to the current scope.

JASS:
scope abc
    private integer def

^ def is limited to abc, abc would be your spell. However, def would still be a single variable because the source code is static, casting a new spell instance does not copy the script, you would not gain a 2nd def variable.

To explain you how structs work:

JASS:
struct abc
    integer def

Behind the scenes, def here will be translated into an array, an indexed data struture with fields of the same type. So if you were to present a unique index per spell instance, each one would gain another part of def.

The indexing is typically done by the inbuilt allocate/create, the deindexing by the deallocate/destroy method.

JASS:
local abc abcInstance = abc.create()

^ that would fetch a new index within abc and store it in the abcInstance variable (which is actually a disguised integer variable).

JASS:
call BJDebugMsg(I2S(abcInstance.def))

^ that would print the current value of the def object variable assigned to the object (integer value) behind abcInstance.

It actually translates to

JASS:
call BJDebugMsg(I2S(s__abc_def[abcInstance]))

JASS:
call abcInstance.someMethod()

^ that would invoke the someMethod method of abc using the current value of abcInstance as entry object, meaning it sneakily gets passed as first function parameter and the method shall target this exact instance. In someMethod you can access the entry object via "this".

So all object instances are realized via different integer values, which are then used in data structures to assign data per object instance.


@trigger merging: As I have said above, just convert the single GUI triggers to see the code used for creating the trigger objects. You can copy those lines and put them in the same initializer, only change the trigger variables because a trigger leaf provides a global trigger variable named after the trigger leaf, so those variables would get deleted after you remove the superfluous leaves.
 
Status
Not open for further replies.
Top