HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Passing multiple trigger to a library function bugs

03-02-2009, 01:03 PM#1
Hans_Maulwurf
Collapse JASS:
library testlib

function testlib takes trigger trig1, trigger trig2 returns nothing
    call BJDebugMsg(I2S(H2I(trig1)))
    call BJDebugMsg(I2S(H2I(trig2)))
endfunction

endlibrary

Collapse 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?
Attached Images
File type: jpgsametrig.jpg (58.2 KB)
03-03-2009, 01:19 PM#2
Vexorian
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
Vexorian
This fixes it:

Collapse 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.

Collapse 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
akolyt0r
Collapse why not just use private:
globals
    private trigger trig1 = CreateTrigger()
    private trigger trig2 = CreateTrigger()
endglobals
03-03-2009, 01:54 PM#5
Hans_Maulwurf
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
akolyt0r
public is still much better than nothing ...because you wont get unintended overlaps by mistake ...
03-03-2009, 03:27 PM#7
Vexorian
Quote:
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.
But there really is no point in making a spell's trigger public. Unless you intended them to be used by another scope, but then , you should have made it a library, not a scope.
03-03-2009, 03:48 PM#8
emjlr3
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
Captain Griffen
Members are neither public nor private by default.