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

[JASS] Why is it not working?

Status
Not open for further replies.
Level 2
Joined
Feb 6, 2011
Messages
19
JASS:
function Cond takes nothing returns boolean
    return GetSpellAbilityId() == 'A000'
endfunction

function Mass_Sleep takes nothing returns nothing
    local group g
    local unit u
    local unit cast
    local unit dumb
    local location p
    set cast = GetTriggerUnit()
    set p = GetSpellTargetLoc()
    set g = GetUnitsInRangeOfLocAll(800.00, p)
    loop
        set u = FirstOfGroup(g)
        exitwhen u==null
        if  IsUnitEnemy(u, GetOwningPlayer(cast))==true then
        call GroupRemoveUnit(g,u)
        set dumb = CreateUnitAtLoc(GetOwningPlayer(cast), 'h000', GetUnitLoc(u), 0.00)
        call IssueTargetOrderBJ(dumb, "sleep", u)
        call UnitApplyTimedLifeBJ (1.50, 'BTLF', dumb)
        set dumb = null
        endif
    endloop 
    set g = null
    set u = null
    set cast = null
    set p = null
endfunction

function InitTrig_masssleep takes nothing returns nothing
    local trigger t
    set t=CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(t, Condition(function Cond))
    call TriggerAddAction(t, function Mass_Sleep)
endfunction

This is included in one tutorial about Jass
y is it not working?
I made like author says
A000 is a silence with 0.1 duration
h000 is a dummy with locust, invul, sleep
A001 is a sleep
and named trigger masssleep
this tutorial was written 6 years ago so something wrong?
 
Level 6
Joined
Oct 10, 2009
Messages
1,425
Hmmm...
2 things.

I'm pretty sure the problem is local group g. It should be local group g = CreateGroup().

Also, you can reduce a line here:
JASS:
local trigger t
    set t=CreateTrigger()
You can just make it:
JASS:
local trigger t = CreateTrigger()

If that doesn't work then it never hurts to DOUBLE check your rawcodes. They can be quite tricky.
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
"call GroupRemoveUnit(g,u)" should be OUTSIDE the if/then/else.
You've got yourself an infinite loop here.
(It always picks the same unit, yet never removes it, that's why it doesn't do anything).

I did a really quick fix so I hope I didn't mess up anything:
JASS:
function Cond takes nothing returns boolean
    return GetSpellAbilityId() == 'A000'
endfunction

function Mass_Sleep takes nothing returns nothing
    local group g = CreateGroup()
    local unit u
    local unit cast = GetTriggerUnit()
    local unit dumb
    local real x = GetSpellTargetX()
    local real y = GetSpellTargetY()

    call GroupEnumUnitsInRange(g, x, y, 800., null)

    loop
        set u = FirstOfGroup(g)
        exitwhen u==null

        if  IsUnitEnemy(u, GetOwningPlayer(cast))==true then
            set dumb = CreateUnitAtLoc(GetOwningPlayer(cast), 'h000', GetUnitLoc(u), 0.00)
            call IssueTargetOrder(dumb, "sleep", u)
            call UnitApplyTimedLife(dumb, 'BTLF', 1.5)
        endif

        call GroupRemoveUnit(g,u)
    endloop 

    set dumb = null
    set g = null
    set u = null
    set cast = null
endfunction

function InitTrig_masssleep takes nothing returns nothing
    local trigger t = CreateTrigger()

    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(t, Condition(function Cond))
    call TriggerAddAction(t, function Mass_Sleep)
endfunction
  • Removed most BJ's
  • Improved visuals.
  • Improved efficiency by setting variables to null only when you have to (at the end).
  • Improved efficiency by using coordinates instead of location
  • Improved efficiency by setting variables when initialized.
  • Fixed the infinite loop
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,206
Such breakdown group loops are slower than enums apparently. Conveniet yes, but do not forget old enums. The reason is some of the group opperations can have O(n) efficncy thus the solution ends up with a O(n^2) effency while enums are always O(n) (each itteration is O(1)). There is probably a cut off though.

Additionally, you could recycle the same group again and again instead of creating, using and destroying it saving some time.
 
Status
Not open for further replies.
Top