• 🏆 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!

[vJASS] Textmacro Problems

Status
Not open for further replies.
Level 11
Joined
Jun 30, 2008
Messages
580
JASS:
    struct attribute
        choice array choices[MAX_CHOICES]
        string name
        integer max_choice
        static method RegisterChoice takes choice c returns nothing
            set .max_choice = .max_choice + 1
            set .choices[.max_choice] = c
        endmethod
        
        static method create takes string name returns attribute
            local attribute r = attribute.allocate()
            set r.name = name
            return attribute
        endmethod
    endstruct
    
    struct choice
        string cname
        //! textmacro SetType takes TYPE
        $TYPE$ data
        static method create takes string name, $TYPE$ a returns choice
            local choice r = choice.allocate()
            set .cname = name
            set .data = a
            return choice
        endmethod
        //! endtextmacro
    endstruct
    
    //! runtextmacro SetType("string")
    function tempint takes nothing returns nothing
        local attribute r = attribute.create("Hair Color")
        call r.RegisterChoice(choice.create("Black", ""))
    endfunction

I keep getting the error: Constructor requires no arguments

Any Ideas why? Keep in mind this is the first time ever messing with textmacros.
 
Level 16
Joined
Aug 7, 2009
Messages
1,403
The way it should look like:

JASS:
struct attribute
    choice array choices[MAX_CHOICES]
    string name
    integer max_choice
    static method RegisterChoice takes choice c returns nothing
        set .max_choice = .max_choice + 1
        set .choices[.max_choice] = c
    endmethod
    
    static method create takes string name returns attribute
        local attribute r = attribute.allocate()
        set r.name = name
        return attribute
    endmethod
endstruct

//! textmacro SetType takes TYPE
    $TYPE$ data
    static method create takes string name, $TYPE$ a returns choice
        local choice r = choice.allocate()
        set .cname = name
        set .data = a
        return choice
    endmethod
    //! endtextmacro

struct choice
    string cname
    //! runtextmacro SetType("string")
endstruct

function tempint takes nothing returns nothing
    local attribute r = attribute.create("Hair Color")
    call r.RegisterChoice(choice.create("Black", ""))
endfunction
 
Level 11
Joined
Jun 30, 2008
Messages
580
Alright that worked, now I added more macros and it isn't working anymore:

JASS:
   struct attribute
    choice array choices[MAX_CHOICES]
    string name
    integer max_choice
    static method RegisterChoice takes choice c returns nothing
        set .max_choice = .max_choice + 1
        set .choices[.max_choice] = c
    endmethod
    
    static method create takes string name returns attribute
        local attribute r = attribute.allocate()
        set r.name = name
        return attribute
    endmethod
endstruct

    //! textmacro SetType takes TYPE
    $TYPE$ data$TYPE$
    static method create$TYPE$ takes string name, $TYPE$ a returns choice
        local choice r = choice.allocate()
        set .cname = name
        set .data$TYPE$ = a
        return choice
    endmethod
    //! endtextmacro

struct choice
    string cname
    //! runtextmacro SetType("string")
    //! runtextmacro SetType("real")
    //! runtextmacro SetType("integer")
endstruct

function tempint takes nothing returns nothing
    local attribute r = attribute.create("Hair Color")
    call r.RegisterChoice(choice.createstring("Black", ""))
endfunction
 
Level 16
Joined
Aug 7, 2009
Messages
1,403
It should be return r. You wan't to return the fresh instance, not the data type.
This one looks better tho':

JASS:
static method create$TYPE$ takes string name, $TYPE$ a returns thistype
    local thistype this=thistype.allocate()
    set this.cname=name
    set this.data$TYPE$=a
    return this
endmethod

Also, you should check the next tutorial: http://www.hiveworkshop.com/forums/...83/jpag-jass-proper-application-guide-204383/
 
Level 11
Joined
Jun 30, 2008
Messages
580
I know how to JASS properly, I was just practicing with textmacros, I've never used them before, so I'm using an old system and try applying it to it.

Thanks for the help, I got it working now. I just never realized where you put the //! runtextmacro goes is where the code is copied to.
 
Status
Not open for further replies.
Top