HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

loop never starting, rest of code never finishing... What's wrong?

10-20-2006, 01:48 AM#1
darkwulfv
Ok, I have laced this code with a thousand Debug messages. The messages stop appearing right before the loop, and nothing happens from there. Now, I'm aware that this could probably be done in a much better way, but I just want to know where the hell I went wrong here. I'll work on optimizing it later. (That means sending it to Tide, who is helping me with such matters.)
Collapse JASS:
function Conditions_Athenas_Rage takes nothing returns boolean
    return ( GetSpellAbilityId() == 'A00B' )
endfunction

//Comments are markers to help organization.
//They are nothing more than that.

function Athena takes nothing returns nothing
  local unit u = GetTriggerUnit()
  local location l = GetUnitLoc(u)
  local real x = GetUnitX(u) + 100
  local real y = GetUnitY(u) + 100
  local real face = GetUnitFacing(u)
  local integer level = GetUnitAbilityLevel(u, 'A00B')
  //End Unit Variables
  //Start Group Variables
  local rect r = RectFromCenterSizeBJ(l, 400+(level*200), 400+(level*200))   
  local group g = GetUnitsInRectMatching(r, null)
  local integer i = CountUnitsInGroup(g)
  local unit f = FirstOfGroup(g)
  local boolean b = IsUnitEnemy(f, GetOwningPlayer(u))
  //End Group Variables
  //Start Other Variables
  local effect SFX
  local integer count
  //End Variables
    call BJDebugMsg("variables")
set udg_Athena = CreateUnit(Player(14), 'E001', x, y, face)
    call SetUnitAbilityLevel(udg_Athena, 'A006', level)
    call BJDebugMsg("Level set")
    call BJDebugMsg(I2S(i))
     
    loop
    exitwhen count == i
     if b == true then
     call BJDebugMsg("Succsess! Pt. 2")      
     call IssueTargetOrder( udg_Athena, "chainlightning", f )
     call GroupRemoveUnit(g, f)
set f = FirstOfGroup(g)
set count = count + 1
     else
     call BJDebugMsg("fail")
     call GroupRemoveUnit(g, f)
set f = FirstOfGroup(g)
     endif
    endloop         

  //Start Clean Up
    call BJDebugMsg("Clean up started")
    call PolledWait(3.0)
set SFX = AddSpecialEffect("Abilities\\Spells\\Human\\Resurrect\\ResurrectTarget.mdl", GetUnitX(udg_Athena), GetUnitY(udg_Athena))
    call KillUnit(udg_Athena)
    call PolledWait(3.0)
    call DestroyEffect(SFX)
    call RemoveRect(r)
    call DestroyGroup(g)
    call RemoveLocation(l)
set u = null
set l = null
set r = null
set g = null
set f = null
set SFX = null
    call BJDebugMsg("Clean up complete")
  //End Clean Up 
endfunction

//===========================================================================
function InitTrig_Athenas_Rage takes nothing returns nothing
  local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( t, Condition( function Conditions_Athenas_Rage ) )
    call TriggerAddAction( t, function Athena )
set t = null
endfunction
10-20-2006, 02:03 AM#2
Mythic Fr0st
This may not help at all, as I do not know much of jass

Your trigger
Collapse JASS:
local effect SFX
  local integer count

Collapse JASS:
local effect SFX
  local integer count = 0

(I think, that may help)
10-20-2006, 02:13 AM#3
zen87
Collapse JASS:
    loop
    exitwhen count == i
are you sure this part are ok ? because the loop quit immediately when you are casting the spell on one unit (i=1, and you set count=1 at local variable), it should be
Collapse JASS:
    loop
    exitwhen count > i
10-20-2006, 02:50 AM#4
Vexorian
Mythic Fr0st, is right, count is not initialized, would crash the thread in the count==i condition
10-20-2006, 03:20 AM#5
darkwulfv
Oh, I didn't know you had to set integers to something before they could be used. I always thought that if it wasn't set to anything it would be considered 0. Well I'll try it out and see what happens. Thanks.

Quote:
Collapse JASS:
 loop
    exitwhen count == i
are you sure this part are ok ? because the loop quit immediately when you are casting the spell on one unit (i=1, and you set count=1 at local variable), it should be
JASS:
Collapse JASS:
    loop
    exitwhen count > i

This spell is an area affecting spell, and count will be set to zero when created, then set to 1 after one run of the loop. Thats the way its supposed to be.

