HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Strange Loop Issue(Spells)

02-26-2006, 07:17 PM#1
Meanie
For the first time now i created a spell that uses caster systems functions, using attachable variables and special events but it must not be the problem

here is the script
Collapse JASS:
function ShiverArmor_Actions takes nothing returns nothing
  local unit A = GetTriggerUnit()
  local unit D = GetAttachedUnit(gg_trg_ShiverArmor,"S")
  local player S = GetOwningPlayer(A)

    call DisplayTextToForce( GetPlayersAll(), UnitId2StringBJ(GetUnitTypeId(D)) )
    call CasterCastAbility( S, ShiverArmor_DummySpellId(), ShiverArmor_Orderid(), A, true)

endfunction

function ShiverArmor_Effects takes nothing returns nothing
  local real A = GetRandomReal(-100.00, 100.00)
  local real S = GetRandomReal(-100.00, 100.00)
  local unit G = GetAttachedUnit(gg_trg_ShiverArmor,"S")
  local location D = OffsetLocation(GetUnitLoc(G), A, S)
  local player F = GetOwningPlayer(G)
  local location H = GetUnitLoc(G)

    if UnitHasBuffBJ(GetTriggerUnit(), 'B000') == true then
        call ProjectileLaunchExLoc( F, "Abilities\\Weapons\\ZigguratFrostMissile\\ZigguratFrostMissile.mdl", 1.5, 255, 255, 255, 255, 522, 0.15, H, 0, D, 200 )
    endif

    call RemoveLocation(D)
    call RemoveLocation(H)

  set A = 0
  set S = 0
  set G = null
  set D = null
  set F = null
  set H = null
endfunction

function ShiverArmor_Retaliation takes nothing returns nothing
endfunction

function ShiverArmor_Setup takes nothing returns nothing
  local trigger A = CreateTrigger(  )
  local unit S = GetTriggerUnit()

    call CleanAttachedVars(A)
    call AttachObject( gg_trg_ShiverArmor,"S",S)

    call TriggerRegisterUnitEvent(A,S,EVENT_UNIT_SPELL_EFFECT)
    call TriggerAddAction( A, function ShiverArmor_Actions )

    if ShiverArmor_Effect() == true then
       call TriggerRegisterTimerEventPeriodic( A, ShiverArmor_EffectTimer() )
       call TriggerRegisterTimerEvent(A,0,false)
       call TriggerAddAction( A, function ShiverArmor_Effect )
    else
    endif

    call TriggerRegisterUnitEvent( A, S, EVENT_UNIT_ATTACKED )
    call TriggerAddAction( A, function ShiverArmor_Retaliation )

  set S = null              //Nullify the unit var so it wont leak (Unit vars do not leak anyway:P)
endfunction

function InitTrig_ShiverArmor takes nothing returns nothing
    call OnAbilityEffect(ShiverArmor_SpellId(),"ShiverArmor_Setup")
endfunction

it is faaaaaaar from finished and i have some unused calls which i only use for fixing this annoying problem

Here is the problem: "Nothing Happens first time i cast the ability and then i added a function call DisplayTextToForce to test the attachment but second time i cast the ability i see the effects and everything is working but it is looping so whit each time i cast it it loops one more time, like second time = 2 loops fifth time = 5 loops, how do i fix this?"
02-27-2006, 03:08 AM#2
Vexorian
how is the ShiverArmor_Effect() function like?

OnAbilityEffect makes it trigger on the spell effect event btw.
02-27-2006, 05:02 AM#3
Meanie
Collapse JASS:
function ShiverArmor_Effect takes nothing returns boolean
   return true
endfunction

function ShiverArmor_EffectTimer takes nothing returns real
   return GetRandomReal(1.25, 4.00)
endfunction

Hmm it is a weird code yea, but the effects will show all the time like the real Shiver Armor in diablo where small pieces pops out of the sorc all the time.

Hmm made some slight modifications and it stops looping, but that Periodic event seems triggering all the functions and that confuse me because when i look at your triggers that use multiple events i have done exactly the same(I looked at the Inferno ability)
02-27-2006, 05:56 PM#4
Vexorian
hmnn the code is not weird, it is completelly senseless

