another question... static ifs and text macros together, + rep for help

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
ok so heres my problem, im trying to create a data sorting system, and im having issues with my remove function
it uses 2 text macros to be implemented properly, i have included an example, i am posting the actual system, but im not looking for a critique on it, it is just the beginning and is nowhere near done, i just wanted to know what the problem is with static ifs, can textmacros not have static ifs inside? do the booleans for static ifs need to be defined before compile?

the error i get is: expected a name for the line: else

heres the code:

example:
JASS:
//! runtextmacro STDConstant("integer")

struct Example extends array
    //! runtextmacro STD("thisUnit", "unit", "private", "kills", "integer", "private")
endstruct


system:
JASS:
/*
S.T.D.
Sort Titanic Data, stores vast ammounts of data in a sorted linked list allowing you to accurately sort vast datatypes and ammounts of data
*/

library STD

    //! textmacro STDConstant takes VARTYPE
        function $VARTYPE$_Number takes nothing returns boolean
            return "$VARTYPE$" == "integer" or "$VARTYPE$" == "real" or "$VARTYPE$" == "unittype" or "$VARTYPE$" == "ability"
        endfunction
    //! endtextmacro
    
    //! textmacro STD takes VARNAMEBASE, VARTYPEBASE, VISIBILITYBASE, VARNAME, VARTYPE, VISIBILITY
        $VISIBILITYBASE$ $VARTYPEBASE$ $VARNAMEBASE$
        $VISIBILITY$ $VARTYPE$ $VARNAME$
        private integer basePosition
        private integer next
        private integer previous
        
        private static integer array recycleList
        private static integer lastRecycled
        private static integer listCount
        private static integer listSize
        
        static method allocation takes nothing returns thistype
            local thistype this = .recycleList[0]
            if this == 0 then
                debug if .listCount >= 8190 then
                debug     call BJDebugMsg("STD ERROR: Attempting to add another set of data higher than the max")
                debug     return 0
                debug endif
                set .listCount = .listCount + 1
                set thistype(.listCount).basePosition = .listCount
                return .listCount
            endif
            set thistype(thistype(0).previous).next = this
            set thistype(0).previous = this
            set .listSize = .listSize + 1
            set this.basePosition = .listSize
            return this
        endmethod
        
        static method deallocate takes integer i returns nothing
            set thistype(thistype(i).previous).next = thistype(i).next
            set thistype(thistype(i).next).previous = thistype(i).previous
            set .recycleList[.lastRecycled] = i
            set .lastRecycled = i
            set .listSize = .listSize - 1
        endmethod
        
        static method sortThis takes integer a returns integer
            local thistype this = a
            local boolean bool = false
            loop
                exitwhen bool
                if thistype(this.next).$VARNAME$ >= this.$VARNAME$ then
                    set this.basePosition = this.basePosition + 1
                    set thistype(this.next).basePosition = thistype(this.next).basePosition - 1
                    set thistype(this.previous).next = this.next
                    set thistype(this.next).previous = this.previous
                    set this.previous = this.next
                    set this.next = thistype(this.next).next
                    set thistype(this.previous).next = this
                    call thistype.sortThis(this.previous)
                elseif thistype(this.previous).$VARNAME$ <= this.$VARNAME$ then
                    set this.basePosition = this.basePosition - 1
                    set thistype(this.previous).basePosition = thistype(this.previous).basePosition + 1
                    set thistype(this.next).previous = this.previous
                    set thistype(this.previous).next = this.next
                    set this.next = this.previous
                    set this.previous = thistype(this.previous).previous
                    set thistype(this.next).previous = this
                    call thistype.sortThis(this.next)
                endif
                if this.$VARNAME$ <= thistype(this.next).$VARNAME$ and this.$VARNAME$ >= thistype(this.previous).$VARNAME$ then
                    set bool = true
                endif
            endloop
            return this.basePosition
        endmethod
        
        static method addTo$VARNAME$ takes $VARTYPEBASE$ $VARNAMEBASE$, $VARTYPE$ change returns nothing
            local thistype this = thistype(0).previous
            loop
                exitwhen this.$VARNAMEBASE$ == $VARNAMEBASE$
                set this = thistype(this).previous
            endloop
            set this.$VARNAME$ = this.$VARNAME$ + change
            call thistype.sortThis(this)
        endmethod
        
//======================================================================================================
//HERE is where i use the static if <-------------------------------------------------------------------
//======================================================================================================

        static if $VARTYPE$_NUMBER
            static method remove$VARNAMEBASE$ takes $VARTYPEBASE$ $VARNAMEBASE$ returns nothing
                local thistype this = thistype(0).previous
                loop
                    exitwhen this.$VARNAMEBASE$ == $VARNAMEBASE$
                    set this = thistype(this).previous
                endloop
                set this.$VARNAME$ = 0
                call thistype.sortThis(this)
                call thistype.deallocate(this)
            endmethod
        else
            static method remove$VARNAMEBASE$ takes $VARTYPEBASE$ $VARNAMEBASE$ returns nothing
                local thistype this = thistype(0).previous
                loop
                    exitwhen this.$VARNAMEBASE$ == $VARNAMEBASE$
                    set this = thistype(this).previous
                endloop
                set this.$VARNAME$ = null
                call thistype.sortThis(this)
                call thistype.deallocate(this)
            endmethod
        endif
        
        static method add$VARNAMEBASE$ takes $VARTYPEBASE$ $VARNAMEBASE$, $VARTYPE$ $VARNAME$ returns nothing
            local thistype this = thistype.allocation
            set this.$VARNAMEBASE$ = $VARNAMEBASE$
            set this.$VARNAME$ = $VARNAME$
            call thistype.sortThis(this)
        endmethod
        
    //! endtextmacro
endlibrary
 

Dirac

22710180
Reaction score
147
can textmacros not have static ifs inside?
Did you mean...
can textmacros have static ifs inside?

And yes they can, the booleans are compiled before textmacro declaration

Also
[ljass]static if $VARTYPE$_NUMBER[/ljass]
->
[ljass]static if $VARTYPE$_NUMBER then[/ljass]

You should really read what the compile error says, they always point where the error is

May i ask why are you doing this? I already wrote a sorting algorithm for linked lists
 

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
to improve my scripting abilities...
and i dont get a compile error with:
[ljass]static if $VARTYPE$_NUMBER[/ljass]
but i do with:
[ljass]static if $VARTYPE$_NUMBER then[/ljass]

i read the compile errors every time, the syntax error i was getting was only when i had the then added on

and dirac i dont script in wc3 anymore i use sc2, so jass for me is useless, but i want to learn how to do it simply to improve my coding abilities, going to school to be a programmer

and can you have the static if comparison created in a text macro?
 

Dirac

22710180
Reaction score
147
As i said in the previous post yes you can
But your textmacro is filled with nonsense stuff such as
JASS:
function $VARTYPE$_Number takes nothing returns boolean
    return "$VARTYPE$" == "integer" or "$VARTYPE$" == "real" or "$VARTYPE$" == "unittype" or "$VARTYPE$" == "ability"
endfunction

Those are string comparisons...
Also as i previously said i already wrote a sorting algorithm for linked lists way better than the one you're using
 

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
they are string comparisons that allow to compare variable types to determine if the variable type is an integer/real and whether or not it is possible to set it to [ljass]null[/ljass] before removing it, that comparison is used to create a static if constant using a textmacro
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top