| 03-02-2009, 01:03 PM | #1 |
JASS:library testlib function testlib takes trigger trig1, trigger trig2 returns nothing call BJDebugMsg(I2S(H2I(trig1))) call BJDebugMsg(I2S(H2I(trig2))) endfunction endlibrary JASS:scope test initializer Init globals trigger trig1 = CreateTrigger() trigger trig2 = CreateTrigger() endglobals private function Init takes nothing returns nothing call BJDebugMsg(I2S(H2I(trig1))) call BJDebugMsg(I2S(H2I(trig2))) call testlib(trig1, trig2) endfunction endscope I´m calling testlib with 2 different triggers but it only gets the last one. What I am doing wrong? |
| 03-03-2009, 01:19 PM | #2 |
This is very odd, I pasted the same code and the same happens. I thought for a second it was a jasshelper bug, but I looked at the compiled code and it isn't. |
| 03-03-2009, 01:25 PM | #3 |
This fixes it: JASS:library testlib function testlib takes trigger trigg1, trigger trigg2 returns nothing call BJDebugMsg(I2S(H2I(trigg1))) call BJDebugMsg(I2S(H2I(trigg2))) endfunction endlibrary It reminded me that there are glitches with variable shadowing when you do more than one per function. This is one of the reasons encapsullation is your friend always make a habit to make stuff private unless you want something else to use it, in a scope, for example, you are not likely to ever need something to be public unless there's something flawed on the design. JASS:scope test initializer Init globals private trigger trig1 = CreateTrigger() private trigger trig2 = CreateTrigger() // by hiding stuff to code that doesn't need it, we will prevent conflicts and pitfalls like that one. // besides, it is easier to update stuff since you will know the rest of the code doesn't depend on // these variables. endglobals private function Init takes nothing returns nothing call BJDebugMsg(I2S(H2I(trig1))) call BJDebugMsg(I2S(H2I(trig2))) call testlib(trig1, trig2) endfunction endscope |
| 03-03-2009, 01:31 PM | #4 |
why not just use private:globals private trigger trig1 = CreateTrigger() private trigger trig2 = CreateTrigger() endglobals |
| 03-03-2009, 01:54 PM | #5 |
Ah thank you. For some reason I allways made triggers public If i remember right, it´s, because the first vJass code i ever saw was some spell by Cassiel, where he even used "public trigger SomeTrig" in globals. Kinda made sense for me, since you could see triggers as sth, that is not limited to its scope or has to exist multiple times at once |
| 03-03-2009, 02:22 PM | #6 |
public is still much better than nothing ...because you wont get unintended overlaps by mistake ... |
| 03-03-2009, 03:27 PM | #7 | |
Quote:
|
| 03-03-2009, 03:48 PM | #8 |
it allows ppl that use it to refer to that trigger outside of the scope, if they so choose, if not, there is still the open option |
| 03-03-2009, 04:13 PM | #9 |
Members are neither public nor private by default. |
