• 🏆 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!

Need help with Some jass Concepts

Status
Not open for further replies.
Level 5
Joined
Mar 6, 2015
Messages
130
hello
I need help with these codes
I won`t use BJs (i know they are slow inefficient etc .. I can convert them to natives) i need help with these concepts :'Code actionfunc ' and 'Boolexpr ' and 'filterEnumDestructablesInCircleBJ'

How can i define code and boolexpr in Custom Script (please don`t advise me to use vjass i just want to know what are these and how i can use them in custom scripts )

What is the second and third arguments?
JASS:
function EnumDestructablesInCircleBJ takes real radius, location loc, code actionFunc returns nothing

What is the second argument?
JASS:
ForGroupBJ takes group whichGroup, code callback returns nothing

Thanks in advance
 

EdgeOfChaos

E

EdgeOfChaos

Code is a function. As in, if it asks for "code", you should pass in "function zxy"
Boolexpr is a boolean expression - code that returns a boolean. This is passed in with the Filter keyword, for unit groups (as in Filter(function myFunction))

Example for ForGroup
JASS:
call ForGroup(myUnits,function doAction)
This would call the doAction function for every unit in myUnits.

Using these in custom script is quite difficult, as you don't specifically define filter functions and enumerator functions in GUI. Why do you need these to be custom script?
 
Level 13
Joined
Jan 2, 2016
Messages
973
Take my Destructables library for example
JASS:
library Destructables

    globals
        private real X = 0
        private real Y = 0
        private rect R = Rect(-1,-1,1,1)
        private real radi = 0
    endglobals
    
    function IsDestructableInCircle takes nothing returns boolean
        local real x = GetDestructableX(GetFilterDestructable()) - X
        local real y = GetDestructableY(GetFilterDestructable()) - Y
        return x*x+y*y <= radi
    endfunction

    function IsDestructableTree takes integer i returns boolean
        return (i == 'ZTtw' or i == 'ATtr' or i == 'ATtc' or i == 'BTtw' or i == 'BTtc' or i == 'KTtw' or i == 'YTft' or i == 'YTst' or i == 'YTct' or i == 'YTwt' or i == 'JTct' or i == 'JTtw' or i == 'DTsh' or i == 'CTtr' or i == 'CTtc' or i == 'ITtw' or i == 'ITtc' or i == 'NTtc' or i == 'FTtw' or i == 'LTlt' or i == 'WTst' or i == 'WTtw' or i == 'NTtw' or i == 'OTtw' or i == 'ZTtw' or i == 'ZTtc' or i == 'GTsh' or i == 'VTlt')
    endfunction

    function KillTrees takes nothing returns nothing
        local integer id = GetDestructableTypeId(GetEnumDestructable())
        if IsDestructableTree(id) then
            call KillDestructable(GetEnumDestructable())
        endif
    endfunction
    
    function EnumDestructablesInCircle takes real x, real y, real radius, code actionFunc returns nothing
        call SetRect(R,x-radius,y-radius,x+radius,y+radius)
        set X = x
        set Y = y
        set radi = radius*radius
        call EnumDestructablesInRect( R , Filter(function IsDestructableInCircle), actionFunc )
    endfunction

endlibrary
When I do this:
JASS:
function Regrow_Trees takes nothing returns nothing
    local destructable dest = GetEnumDestructable()
    if IsDestructableTree(GetDestructableTypeId(dest)) then
        call DestructableRestoreLife( dest, GetDestructableMaxLife(dest), false )
    endif
endfunction

function Grow_Trees takes nothing returns boolean
    local real x
    local real y
    local group g
    local unit FoG
    if GetSpellAbilityId() == 'A01D' then
        set x = GetSpellTargetX()
        set y = GetSpellTargetY()
        set g = CreateGroup()
        call EnumDestructablesInCircle( x , y, 200.00, function Regrow_Trees )
        call GroupEnumUnitsInRange(g, x, y, 200, null)
        loop
            set FoG = FirstOfGroup(g)
            exitwhen FoG == null
            set x = GetUnitX(FoG)
            set y = GetUnitY(FoG)
            if IsUnitType(FoG, UNIT_TYPE_STRUCTURE) then
                call EnumDestructablesInCircle( x , y , 135.00 , function KillTrees )
            elseif not IsUnitType(FoG, UNIT_TYPE_FLYING) then
                call EnumDestructablesInCircle( x , y , 90.00 , function KillTrees )
            endif
            call GroupRemoveUnit(g,FoG)
        endloop
        call DestroyGroup(g)
        set g = null
    endif
    return false
endfunction

//===========================================================================
function InitTrig_Grow_Trees takes nothing returns nothing
    set gg_trg_Grow_Trees = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Grow_Trees, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Grow_Trees, Condition( function Grow_Trees ) )
endfunction
The actionFunc in the 1-st part will be Regrow_Trees, and in the 2-nd part, it will be KillTrees, which is in the library, so I don't need to re-write it in the trigger.
 
Level 5
Joined
Mar 6, 2015
Messages
130
thanks for reply the thing i`v found out after inspecting your code is that you can specify a Function like killTree in your code or a specific call function right?
the question is how to define a Function inside a GUI Spell and use it as a Function ?
My purpose is to rewrite this GUI Action
  • Destructible - Pick every destructible in (Playable map area) and do (Actions)
    • Loop - Actions
i want to do Loop - Actions
is that possible?
 

EdgeOfChaos

E

EdgeOfChaos

I would recommend that if you want to create functions, put them in a new trigger. Make a new trigger, convert to custom text, delete everything, and write the following.
JASS:
library CustomFunctions

    function killTree takes nothing returns nothing
    
    endfunction
    
endlibrary
Then write your function. You can freely call it from anywhere in the map.

There are ways to create functions in GUI triggers, but they are dumb syntax abuse. There's no need to do it.

(edit)
or if you really want the gui way
  • killTree
    • Events
    • Conditions
    • Actions
      • Custom script: endfunction
      • Custom script: function killTree takes nothing returns nothing
 
Status
Not open for further replies.
Top