HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Scopes and local triggers, some questions and comments...

01-20-2008, 04:14 PM#1
Jitse
Hi ho :)

I'm new to JASS, and I've read Cohadar's Little School of ABC. Now good practice would be:

Collapse JASS:
scope TestTrigger

private function Actions takes nothing returns nothing
    call BJDebugMsg("This is the map initialization.")
endfunction

//===========================================================================
public function InitTrig takes nothing returns nothing
    local trigger trig = CreateTrigger()
    call TriggerAddAction( trig, function Actions )
endfunction

endscope

Now, how do I make the trigger actually get triggered at map initialization? Because of the local trigger, WE won't do it for you anymore. What it internally does is:

Collapse JASS:
function RunInitializationTriggers takes nothing returns nothing
    call ConditionalTriggerExecute(gg_trg_TestTrigger)
endfunction

But this global has become null, because I now use a local trigger variable. That brings me to another question. If Cohadar recommends to use local triggers, it leaves a big mess of nulled global triggers behind.

And my third question, if this is good practice (which I somehow agree, because it makes it more readable and independent), how come I never actually saw any map designer using this way of coding? To test this I just downloaded some random (but popular) maps from this site. But none of them does it like this.

Take...

(12) We Were Snipers - Mr.Safety
Caster System - Vexorian
(12) Call to Arms - Panto

Those maps for example. And many of the other big maps are even totally in GUI! How can that be efficient? :p
01-20-2008, 05:25 PM#2
TaintedReality
Quote:
Now, how do I make the trigger actually get triggered at map initialization? Because of the local trigger, WE won't do it for you anymore. What it internally does is:

You can just run your actions in the InitTrig function. You don't need an actual trigger to run things at map initialization, because map initialization is when the triggers are all created.

Quote:
But this global has become null, because I now use a local trigger variable. That brings me to another question. If Cohadar recommends to use local triggers, it leaves a big mess of nulled global triggers behind.

You don't need to make triggers in GUI. At map initialization just create your local triggers and set them up. Libraries can have an initialization function which runs at map init, so within each of your libraries you can set up triggers specific for it, without ever creating global trigger variables or anything. With vJass you really don't need to use the GUI Trigger Editor at all.

Quote:
And my third question, if this is good practice (which I somehow agree, because it makes it more readable and independent), how come I never actually saw any map designer using this way of coding? To test this I just downloaded some random (but popular) maps from this site. But none of them does it like this.

vJass and all this stuff is relatively new, and War3 modding is declining. Most of the big and popular maps have been around for a while. And, really, how organized and efficient your code is has very little effect on how good or popular your map is.
01-20-2008, 05:54 PM#3
Jitse
Quote:
Originally Posted by TaintedReality
You don't need to make triggers in GUI. At map initialization just create your local triggers and set them up. Libraries can have an initialization function which runs at map init, so within each of your libraries you can set up triggers specific for it, without ever creating global trigger variables or anything. With vJass you really don't need to use the GUI Trigger Editor at all.
What do you exactly mean with, 'at map initialization'? Do you mean just in the custom map script? Isn't that still using the GUI Trigger Editor then? And if I don't use it anymore, isn't it quite annoying triggers aren't decently categorized in a treeview in the GUI Trigger Editor?

And if you say I shouldn't use the GUI Trigger Editor anymore, what's the point of Cohadar's Little School of ABC post, where he makes the GUI to JASS converted code into some decent code that - according to him - should always be used. Like for example the scope having the same name as the GUI trigger thing in the treeview and such.

I tried the thing with the initialization function, and libraries and such, but I don't really get it yet. Could you give a code example of what you mean? A library with initialization, and a local trigger in a scope not using global trigger variables and such. =/

Edit: Topics should really have a "Who's reading" feature or so, I'm really eager to get the answer, because it's kind of crucial to develop my maps any further. :p
01-20-2008, 06:17 PM#4
TaintedReality
Quote:
What do you exactly mean with, 'at map initialization'? Do you mean just in the custom map script? Isn't that still using the GUI Trigger Editor then? And if I don't use it anymore, isn't it quite annoying triggers aren't decently categorized in a treeview in the GUI Trigger Editor?