EDIT: Ok, good news bad news. Good news is, it runs the loop and finishes the trigger. Bad news is, it ALWAYS fails. Heres the new code, see if you can find whats causing it. (I'm 90% sure its the first unit in group, which would probably be the caster, but i always change it (using set f = FirstOfGroup) after it gets removed...) Thanks again.
Collapse JASS:
function Conditions_Athenas_Rage takes nothing returns boolean
    return ( GetSpellAbilityId() == 'A00B' )
endfunction

//Comments are markers to help organization.
//They are nothing more than that.

function Athena takes nothing returns nothing
  local unit u = GetTriggerUnit()
  local location l = GetUnitLoc(u)
  local real x = GetUnitX(u) + 100
  local real y = GetUnitY(u) + 100
  local real face = GetUnitFacing(u)
  local integer level = GetUnitAbilityLevel(u, 'A00B')
  //End Unit Variables
  //Start Group Variables
  local rect r = RectFromCenterSizeBJ(l, 200+(level*200), 200+(level*200))   
  local group g = GetUnitsInRectMatching(r, null)
  local integer i = CountUnitsInGroup(g)
  local unit f = FirstOfGroup(g)
  local boolean b = IsUnitAlly(f, GetOwningPlayer(u))
  //End Group Variables
  //Start Other Variables
  local effect SFX
  local integer count = 0
  //End Variables
    call BJDebugMsg("variables")
set udg_Athena = CreateUnit(Player(14), 'E001', x, y, face)
    call SetUnitAbilityLevel(udg_Athena, 'A006', level)
    call BJDebugMsg("Level set")
    call BJDebugMsg(I2S(i))
     
    loop
    exitwhen count == i
     if b == false then
     call BJDebugMsg("Succsess! Pt. 2")      
     call IssueTargetOrder( udg_Athena, "chainlightning", f )
     call GroupRemoveUnit(g, f)
set f = FirstOfGroup(g)
set count = count + 1
     else
     call BJDebugMsg("fail")
     call GroupRemoveUnit(g, f)
set f = FirstOfGroup(g)
set count = count + 1
     endif
    endloop         

  //Start Clean Up
    call BJDebugMsg("Clean up started")
    call PolledWait(3.0)
set SFX = AddSpecialEffect("Abilities\\Spells\\Human\\Resurrect\\ResurrectTarget.mdl", GetUnitX(udg_Athena), GetUnitY(udg_Athena))
    call KillUnit(udg_Athena)
    call PolledWait(3.0)
    call DestroyEffect(SFX)
    call RemoveRect(r)
    call DestroyGroup(g)
    call RemoveLocation(l)
set u = null
set l = null
set r = null
set g = null
set f = null
set SFX = null
    call BJDebugMsg("Clean up complete")
  //End Clean Up 
endfunction

//===========================================================================
function InitTrig_Athenas_Rage takes nothing returns nothing
  local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( t, Condition( function Conditions_Athenas_Rage ) )
    call TriggerAddAction( t, function Athena )
set t = null
endfunction
10-20-2006, 08:41 AM#6
blu_da_noob
I feel like c+p'ing my other post. How does it fail? The more information you give, the more likely it is that someone will be able to help you. You provided lots of nice debug information in your first post, and you got an answer quickly.
10-20-2006, 11:37 AM#7
darkwulfv
Oh, by fail I meant it gives me the fail message through my debugs. Every time to be presice, and I',m thinking its from the First Of Group unit, who is probably the caster. But in the loop I have the FirstOfGroup unit (f) rwemoved and it SHOULD be replaced with the next unit. Maybe its not, or maybe its the boolean check I have (b). Sorry, I was kinda speaking to myself when I posted ><.
10-20-2006, 11:42 AM#8
Captain Griffen
You aren't setting b in the loop.
10-20-2006, 07:26 PM#9
darkwulfv
b needs to be made in the loop? Orr what do you mean? b is local variable that is made with a check. Does it need to be set again inside the loop?
10-20-2006, 07:33 PM#10
The)TideHunter(
Quote:
Originally Posted by darkwulfv
b needs to be made in the loop? Orr what do you mean? b is local variable that is made with a check. Does it need to be set again inside the loop?

Yes, when you create a variable, it dosent stand for what its equal, it stands for a value. If you know what i mean.

Take your f for example, its not always equal to FirstOfGroup, its equal to the first of group once.
It dosent get updated automatically.

So set b = IsUnitAlly(f, GetOwningPlayer(u))
And set f = FirstOfGroup(g) on every loop run.

Example:

Collapse JASS:
function Test takes nothing returns nothing
    local group g = RandomWhatever
    local unit u
    loop
        set u = FirstOfGroup(g)
        exitwhen u==null
        call DoSomethingWithUnit(u)
        call GroupRemoveUnit(g, u)
    endloop
    call DestroyGroup(g)
    set g = null
    set u = null
endfunction

That will do something with every unit in group g.
10-20-2006, 08:22 PM#11
darkwulfv
Does it really? I remebered that method beign used in one of my triggers by someone who had helped, but it seemed illogical when I tried to remeber it. Weird. Oh well, I'll go install it and try it out.

Ok, one last issue. Evertying works fine except for one thing. udg_Athena nevers uses chain lightning, regardless of whether b was equal to false or not. I checked just about everything I could, but I have one sneaking suspicion. When using SetUnitAbilityLevel, does the unit whos level is being changed have to have enough extra skill points for it to work?
10-21-2006, 01:10 AM#12
darkwulfv
~*bump*~
Still can't figure out this problem:
Quote:
Ok, one last issue. Evertying works fine except for one thing. udg_Athena nevers uses chain lightning, regardless of whether b was equal to false or not. I checked just about everything I could, but I have one sneaking suspicion. When using SetUnitAbilityLevel, does the unit whos level is being changed have to have enough extra skill points for it to work?
10-21-2006, 10:35 AM#13
Captain Griffen
Does it have enough mana?
Does it have the spell?
Are you using the correct order string?
10-21-2006, 11:58 AM#14
blu_da_noob
Do not bump after such a short time (and especially not on a double post).

Quote:
When using SetUnitAbilityLevel, does the unit whos level is being changed have to have enough extra skill points for it to work?
No.

Check griffs list above, along with checking cast range etc. (On a side note, you're trying to get the Athena unit to cast a spell multiple times at once, without giving it time to cast, so it'll only cast on the last one.)
10-21-2006, 05:03 PM#15
darkwulfv
Sorry about the bump, I was anxious ><. All of Griff's list checks out fine, cast range is 999999, but isn't there a way to reduce the amount of total time it takes to cast? (like backswing or something) I can throw a very short wait in the loop, but thats all I can think of...