- Joined
- Sep 25, 2005
- Messages
- 71
In an effort to make my stuff a lot more readable and organized, I've started adventuring into the realm of scopes. However, I'm having some issues, primarily in the fact that I have no idea how to pass data (a struct in this case) to a periodic timer without using outside globals:
I need to be able to have multiple instances of the structs passed to the timer. I have no idea how to go forward, keeping it all bundle in a scope, and don't intend to use anything like another system (trying to learn.) I clearly can't define an array of a struct type from within the same scope, at least if its defined before the struct, which allows it to reference the global.
I was told I could use a hashtable, but my google fu is too weak to find a single comprehensive non-GUI, jass guide to hashtables. I also heard that having over 8120~ instances of a struct in an array prevents further, and although it's not in my agenda to create that many instances of the spell, I'd like to know if there's a way to circumvent this hard limit using other methods than just creating an array of structs, and iterating through the array for the number of instances of a spell to keep it multi-use.
Either way, if someone has a solution, or a lesson, I'm open to hearing it. Until then, I'm sort of stunted.
JASS:
// Blizzard Counter -
// Responds to an enemy attack with a cast of Blizzard
// with a cooldown of five seconds
scope BlizzardCounter
globals
private constant integer ABIL_ID = 'A00D'
private constant real COUNTER_CD = 5.00
endglobals
globals
private BlizzardData array blizzarray // Gives an undefined type error
private integer instances
endglobals
private struct BlizzardData
unit attacked
unit attacker
timer cdtimer
integer level
real cooldown
real x
real y
private static method BlizzCast takes nothing returns nothing
// Empty for now
endmethod
private method Blizzard takes nothing returns nothing
local thistype localblizzard = thistype.allocate()
set .attacked = GetTriggerUnit()
set .attacker = GetAttacker()
set .cdtimer = CreateTimer()
set .level = GetUnitAbilityLevel(GetTriggerUnit(), ABIL_ID)
set .cooldown = COUNTER_CD
set .x = GetUnitX(.attacker)
set .y = GetUnitY(.attacker)
set blizzarray[instances] = localblizzard
call TimerStart(.cdtimer, .5, true, function thistype.BlizzCast)
endmethod
private static method Check takes nothing returns boolean
if IsUnitAlly(GetAttacker(), GetOwningPlayer(GetTriggerUnit())) == false /*
*/and GetUnitAbilityLevel(GetTriggerUnit(), ABIL_ID) >= 1 /*
*/and ValidGroundTarget(GetAttacker(), GetTriggerUnit()) == true /*
*/then
return true
endif
return false
endmethod
private static method DefaultTrue takes nothing returns boolean
return true
endmethod
private method Init takes nothing returns nothing
local trigger t = CreateTrigger()
local integer i = 0
loop
exitwhen i > 15
call TriggerAddCondition(t, Filter(function thistype.Check))
call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_ATTACKED, Filter(function thistype.DefaultTrue) )
set i = i + 1
endloop
endmethod
endstruct
endscope
I need to be able to have multiple instances of the structs passed to the timer. I have no idea how to go forward, keeping it all bundle in a scope, and don't intend to use anything like another system (trying to learn.) I clearly can't define an array of a struct type from within the same scope, at least if its defined before the struct, which allows it to reference the global.
I was told I could use a hashtable, but my google fu is too weak to find a single comprehensive non-GUI, jass guide to hashtables. I also heard that having over 8120~ instances of a struct in an array prevents further, and although it's not in my agenda to create that many instances of the spell, I'd like to know if there's a way to circumvent this hard limit using other methods than just creating an array of structs, and iterating through the array for the number of instances of a spell to keep it multi-use.
Either way, if someone has a solution, or a lesson, I'm open to hearing it. Until then, I'm sort of stunted.
Last edited: