- Joined
- Aug 27, 2011
- Messages
- 41
I wrote a small system to handle my spells to avoid having to save things to a hashtable, however the system won't compile if I add a static Create() method. It's giving the Error: "Syntax Error" in create "array s__SpellObj_SpellObjs"
Here is the code any clue to why it won't compile would help greatly
Here is the code any clue to why it won't compile would help greatly
JASS:
//--------------------------------------------------------------------------
//
// SpellObjs
//
// Made by: Fox536
// Date: 09/24/2011
// Version: 0.1
//==========================================================================
// This is a system to better hold the info, for MUI Spell, that
// completely removes the need to save any information into a hashtable.
// Useful for channeled abilities, Dots, Hots, and any other spell that
// might need a timer.
//==========================================================================
// Features
// - Recycling
//==========================================================================
// Future Features
// - Integer for Allied targets' healing/dmg
// - Real for Range
// - Integer for amount of ticks, for repeating timers
// -
// - Array for spell Effects for Allied targets Spell Effects
// - Array for spell Effects for Enemy targets Spell Effects
//--------------------------------------------------------------------------
scope Fox
struct SpellObj
//------------------------------------------------------------------
// Static Variables
//------------------------------------------------------------------
static array SpellObjs
//------------------------------------------------------------------
// Private Static Variables
//------------------------------------------------------------------
private static integer TotalSpellObjs = -1
private static array RecycledObjs
private static integer TotalRecSpellObjs = -1
//------------------------------------------------------------------
// Static Functions
//------------------------------------------------------------------
// GetTotal - Gets the total SpellObjs
static method GetTotal takes nothing returns integer
return TotalSpellObjs
endmethod
// GetIndexFromTimerHandle - Loops through the array and checks if
// it has the timer in it. If it finds it, it returns the obj
static method GetIndexFromTimerHandle takes integer handleId returns SpellObj
local integer i = 0
local SpellObj obj
if (TotalSpellObjs >= 0) then
loop
exitwhen i > TotalSpellObjs
if (SpellObjs[i] != null) then
// For access set variable to obj
set obj = SpellObjs[i]
// If HandleIds match
if (handleId == GetHandleId(obj.castTimer)) then
// Remove Leak
set obj = null
// Return Matched SpellObj
return SpellObjs[i]
endif
endif
set i = i + 1
endloop
endif
// No Matched SpellObj
return null
endmethod
//------------------------------------------------------------------
// Private Static Functions
//------------------------------------------------------------------
// CreateNew - Creates a new SpellObj, System Use only
private static method CreateNew takes nothing returns SpellObj
//--------------------------------------------------------------
// Struct Variables
//--------------------------------------------------------------
// Create New Object
local SpellObj newSpellObj = SpellObj.allocate()
// Increase the Total
set TotalSpellObjs = TotalSpellObjs + 1
// Set Index to the Total of the objects
set newSpellObj.index = TotalSpellObjs
// Set recycled to false
set newSpellObj.recycled = false
// Add the new Object to the used Array
set SpellObjs[index] = newSpellObj
//--------------------------------------------------------------
// Object Variables
//--------------------------------------------------------------
set newSpellObj.castTimer = CreateTimer()
set newSpellObj.castTime = 1.0
set newSpellObj.castTimerRepeats = false
set newSpellObj.casterUnit = null
set newSpellObj.targetUnit = null
set newSpellObj.targetX = 0.0
set newSpellObj.targetY = 0.0
set newSpellObj.targetDestructable = null
set newSpellObj.spellTargetType = 0
// Remove Leak
set newSpellObj = null
// Return the new object
return SpellObjs[index]
endmethod
// ResetSpell - Clears the Spell to be reused
private method ResetSpell takes SpellObj obj, integer spellTypeId, real duration, boolean repeating, real damage returns nothing
// Set Everything to default
set obj.casterUnit = null
set obj.targetUnit = null
set obj.targetX = 0.0
set obj.targetY = 0.0
set obj.targetDestructable = null
// Set given Variables
set obj.spellTargetType = spellTypeId
set obj.castTime = duration
set obj.castTimerRepeats = repeating
set obj.damageToWidget = damage
endmethod
//------------------------------------------------------------------
// Struct Variables
//------------------------------------------------------------------
// Struct use only
private integer index // The Index of the spellObj.
private boolean recycled // The Index of the spellObj.
// Struct Variables
timer castTimer // The cast Timer for the spell.
real castTime // The duration of the Timer.
boolean castTimerRepeats // Whether or not the Timer Repeats.
unit casterUnit // The Unit casting the spell.
unit targetUnit // The Unit targeted by the spell, for spellType 1 (Unit targeted Spell).
real targetX // The Real X targeted by the spell, for spellType 2 (Point Targeted Spell).
real targetY // The Real Y targeted by the spell, for spellType 2 (Point Targeted Spell).
destructable targetDestructable // The Destructable targeted by the spell, for spellType 4 (Destructable targeted Spell).
integer spellTargetType // The Target Type of the spell. Example:
// 1 = Unit Targeted Spell
// 2 = Point Targeted Spell
// 3 = No Target (Self-Cast/Self-Location Cast)
// 4 = Targeted Destructable
real damageToWidget // Damage to do to the widget
//------------------------------------------------------------------
// Methods
//------------------------------------------------------------------
// Create - Recycles or Creates a SpellObj and returns it
static method Create takes nothing returns SpellObj
local SpellObj obj
// if recycled has at least 1 non-empty element
if (TotalRecSpellObjs >= 0) then
// Use one of the recycled objects
// Increase Total Objects
set TotalSpellObjs = TotalSpellObjs + 1
// Move recycled obj to used array
set SpellObjs[TotalSpellObjs] = RecycledObjs[TotalRecSpellObjs]
// Remove moved obj from recycled array
set RecycledObjs[TotalRecSpellObjs] = null
// Decrease Recycled Object Total
set TotalRecSpellObjs = TotalRecSpellObjs - 1
// For access set variable to obj
set obj = SpellObjs[TotalSpellObjs]
// Set recycled to false to allow it to be recycled again later
set obj.recycled = false
// Remove leak
set obj = null
// Return the recycled obj
return SpellObjs[TotalSpellObjs]
// Otherwise Create one
else
// Remove Leak
set obj = null
// Create and Return the new obj
return CreateNew()
endif
endmethod
// Clear - Clears the SpellObj removing memory leak
method Clear takes boolean recycle returns nothing
// Pause Timer to avoid possible repeat tick
call PauseTimer(castTimer)
// Nulls Old Data
set casterUnit = null
set targetUnit = null
set targetX = 0.0
set targetY = 0.0
set targetDestructable = null
if (recycle) then
call Recycle()
endif
endmethod
// Recycle - Recycles the SpellObj, for later use
method Recycle takes nothing returns nothing
local SpellObj obj
if (recycled == false) then
// Increase RecycleTotal
set TotalRecSpellObjs = TotalRecSpellObjs + 1
// Put the recycled Object into the recycled array
set RecycledObjs[TotalRecSpellObjs] = SpellObjs[index]
// if array has at least 2 non-empty Elements
if (TotalSpellObjs > 0) then
// Array has at least 1 other obj in it
set SpellObjs[index] = SpellObjs[TotalSpellObjs]
// For access set variable to obj
set obj = SpellObjs[index]
// Set the index to the new Index
set obj.index = index
else
// Other wise array now empty
set SpellObjs[index] = null
endif
set obj = RecycledObjs[TotalRecSpellObjs]
// Set the index to the new Index position
set obj.index = index
// Set the Recycled to true
set recycled = true
// Remove Leak
set obj = null
endif
endmethod
// SetupUnitTarget - Sets the timer to be used for Spell Targeting Unit
method SetupUnitTarget takes real duration, boolean repeating, code func, unit caster, unit target, real damage returns boolean
if (recycled == false) then
// Clear Old Data
call ResetSpell(this, 1, duration, repeating, damage)
// Set Variables
set casterUnit = caster
set targetUnit = target
// Start Timer
TimerStart(castTimer, castTime, castTimerRepeats, function func)
endif
endmethod
// SetupCoorTarget - Sets the timer to be used for Spell Targeting Coors
method SetupCoorTarget takes real duration, boolean repeating, code func, unit caster, real x, real y, real damage returns nothing
if (recycled == false) then
// Clear Old Data
call ResetSpell(this, 2, duration, repeating, damage)
// Set Variables
set casterUnit = caster
set targetX = x
set targetY = y
// Start Timer
TimerStart(castTimer, castTime, castTimerRepeats, function func)
endif
endmethod
// SetupSelfTarget - Sets the timer to be used for Spell Targeting Self
method SetupSelfTarget takes real duration, boolean repeating, code func, unit caster, real damage returns nothing
if (recycled == false) then
// Clear Old Data
call Reset(this, 3, duration, repeating, damage)
// Set Variables
set casterUnit = caster
// Start Timer
TimerStart(castTimer, castTime, castTimerRepeats, function func)
endif
endmethod
// SetupDestructableTarget - Sets the timer to be used for Spell Targeting Destructable
method SetupDestructableTarget takes real duration, boolean repeating, code func, unit caster, real damage returns nothing
if (recycled == false) then
// Clear Old Data
call ResetSpell(this, 4, duration, repeating, damage)
// Set Variables
set casterUnit = caster
// Start Timer
TimerStart(castTimer, castTime, castTimerRepeats, function func)
endif
endmethod
// GetIndex - Gets the index of the timer in the SpellObjs Array
method GetIndex takes nothing returns integer
return index
endmethod
// DamageTarget - Damages the Target
method DamageTarget takes nothing returns nothing
if ((spellTargetType != 0) or (spellTargetType != 2)) then
UnitDamageTarget(casterUnit, targetUnit, damageToWidget, false, false, null, null, null)
endif
endmethod
endstruct
endscope