• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] jass trigger not working

Status
Not open for further replies.
Level 21
Joined
Mar 29, 2020
Messages
1,237
hey,

this is my first trigger in jass. it doesn't have any traceback malfunctions, but for some reason it just does absolutely nothing in game. what did I do wrong here?

Code:
function taken_conditions takes nothing returns boolean
    if (GetManipulatedItem() == udg_Bait ) then
    call BJDebugMsg("item moved")
    //call DisplayTextToForce( GetPlayersAll(), "moved" )
        return true
    endif
    call BJDebugMsg("not item?")
    //call DisplayTextToForce( GetPlayersAll(), "not?" )
    return false
endfunction


function taken_actions takes nothing returns nothing
    call BJDebugMsg("got trig unit")
    set udg_Carrier = GetTriggerUnit()
    if (IsTriggerEnabled(gg_trg_ChaseLoop) == false) then
    call EnableTrigger(gg_trg_ChaseLoop)
    endif
endfunction


function InitTrig_taken takes nothing returns nothing
    local trigger taken = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(taken,EVENT_PLAYER_UNIT_PICKUP_ITEM)
    call TriggerAddCondition(taken,Condition(function taken_conditions))
    call TriggerAddAction(taken,function taken_actions)
endfunction

thanks...

obv there are more parts to it, but it doesn't even show the debug stuff here that shouldn't be dependant on anything else...
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,192
I picked up the item with a unit. shouldn't that make it run?
The InitTrig_taken function seems as if it should run when the map is being initialized as it is responsible for creating the trigger and associated events, conditions and actions. If it does not get called once then all other functions are effectively unreachable and cannot ever be run unless called by some other script.
 
Level 21
Joined
Mar 29, 2020
Messages
1,237
The InitTrig_taken function seems as if it should run when the map is being initialized as it is responsible for creating the trigger and associated events, conditions and actions. If it does not get called once then all other functions are effectively unreachable and cannot ever be run unless called by some other script.
do I need to add something to make that initialize? I thought that calling it "InitTrig", does that automatically...
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,192
do I need to add something to make that initialize? I thought that calling it "InitTrig", does that automatically...
At the bottom of the custom script window there should be a field to specific initial function name to call. This was the case with JNGP and WEX long ago.

Otherwise you can use vJASS library or scope features to achieve something similar. Declare the library with the appropriate initialization function to call at map initialization.
 
Level 21
Joined
Mar 29, 2020
Messages
1,237
At the bottom of the custom script window there should be a field to specific initial function name to call. This was the case with JNGP and WEX long ago.

Otherwise you can use vJASS library or scope features to achieve something similar. Declare the library with the appropriate initialization function to call at map initialization.

oh. I just have all of my jass "triggers" the same way I had GUI. just seperate trigger tabs in the editor. somehow I don't think the jass tutorial I read covered this... :confused:2

and I'm not sure where I'm supposed to find "a field to specific initial function name to call"... are you talking about in the trigger editor of the WE or in the text editor (I'm using jasscraft)...?
 
Level 17
Joined
Mar 21, 2011
Messages
1,597
so, change that line from:

'function InitTrig_taken takes nothing returns nothing'

to:

'function taken takes nothing returns nothing'?
No,
whenever you create a trigger, you have to give it a certain name, right?

For example "My Spell"

Now, if you want a function of this trigger to run on map init, you need to call the function InitTrig_My_Spell
 
Level 21
Joined
Mar 29, 2020
Messages
1,237
No,
whenever you create a trigger, you have to give it a certain name, right?

For example "My Spell"

Now, if you want a function of this trigger to run on map init, you need to call the function InitTrig_My_Spell

sorry for being thick, but I still don't get it. isn't that line where I defined the name of that trigger? where else would I write it?
 
Level 17
Joined
Mar 21, 2011
Messages
1,597
Think about creating a GUI trigger. You open the trigger editor, and create a new trigger which has event/conditions/actions. Now, you usually give it some name.

This is what i mean by trigger name. Now we are in jass, so if you want a function of that trigger to run at init, you need to give it the name InitTrig_TRIGGERNAME, you just need to replace placeholders with underscores

Example:

Trigger with the name "Thunder Clap"

JASS:
function foo takes nothing returns nothing
call BJDebugMsg("foo")
endfunction

// runs at map init
function InitTrig_Thunder_Clap takes nothing returns nothing
call BJDebugMsg("init")
endfunction
 
Level 21
Joined
Mar 29, 2020
Messages
1,237
thanks! that seems to have done it. Is that the normal way to write maps in jass, with converted triggers, or is there a better more cohesive and fluid way that is the norm?

and do triggers with other suffixes act differently in this respect? (i.e. gg_trg etc')
 
Level 17
Joined
Mar 21, 2011
Messages
1,597
I do only use "converted" triggers, but i never use the InitTrig_ prefix to initialize.
As DSG mentioned, you can use library/scope/struct initializer when using vJass.

JASS:
library l initializer init

    private function init takes nothing returns nothing
        // runs on map init
    endfunction
  
endlibrary

scope s initializer init

    private function init takes nothing returns nothing
        // runs on map init
    endfunction
  
endscope

struct s

    method onInit takes nothing returns nothing
        // runs on map init
    endmethod

endstruct
 
Level 21
Joined
Mar 29, 2020
Messages
1,237
1. when you use a library for initialization, do you only need to stick the function of the initialization inside of it, or all related code (i.e. the condition and action functions of the trigger)?

2. Do I need to change the way I have been writing functions in order to have them in libraries, or just stick the word "private" at the beginning?

If you can point me in the direction of a relevant tutorial on libraries that would be great too, I couldn't find anything that specifies on vjass libraries...

thanks!
 
Level 17
Joined
Mar 21, 2011
Messages
1,597
1. You dont need to put all related code into the library, but i would suggest it. See it as a wrapper for your trigger.
2. No, you dont even have to make them private. Private keyword means, that the function is not visible outside the library. So you can call the function ONLY inside the library.
Private keyword is very important to protect your stuff from wrong usage.

You can take a look at the JassHelper Manual: WC3 Modding Information Center - VJASS Documentation
 
Status
Not open for further replies.
Top