HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

syntax for method Create

03-07-2008, 09:33 PM#1
Szythe
can anyone tell me the correct syntax for the method Create? i know its supposed to be static and its supposed to return something, but I'm pretty lost as to how exactly it is supposed to be set up.
03-07-2008, 09:36 PM#2
Anitarf
http://www.wc3campaigns.net/vexorian...permanual.html

It's a bit outdated but there haven't really been any recent changes to the create method so it shold serve you just fine.
03-07-2008, 10:01 PM#3
TheSecretArts
set (Variable) = (Variabletype).create() IE;
Collapse JASS:
struct vector
     real x
     real y
     real z
     real Force
endstruct
function stuff takes nothing returns nothing
    local vector v
    set v = vector.create()
    set v.x = 1
    set v.y = 1
    set v.z = 1
    set v.Force = 0
    //Blah blah more stuff
    call vector.destroy(v)
endfunction
You can also specify what the function does
Collapse JASS:
struct vector
     real x
     real y
     real z
     real Force
     static method create takes real X, real Y, real Z, real F returns vector
            local vector Vec = Vector.allocate()
            set Vec.x = X
            set Vec.y = Y
            set Vec.z = Z
            set Vec.Force = F
            return Vec
     endmethod
endstruct
function stuff takes nothing returns nothing
    local vector v
    set v = vector.create(1,1,1,0)
    //Blah blah more stuff
    call vector.destroy(v)
endfunction
03-07-2008, 11:56 PM#4
Toadcop
btw yes. in fact methods makes not really much sense due the methods in structures make all harder to read =). but ofc it's a question of taste (education). i prefer to use simple functions. and there is no magic behind. in some cases vJass have slower realisations than possible with "normal" (omg we have now the time than we must point it >.<) jass. but the most common features realisation is top.

// Jass New Gen Pack (Jass Helper) have a manual ^^ (with relative nice examples)
03-08-2008, 12:18 AM#5
Ammorth
create method must be static and must return the type.

static method create takes anything returns type
03-08-2008, 01:34 AM#6
cohadar
Collapse JASS:
struct StructName
    static method LetThereBeStruct takes nothing returns StructName
        local StructName dat = StructName.allocate()
        // add your stuff here
        return dat
    endmethod
endstruct

//------------------------------------------------------------------
//  Other optional names for create method are :
//
//  SuckMyBalls
//  KylesMomIsABiach
//  ScrewYouGuysIAmGoingHome
//  OmgYouKilledKennyYouBastards
//  ...
//------------------------------------------------------------------
03-08-2008, 03:09 AM#7
Szythe
Thanks everyone for the help, I wanted to use Rain9441's Autocast System for my map, but it caused errors (linked to the initialization of structs) with the newest vjass compiler. I've got it working now.