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.
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      The Helper Discord

      Staff online

      • Ghan
        Administrator - Servers are fun

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top