• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] JASS Slide Script

Status
Not open for further replies.
Level 3
Joined
Feb 17, 2008
Messages
41
I'm having an issue with my JASS Slide script, because I want it to select a certain type of unit and slide all of them. When I use this one, it slides but then I guess of memory leaks or something it makes the map unplayable and soon locks up without a crash message and I have to kill the process.

JASS:
function slide takes nothing returns nothing
    local group g = GetUnitsOfTypeIdAll('h001')
    local unit u = FirstOfGroup(g)
    local location l
    call BJDebugMsg(GetUnitName(u))
        loop
            exitwhen g == null
            set l = PolarProjectionBJ(GetUnitLoc(u), 20.00, 270.00)
            call SetUnitPositionLoc( u, l )
            call GroupRemoveUnit(g, u)
            set u = FirstOfGroup(g)
        endloop
    call DestroyGroup(g)
    set u = null
endfunction

Any ideas?
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
Fixes below (the actual problem was that you should've exitwhen u == null):

JASS:
globals
    group enumGrp = CreateGroup()
    //you should use a global group for speed and such
endglobals

function SlideFilter takes nothing returns boolean
    return GetWidgetLife(GetFilterUnit()) > 0
    //I assume you don't want to slide the dead
endfunction

function Slide takes nothing returns nothing
    local unit u
    call GroupEnumUnitsOfType(enumGrp,"custom_h001",Filter(function SlideFilter))
    loop
        set u = FirstOfGroup(enumGrp)
        exitwhen u == null
        call SetUnitX(u,GetUnitX(u)+20*Cos(GetUnitFacing(u)*bj_DEGTORAD))
        call SetUnitY(u,GetUnitY(u)+20*Sin(GetUnitFacing(u)*bj_DEGTORAD))
        //I assume you wanted it by facing. You can always change it back.
        call GroupRemoveUnit(enumGrp,u)
    endloop
endfunction
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
Well firstly it leaks 2 locations per unit, which is bad. Switch to X/Y with trigonometry to improve speed and remove all leaks.

Secondly we would need to see the function activator (what runs the function) inorder to tell what is truely causing the lag.

Yes poot was right about the exitwhen, that is causing the problem as it hits the opp limate with leaks all the way. With poot's fixes it should not lag at all. Infact he should have fixed all problems and optimized it as well.

The only further optimization I can think of is in the actual unit filter putting the move script as people like Captian Griffin and hindyhat say that that is faster than a looping through all units in a group in a function.
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
In that case,

JASS:
globals
    group enumGrp = CreateGroup()
    //you should use a global group for speed and such
endglobals

function SlideFilter takes nothing returns boolean
    return GetWidgetLife(GetFilterUnit()) > 0
    //I assume you don't want to slide the dead
endfunction

function Slide takes nothing returns nothing
    local unit u
    call GroupEnumUnitsOfType(enumGrp,"custom_h001",Filter(function SlideFilter))
    loop
        set u = FirstOfGroup(enumGrp)
        exitwhen u == null
        call SetUnitY(u,GetUnitY(u)-20)
        call GroupRemoveUnit(enumGrp,u)
    endloop
endfunction
 
Status
Not open for further replies.
Top