GUI Converted to JASS

skyblader

You're living only because it's illegal killing.
Reaction score
159
I believe JASS-ers code stuff more efficiently than just any GUI converted to JASS code. Just wondering how to code efficiently, for example I'm trying to learn how to make this spell in JASS, which I made in GUI. And I convert it to custom text, but it's not efficient right? How do I make it that way?

JASS:
function Trig_Untitled_Trigger_001_Actions takes nothing returns nothing
    call CreateNUnitsAtLoc( 1, 'hfoo', Player(0), GetSpellTargetLoc(), bj_UNIT_FACING )
    call SetUnitInvulnerable( GetTriggerUnit(), true )
endfunction

//===========================================================================
function InitTrig_Untitled_Trigger_001 takes nothing returns nothing
    set gg_trg_Untitled_Trigger_001 = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Untitled_Trigger_001, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddAction( gg_trg_Untitled_Trigger_001, function Trig_Untitled_Trigger_001_Actions )
endfunction


Just an example of a GUI converted to JASS code. How can it be made more efficient?
 

luorax

Invasion in Duskwood
Reaction score
67
1, Don't use locations. Use reals instead. Each native has a "location" and a "real" version.
2, Use the condition as the function.
3, Try to replace the BJs with their native version.

JASS:
function Act takes nothing returns boolean
    call CreateUnit(Player(0), 'hfoo', GetSpellTargetX(), GetSpellTargetY(), 270.)
    call SetUnitInvulnerable( GetTriggerUnit(), true )
    return false
endfunction

//===========================================================================
function InitTrig_Untitled_Trigger_001 takes nothing returns nothing
    local trigger t = CreateTrigger()
    local integer i = 0
    loop
        exitwhen i > 11//To optimize it, use the maximum players' number here.
        call TriggerRegisterPlayerUnitEvent( t, Player(i), EVENT_PLAYER_UNIT_SPELL_EFFECT, null ) //We don't need the boolexpr anymore. Thanks to Romek.
        set i = i + 1
    endloop
    call TriggerAddCondition( t, Condition(function Act) )
endfunction
 

Romek

Super Moderator
Reaction score
963
I cover how to remove BJ's in my JASS Tutorial.

As for coding more efficiently, you'll be better off coding from scratch rather than converting from GUI. You should only ever do that to find out what the JASS equivalent of an action is, and then convert that to its native form. Never do it for anything else, as GUI seems to do everything in an inefficient manner by default. :p

If you don't already have the JASS Newgen Pack, I'd strongly recommend getting it. There's a thread for it (which includes a download link) in the main WEHZ Forum. Not only will it allow you to declare globals without the variable editor (probably the best part of it), but you'll also be able to use scopes (and therefore initializers as starting places for code), and encapsulation. There's also syntax highlighting for vJASS, as well as a function list. Most JASS natives have fairly descriptive function names, so you'll easily be able to find them.

@ luorax:
You can safely pass 'null' as a boolexpr in TriggerRegister... functions without it leaking.
 

Darthfett

Aerospace/Cybersecurity Software Engineer
Reaction score
615
@ luorax:
You can safely pass 'null' as a boolexpr in TriggerRegister... functions without it leaking.

And, since one of the most recent patches, you can also pass it in group filters without a leak.

Everything else seems to be covered. Even if you don't want to use vJASS, I would still highly recommend Newgen for the function list. It's invaluable.
 

luorax

Invasion in Duskwood
Reaction score
67
My map(s) contain(s) a simple library (BoolexprUtils), so it doesn't really for me. I read somewhere that they leak, that's why rewrote the code using it.
 

tooltiperror

Super Moderator
Reaction score
231
Optimizing the BJ for events is completely unnecessary. Use a trigger array or an automated one (GTrigger) or just use the BJ.
 
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