• 🏆 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] Local trigger

Status
Not open for further replies.
Level 8
Joined
May 9, 2010
Messages
266
Hey guys!
I know, there are a lot of topics like this already, but i`ve read em and i still cant solve my problem.
I have a trigger that is disabled until a spell would be casted. This trigger should run another trigger (kinda loop).
So i have a next code:

JASS:
scope RunScope initializer Init
function GroupCounter takes nothing returns nothing
set bj_groupCountUnits = bj_groupCountUnits + 1
endfunction
function IsGroupEmpty takes group g returns boolean
    call ForGroup(g, function GroupCounter)
    return bj_groupCountUnits==0
endfunction

function RunActions takes nothing returns nothing
    set udg_TempPoint = GetUnitLoc(GetTriggerUnit())
    set udg_TempPoint2 = GetSpellTargetLoc()
    set udg_SS_RA = bj_RADTODEG * Atan2(GetLocationY(udg_TempPoint2) - GetLocationY(udg_TempPoint), GetLocationX(udg_TempPoint2) - GetLocationX(udg_TempPoint))
    set udg_SS_Unit = CreateUnit(GetTriggerPlayer(),udg_SS_UnitType, GetLocationX(udg_TempPoint) + udg_SS_BasicOffset * Cos(udg_SS_RA * bj_DEGTORAD),GetLocationY(udg_TempPoint) + udg_SS_BasicOffset * Sin(udg_SS_RA * bj_DEGTORAD), udg_SS_RA)
    // -
    set udg_SS_HandleId0 = GetHandleId(udg_SS_Unit)
    call SetUnitPathing( udg_SS_Unit, false )
    // -
    set udg_SS_SpeedFactor = ( udg_SS_SpeedFactor * udg_SS_Period )
    set udg_SS_LiquidResistance = ( ( 6.00 * bj_PI ) * ( udg_SS_SlowLiquidFactor * udg_SS_Density ) )
    // -
    call SaveUnitHandleBJ( udg_SS_Unit, StringHashBJ("Unit"), udg_SS_HandleId0, udg_SS_hash )
    call SaveRealBJ( udg_SS_RA, StringHashBJ("Angle"), udg_SS_HandleId0, udg_SS_hash )
    call SaveRealBJ( udg_SS_DamageFactor, StringHashBJ("DF"), udg_SS_HandleId0, udg_SS_hash )
    call SaveRealBJ( udg_SS_SpeedFactor, StringHashBJ("SpeedFactor"), udg_SS_HandleId0, udg_SS_hash )
    call SaveRealBJ( udg_SS_Size, StringHashBJ("Size"), udg_SS_HandleId0, udg_SS_hash )
    call SaveRealBJ( udg_SS_Density, StringHashBJ("Density"), udg_SS_HandleId0, udg_SS_hash )
    call SaveRealBJ( udg_SS_SlowFactor, StringHashBJ("SlowF"), udg_SS_HandleId0, udg_SS_hash )
    call SaveRealBJ( udg_SS_EnergyFactor, StringHashBJ("EF"), udg_SS_HandleId0, udg_SS_hash )
    call SaveRealBJ( udg_SS_LiquidResistance, StringHashBJ("LR"), udg_SS_HandleId0, udg_SS_hash )
    call SaveRealBJ( 1.00, StringHashBJ("SLFX"), udg_SS_HandleId0, udg_SS_hash )
    // -
    call SaveIntegerBJ( udg_SS_SpellTypeDetector, StringHashBJ("STD"), udg_SS_HandleId0, udg_SS_hash )
    call SaveStringBJ( udg_SS_OnExlodeOrder, StringHashBJ("OnEO"), udg_SS_HandleId0, udg_SS_hash )
    call SaveIntegerBJ(udg_SS_OnExplodeSpell, StringHashBJ("OnES"), udg_SS_HandleId0, udg_SS_hash )
    // -
    call SaveStringBJ( udg_SS_StrikeSFX, StringHashBJ("StrikeSFX"), udg_SS_HandleId0, udg_SS_hash )
    // -
    call SaveStringBJ( udg_SS_BounceSFX, StringHashBJ("WallBounceSFX"), udg_SS_HandleId0, udg_SS_hash )
    // -
    call SaveBooleanBJ( false, StringHashBJ("ISOBS"), udg_SS_HandleId0, udg_SS_hash )
    // -
    call SetUnitMoveSpeed( udg_SS_Unit, 0.00 )
    call GroupAddUnit( udg_SS_group,udg_SS_Unit)
    call UnitAddAbility( udg_SS_Unit,'Amrf' )
    call UnitRemoveAbility( udg_SS_Unit,'Amrf' )
    call SetUnitScale(udg_SS_Unit, udg_SS_Size * 0.01, udg_SS_Size * 0.01, udg_SS_Size * 0.01)
    call SetUnitTimeScale( udg_SS_Unit, ( udg_SS_AnimationFactor * udg_SS_SpeedFactor*0.01 ) )
    call SetUnitFlyHeight( udg_SS_Unit, ( udg_SS_Size / udg_SS_HeightFactor ), 100.00 )
    call RemoveLocation(udg_TempPoint)
    call RemoveLocation(udg_TempPoint2)
    
    if ( IsGroupEmpty(udg_SS_group) == false ) then
        call EnableTrigger( gg_trg_engin_periodic_loop )
    endif
endfunction

//===========================================================================
function Init takes nothing returns nothing
    local trigger t = CreateTrigger()
    call DisableTrigger( t )
    call TriggerAddAction( t, function RunActions )
endfunction

endscope

It doesnt work because of local trigger. I cant understand why it doesnt work :C Could u help me ? =)
 
Level 8
Joined
May 9, 2010
Messages
266
You need an event which fires, in your case, "local trigger t"
i.e a spell effect event. ( after an ability is used )

RunAction is only running when trigger t is executed,
But currently that trigger is disabled and not
registered to any event.

hmmm... i`m pretty bad in JASS, i`m just learning it. Could you create an example of the stuff you said? =p
 
In your case you probably have a spell, so to bind an event you will use:
call TriggerRegisterAnyUnitEventBJ(whichtrigger, whichevent).

Here, t is your trigger, and for the exact event what you need, you can easily
look it up when you convert a GUI trigger into JASS. (just to look for how the event is called)

Then functions RunActions will be executed on this event. (if trigger is not disabled)
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
This will never work.

local trigger t is disabled
This means that t will never run via any events (maybe via direct trigger executions but I doubt that).
Anyway, because it is local and you have no way to access the trigger handle from outside that initialization function, you are not able to enable the trigger again.
This trigger will be disabled the entire game.

Also... if you are unsure of what to use as the events, you can create a GUI trigger, add the event there and change it into custom text.
That way, I always look how certain functions are named and what parameters I should use.
 
Level 8
Joined
May 9, 2010
Messages
266
In your case you probably have a spell, so to bind an event you will use:
call TriggerRegisterAnyUnitEventBJ(whichtrigger, whichevent).

Here, t is your trigger, and for the exact event what you need, you can easily
look it up when you convert a GUI trigger into JASS. (just to look for how the event is called)

Then functions RunActions will be executed on this event. (if trigger is not disabled)

The problem is that the trigger is disabled =) but i still want to execute trigger and turn it off when it`s needed.
This will never work.