What I've started doing is having the custom map script just import a "main.j" file which then includes other files. So after initially setting it to import main.j, I never have to go back to the Trigger Editor, I just edit the .j files. I also keep everything split up into different files and libraries, all included into the main.j file.

Quote:
I tried the thing with the initialization function, and libraries and such, but I don't really get it yet. Could you give a code example of what you mean? A library with initialization, and a local trigger in a scope not using global trigger variables and such. =/

Just a warning, I've never looked at scopes, but I think they would be better here. I just use libraries for everything =P. But this will give you the general idea.

Collapse JASS:
library ArchmageHero intializer Init requires Whatever

private function WaterElemental takes nothing returns nothing
    //...
endfunction

private function Blizzard takes nothing returns nothing
    //...
endfunction

private function MassTeleport takes nothing returns nothing
    //...
endfunction

private function Init takes nothing returns nothing
    local trigger WaterElementalTrig = CreateTrigger()
    local trigger BlizzardTrig = CreateTrigger()
    local trigger MassTeleportTrig = CreateTrigger()
    local integer i = 0
    local player p
    loop
        set p = Player(i)
        call TriggerRegisterPlayerUnitEvent(WaterElementalTrig,p,EVENT_PLAYER_UNIT_SPELL_EFFECT,null)
        call TriggerRegisterPlayerUnitEvent(BlizzardTrig,p,EVENT_PLAYER_UNIT_SPELL_EFFECT,null)
        call TriggerRegisterPlayerUnitEvent(MassTeleportTrig,p,EVENT_PLAYER_UNIT_SPELL_EFFECT,null)
        set i = i + 1
        exitwhen i>=12
    endloop
    call TriggerAddAction(WaterElementalTrig,function WaterElemental)
    call TriggerAddAction(BlizzardTrig,function Blizzard)
    call TriggerAddAction(MassTeleportTrig,function MassTeleport)
    //Add some conditions too if you want. Personally, I just check conditions within the Actions function.
    set WaterElementalTrig = null
    set BlizzardTrig = null
    set MassTeleportTrig = null
    set p = null
endfunction

endlibrary

I split it up into each hero, system, and some individual functions get their own file/library. But you can split it up however you want.

Quote:
And if you say I shouldn't use the GUI Trigger Editor anymore, what's the point of Cohadar's Little School of ABC post, where he makes the GUI to JASS converted code into some decent code that - according to him - should always be used. Like for example the scope having the same name as the GUI trigger thing in the treeview and such.

I'm not sure, I generally try to avoid cohadar :). He has some good ideas, but if you actually want to make maps, rather than consider abstract programming ideals, I wouldn't get too wrapped up in them. I find this way to be very easy and organized. You can obviously use whatever method you think best though, this is just what I do.
01-20-2008, 06:33 PM#5
Jitse
I see, but what's the advantage of the whole Jass NewGen Pack then? The syntax highlighting and such is all not used anymore. As well as the integrated Jass editor.

And what do you use to edit the external files? You're not going to tell me you're using Jasscraft for that, do you? I find Jasscraft horrible. It for example totally ignores the possibility of vJass use, none of the vJass keywords is highlighted properly, etc.
01-20-2008, 09:52 PM#6
TaintedReality
I use Jasscraft. I don't really care about the highlighting anymore, to tell you the truth I could just do it in notepad or something and I wouldn't really care. Every once and a while I do have to look up a function though so Jasscraft is good to have.

The advantage of the NewGen pack for me is mainly in the debugging, and of course the integrated support for vJass.
01-21-2008, 12:48 AM#7
Vexorian
Quote:
vJass and all this stuff is relatively new, and War3 modding is declining. Most of the big and popular maps have been around for a while. And, really, how organized and efficient your code is has very little effect on how good or popular your map is.
It may not have effect on popularity , but map quality decreases when you code like crap, you cannot fix the bugs yourself or you end up wasting time on finding the bugs instead of improving the map's quality, and the whole time GUI-"normal" Jass waste would mean you are either going to need a lot more time or you should get something of bad quality.

