Can this be improved?

xoxdragonxox

New Member
Reaction score
1
I've recently just fixed this trigger because of fatal crashes, Now im asking if it can be improved, ive improved it as much as i can to my knowledge .. btw i SUCK at jass so im not sure if this is good. all i really did was copy n paste things that looked like common sense. if anyone could kindly improve it it'd be great.

i mainly wan tit improved for efficiency and make sure it cant crash or bug

THANK YOU :D

Sorry Lol. I forgot the main part ha :) here it is

JASS:
function RoadFlareConditions takes nothing returns boolean
    return GetSpellAbilityId()=='A022'
endfunction

function RoadFlare takes nothing returns nothing
    local unit marine = GetTriggerUnit()
    local player p = GetOwningPlayer(marine)
    local unit u
    local unit missile 
    local location l = GetSpellTargetLoc()
    local real x = GetLocationX(l)
    local real y = GetLocationY(l)
    local integer i = 1
    call PolledWait(0.1)
    call FieldChat(marine,5.0, udg_Pcolors[GetConvertedPlayerId(p)] + GetPlayerName(p) + "|r : Flare!" )
    set missile = CreateUnit(Player(11),'h00H',GetUnitX(marine),GetUnitY(marine),0.0)
    call UnitApplyTimedLife(missile,'Bhwd',15.0)
    call IssuePointOrderLoc(missile,"attackground",l)
    call PolledWait(2.5)
    set u = CreateUnit(p,'h001',x,y,0.0)
    call UnitApplyTimedLife(u,'Bhwd',40.0)
    call RemoveLocation(l)
    call RemoveUnit(missile)
    set marine = null
    set missile = null
    set l = null
    set u = null
endfunction

//===========================================================================
function InitTrig_Road_Flare takes nothing returns nothing
    set gg_trg_Road_Flare = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(gg_trg_Road_Flare,EVENT_PLAYER_UNIT_SPELL_CAST)
    call TriggerAddCondition( gg_trg_Road_Flare, Condition( function RoadFlareConditions ) )
    call TriggerAddAction(gg_trg_Road_Flare,function RoadFlare)
endfunction
 

tooltiperror

Super Moderator
Reaction score
231
[ljass]GetConvertedPlayerId[/ljass] is a BJ. Use [ljass]GetPlayerId[/ljass] instead.

[ljass]PolledWait[/ljass] is also a BJ.
JASS:
function PolledWait takes real duration returns nothing
    local timer t
    local real  timeRemaining

    if (duration > 0) then
        set t = CreateTimer()
        call TimerStart(t, duration, false, null)
        loop
            set timeRemaining = TimerGetRemaining(t)
            exitwhen timeRemaining <= 0

            // If we have a bit of time left, skip past 10% of the remaining
            // duration instead of checking every interval, to minimize the
            // polling on long waits.
            if (timeRemaining > bj_POLLED_WAIT_SKIP_THRESHOLD) then
                call TriggerSleepAction(0.1 * timeRemaining)
            else
                call TriggerSleepAction(bj_POLLED_WAIT_INTERVAL)
            endif
        endloop
        call DestroyTimer(t)
    endif
endfunction


Also, one letter variables look cleaner.
 

xoxdragonxox

New Member
Reaction score
1
How do i use

JASS:
function PolledWait takes real duration returns nothing
    local timer t
    local real  timeRemaining

    if (duration > 0) then
        set t = CreateTimer()
        call TimerStart(t, duration, false, null)
        loop
            set timeRemaining = TimerGetRemaining(t)
            exitwhen timeRemaining <= 0

            // If we have a bit of time left, skip past 10% of the remaining
            // duration instead of checking every interval, to minimize the
            // polling on long waits.
            if (timeRemaining > bj_POLLED_WAIT_SKIP_THRESHOLD) then
                call TriggerSleepAction(0.1 * timeRemaining)
            else
                call TriggerSleepAction(bj_POLLED_WAIT_INTERVAL)
            endif
        endloop
        call DestroyTimer(t)
    endif
endfunction


do i enter that into my map header, then will that just fix or clean all the PolledWaits i have in all of my triggers?
 

tooltiperror

Super Moderator
Reaction score
231
Think of it sort of like this.

You have this.

JASS:

 function initialization takes nothing returns nothing
     call PolledWait(2.23)
 endfunction


Now, think of it like this. WC3 turns the above code into this, kind of.

JASS:

 function initialization takes nothing returns nothing
    local real duration = 2.23 // Remember, you called with 2.23.
    local timer t
    local real  timeRemaining

    if (duration > 0) then
        set t = CreateTimer()
        call TimerStart(t, duration, false, null)
        loop
            set timeRemaining = TimerGetRemaining(t)
            exitwhen timeRemaining <= 0
            if (timeRemaining > bj_POLLED_WAIT_SKIP_THRESHOLD) then
                call TriggerSleepAction(0.1 * timeRemaining)
            else
                call TriggerSleepAction(bj_POLLED_WAIT_INTERVAL)
            endif
        endloop
        call DestroyTimer(t)
    endif


See, think of it like it replaces it, like I showed you. In reality, when you use [ljass]PolledWait[/ljass] it does the long function with your real.
 

tooltiperror

Super Moderator
Reaction score
231
Don't double post.

For PolledWait, just use timers.

And that is just about the only accepted BJ I know.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top