local trigger t is disabled
This means that t will never run via any events (maybe via direct trigger executions but I doubt that).
Anyway, because it is local and you have no way to access the trigger handle from outside that initialization function, you are not able to enable the trigger again.
This trigger will be disabled the entire game.

Also... if you are unsure of what to use as the events, you can create a GUI trigger, add the event there and change it into custom text.
That way, I always look how certain functions are named and what parameters I should use.
Thank you, i didnt know that.
By the way, this triggers were made as GUI customs scripts. But now I want them to be overworked to JASS to optimise group scripts.
I have seen some systems witch contains exactly functions like
"function blahblah takes nothing returns nothing"
but i dont know how to do that with GUI. If I could, i wouldn`t use JASS at all =)
 
Level 8
Joined
May 9, 2010
Messages
266
In GUI, writing functions and using them properly is harder than just using JASS.

Why dont you explain what you want to achieve?
When is the trigger supposed to run?
When is the trigger supposed to be disabled?

Oh, well, its pretty hard to explain with my english :p
Lets get it started.
I have a GUI trigger witch contains all special initialization (damage etc)
it just must be GUI. This trigger should run next trigger witch i have posted in this thread. This trigger contains some hashtable moments etc. Is just must be so, without any additional events etc. That`s how my system works.
Problem: the 2nd trigger doesnt run when i use local trigger t. But it works fine with this ugly global trigger gg_trig_bluhbluh
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
The problem is that it is local.
A local variable (in this case a trigger) cannot be accessed from outside that function.
You will have to make a global variable of type trigger and use that one instead of the local.
Every trigger (the thing at the left of the screen) automatically creates a global trigger which is the gg_trig_<triggername>.
That one is referenced when you choose a trigger in the GUI board in the variable option. (All the "<gen>" triggers are those automatically generated global variables.)

So in short... Just use that ugly gg_trg_<triggername> variable.
(and you might want to remove the disable part)
 
Level 8
Joined
May 9, 2010
Messages
266
The problem is that it is local.
A local variable (in this case a trigger) cannot be accessed from outside that function.
You will have to make a global variable of type trigger and use that one instead of the local.
Every trigger (the thing at the left of the screen) automatically creates a global trigger which is the gg_trig_<triggername>.
That one is referenced when you choose a trigger in the GUI board in the variable option. (All the "<gen>" triggers are those automatically generated global variables.)

So in short... Just use that ugly gg_trg_<triggername> variable.
(and you might want to remove the disable part)

I think that I got you.
ofc + rep
 
Level 8
Joined
May 9, 2010
Messages
266
The reason it is called a local variable is because it has a meaning. Like wise a global variable also has a meaning.

If you are doing anything programming related I strongly recommend learning about them early on. You will encounter/use them so often it is worth it.

i know something about it, yeah.
Just didnt know enought about local/global triggers.
Anyway this is gonna be good expirience for me
 
Status
Not open for further replies.
Top