What all these 'good' maps with bad code have in common is that their authors have spent a lot of time on them.

Quote:
But this global has become null, because I now use a local trigger variable. That brings me to another question. If Cohadar recommends to use local triggers, it leaves a big mess of nulled global triggers behind
I guess you are right and we should begin to care about things that are totally meaningless.

Although if you used only local triggers, the optimizer is likely to get rid of the totally useless global triggers.

The Caster system has GUI on it for teaching purposes. The only map I was ever able to finish on time does everything differently and things like conding using GUI's generated variable or even GUI just began to sound totally impractical after I did that. It wasn't my first map project, all the previous ones had in common that they eventually became impossible to maintain, so there you go.


Quote:
I see, but what's the advantage of the whole Jass NewGen Pack then? The syntax highlighting and such is all not used anymore. As well as the integrated Jass editor.
Ever heard of war3err? Although I right now cannot use it either, too good I don't really code that much in Jass.

--
I also began to use external .j files exclusively lately, mostly because GUI stuff (including normal Jass) is not portable at all, you need the editor for that and it is quite an annoying requirement. I use gVim to edit the files.

But to share code it is better to use a map and scopes, mostly because err, some guys would never be able to understand the actual code is in a file...

--
If you need map init triggers you are doing some stuff wrong. InitTrig or library initializers if you need to control the order are more than enough.
01-21-2008, 02:30 PM#8
Jitse
@ Vexorian - I'll take a look at the optimizer about the unused global triggers. Btw. gVim is even worse. :p And yes I've heard of war3err, I was just talking about the nicely integrated Jass editor, and the highlighting and such, but nevermind.

@ TaintedReality - You can program anything in notepad, but that doesn't mean it's good to do. It's personal preference of course, but no matter how good you are at a certain scripting or programming language, syntax highlighting is always healthier for your eyes and sanity. :p

I'm concluding here that it's actually just best to have your own way of sorting things out, as long as it's efficient, which also includes using the GUI editor if you use it correctly and filter out the unused globals and such.

Thanks for all the opinions, now I've got a better overall view of everything. :)
01-21-2008, 02:34 PM#9
Vexorian
Quote:
gVim is even worse
Integration with the WE is some of the least worthful things you may find on some editor, syntax highlighting on gVim for vJass was possible for 1 year or more already. If you don't want gVim there's also notepad++ or any text editor with customizable syntax highlighting...

Quote:
I'm concluding here that it's actually just best to have your own way of sorting things out, as long as it's efficient, which also includes using the GUI editor if you use it correctly and filter out the unused globals and such.

Yes, if used correctly the GUI editor is fine.

Of course, considering that it is impossible to use it correctly, I advice against that stuff.

Edit: I mean, mutants are the least succesful maps, if you begin mixing GUI, Jass and vJass it becomes a mess very easily, specially since GUI and normal Jass require these "udg_" variables and have no scope protection nor anything, "udg_" variables and functions being always public, not forgetting that functions are always going to be placed in undefined order..., those things will eat your children, seriously. If you can deal with those abominations, go ahead, but it is more comfortable to pick up a WE "trigger" and place an scope/library there.
01-21-2008, 02:47 PM#10
Jitse
Quote:
Originally Posted by Vexorian
Edit: I mean, mutants are the least succesful maps, if you begin mixing GUI, Jass and vJass it becomes a mess very easily, specially since GUI and normal Jass require these "udg_" variables and have no scope protection nor anything, "udg_" variables and functions being always public, not forgetting that functions are always going to be placed in undefined order..., those things will eat your children, seriously. If you can deal with those abominations, go ahead, but it is more comfortable to pick up a WE "trigger" and place an scope/library there.
Ahum, obviously I meant using vJass only, but with the WE GUI Editor. If the global triggers get filtered I don't see any problems with that anymore. vJass kind of solved it all.