• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Structs not Compiling

Status
Not open for further replies.
Level 3
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
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
 
Level 14
Joined
Nov 18, 2007
Messages
1,084
JASS:
static array SpellObjs
private static array RecycledObjs
->
JASS:
static thistype array SpellObjs
private static thistype array RecycledObjs
There are a lot of syntax errors as well; most of them result from you trying to set an integer to null (set it to 0 instead) and other random scripting mistakes like forgetting to put call.
 
Level 3
Joined
Aug 27, 2011
Messages
41
I do alot of programming in C++ and C#, a little java, and some lua lol I get around but the compiler doesn't should the next error unless you fix the first one it makes compile time errors a pain to find lol. But let me change those and see if it helps lol thanks guys :)

--- When I used the thistype it changes it into a integer and won't let me return null values, cause integer can't be null lol.

And ya there are still quite a few errors but most I'll fix easily the error giving me grief are the ones related to the struct lol

Any Ideas getting it to let me null the structs pointer? I'm pretty sure I shouldn't just set it to 0 that doesn't sound right but thats the only way it'll compile
 
Last edited:
Level 3
Joined
Aug 27, 2011
Messages
41
hmmm... then say I want to check if 2 structs are equal, and I loop through a array if I find a match then I was returning it, what if there isn't a match what do I return then? a negative number a just check to make sure that the number returned isn't negative?
 
I do alot of programming in C++ and C#, a little java

That's why it's only natural for you to omit the call :p
I once wrote an application in C++ and ended up rewriting most of the code because I accidentally wrote call before every function call and set before every variable setting xD (I'm really used to Jass) :p
 
Level 3
Joined
Aug 27, 2011
Messages
41
ya, man everytime I goto set a variable, or call a function I omit the set or call and have to rewrite it. Every once in a while I'll type a funciton out like
Code:
 void Fox_xxx(int i, unit target)
after I get the error I just laugh lol.

Well I think I have the system base pretty much done. I even have a test map done and a few spell templates (Channeled Spell, and Dot/Hot). I think I post it see what everyone thinks. It should be pretty useful I think X).
 
Level 3
Joined
Aug 27, 2011
Messages
41
@Adiktuz
You might not I didn't check using "x == y", I used "GetHandleId(x.castTimer) == GetHandleId(GetExpiredTimer())", so idk lol.

Thanks for confirming my tests on it, I was hoping i had it write lol.

As for other systems there might be other systems, but mine holds all the data without the need for a hashtable, and I haven't seen a system yet to be able to do that. Thats the point of this system is to remove the need to save and load things into hashtable. They're limited to 256 keys, and they are slow. This system can handle 8900 something, and if that isn't enough I could do a small edit to double or triple it (like you'd even ever go near 8900 spells at one time lol).

Plus the ease and format should put this as one of the easier systems to handle it.

Oh and P.S. this doesn't need a hashtable lol :p


@Justify
All array are suppose to start at 0, blizzard starts at 1 for retarded reasons, but programing languages should all start arrays at 0, it's been that way since they invented arrays, it's quite useful in numerous situations. Most people just conform to the bad programming practices of blizzard lol.
 
Level 3
Joined
Aug 27, 2011
Messages
41
Lol ya I knew there was some kind of 256 limit. But still from what I've seen posted by like bribe, _pharoh, and Nestharus, if you have more then like 5 or 6 it starts to lag or something like that. I don't remember exactly what I read but I know they don't suggest it lol
 
then ur matching struct members not the struct itself...

as for hashes, that is why Bribe made the Table library which utilizes only 1 hashtable...

btw, If ur not gonna save into the hashtable, what will you do? save it into an array? then to load a specific instance from a variable, ur gonna loop thru the whole array?? that is slower than hashes, someone told me...
 
Status
Not open for further replies.
Top