Collapse JASS:
function ShiverArmor_Setup takes nothing returns nothing
  local trigger A = CreateTrigger(  )
  local unit S = GetTriggerUnit()

    call CleanAttachedVars(A)
    //You are cleaning variables for a trigger that was just created, why?
    
    call AttachObject( gg_trg_ShiverArmor,"S",S)
    //gg_trg_ShiverArmor is NEVER initialized cause you are just using OnAbilityEffect
    //gg_trg_ShiverArmor is surelly pointing to null
    //Even if that was initialized correctly it would be senseless to attach the Triggering unit to
    //it, because it is a global and that would make the attached var "S" a global too and break
    //any hope of multi instancibility which is the point of Attacheable Variables

    call TriggerRegisterUnitEvent(A,S,EVENT_UNIT_SPELL_EFFECT)
    call TriggerAddAction( A, function ShiverArmor_Actions )
    // More senseless stuff, you are registering the EVENT_UNIT_SPELL_EFFECT event FOR TRIGGERING UNIT
    // So every time current Triggering unit starts a effect of an ability the ShiberArmor_Actions will
    // Execute, that's a problem cause probably the current execution - which was called by a 'Starts
    // the effect of an ability event too - will also trigger the new trigger.
    
    // And you use the attached variable "S" to the global gg_trg_ShiverArmor in that other trigger
    // Did you note that most likelly in ShiverArmor_Actions both unit D and A will actually be
    // the same unit? Cause that trigger will only run when current triggering unit starts the effect
    // of an ability, so in that trigger GetTriggerUnit() will always be the GetTriggerUnit() of this
    // trigger which you are also setting for gg_trg_ShiverArmor,"S"

    
    if ShiverArmor_Effect() == true then
       call TriggerRegisterTimerEventPeriodic( A, ShiverArmor_EffectTimer() )
       call TriggerRegisterTimerEvent(A,0,false)
       call TriggerAddAction( A, function ShiverArmor_Effect )
       // This is the major Senseless ever cause ShiverArmor_Effect is just a function that returns true,
       // whatever makes you think it is a good idea to make the trigger A call it.
       
       // You also override previous call TriggerAddAction( A, function ShiverArmor_Actions )
       
    else
    endif

    call TriggerRegisterUnitEvent( A, S, EVENT_UNIT_ATTACKED )
    // Whenever current Triggering unit is attacked execute that trigger, so the trigger will work when
    // you attack that unit or when that unit starts the effect of an ability?
    
    call TriggerAddAction( A, function ShiverArmor_Retaliation )
    // Now you are giving that trigger an Action that does nothing , congratulations the trigger will not
    // do anything

  set S = null              //Nullify the unit var so it wont leak (Unit vars do not leak anyway:P)
endfunction

function InitTrig_ShiverArmor takes nothing returns nothing
    call OnAbilityEffect(ShiverArmor_SpellId(),"ShiverArmor_Setup")
endfunction

I don't really understand what exactly you want that trigger to do
02-27-2006, 06:02 PM#5
Vexorian
I am sorry, I assumed TriggerAddAction overrided actions but it doesn't. Still it doesn't have any sense to make a trigger have ShiverArmor_Retaliation or function ShiverArmor_Effect as actions cause they don't do anything.

And well after reading all the events you register to that trigger, it will be executed:

- Every time triggering unit starts the effect of an ability (even if it is ShiverArmor_SpellId() )
- Every time triggering unit is attacked
- Every ShiverArmor_EffectTimer() cycles
- Immediatelly after the setup action is called
02-28-2006, 05:50 AM#6
Meanie
Yeye i only made this spell for testing attachable var's and when i got to that loop problem i didnt want to finish it, as for the retaliation. And i know that i only could use GetTriggerUnit() instead of that attached var but that attached var was only temporary anyway so retaliation and effects will do something later on.
03-03-2006, 06:31 PM#7
Meanie
Ok i have putted that spell behind me now but i still want to learn how to use multiple events(Point em to diffrent functions) in a trigger so i dont have to use several triggers each time

didnt want to make a néw thread if i could get my answer right here...
03-09-2006, 06:12 PM#8
Vexorian
you can always use many triggers instead , but if you add multiple events to a trigger then you will have to check the GetTriggerEventId() and call different functions depending on the event id
03-17-2006, 04:39 PM#9
Meanie
Thanks alot Vexorian in the past week i have finally learned how to use all of your systems and functions