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

[vJASS] Stating a reference to an external struct in constants of a scope?

Status
Not open for further replies.
Level 4
Joined
Sep 25, 2005
Messages
71
So, say for instance I had a scope setup which was basically a spell framework. I'm using the constants as a set of toggles for behavior/damage values. I basically want to know if it's possible to have a constant that you can change to the struct of your choice, say if you had a struct setup that creates an AOE Heal when passed parameters, or damage, or has a certain spell effect. The desired coding is such that I can use a constant in the code and declare what struct I'd be using with the constants. Is this possible? I'm pretty sure I can't declare a "private constant struct," but is there some way within code to change

JASS:
                               call structname.create(parameters)

to

JASS:
                               call CONSTANT_STRUCT.create(parameters)

and just set which struct up in constants, are at least a way to reference what struct?
 
Level 22
Joined
Sep 24, 2005
Messages
4,821
Use global variables for constants, make them private.

JASS:
globals
private constant string constString = "Hello World!"
endglobals
 
Level 4
Joined
Sep 25, 2005
Messages
71
The thing before the period is simply the structs name. You can name it whatever you want to. It is standard to name it like this though.
JASS:
structName
You can't have a constant struct as a struct is an array of data.
You can have a private struct though.

I figured, and that's how I've been doing it, but I was wondering if there's some way to say, perhaps set a constant string, and replace instances of STRUCTNAME_GLOBAL (just an example) with the string.
 
Level 14
Joined
Dec 12, 2012
Messages
1,007
Yes, with textmacros:

JASS:
//! textmacro GENERATE_STRUCT takes STRUCT_NAME
    struct $STRUCT_NAME$
        // Your stuff here
    endstruct
//! endtextmacro

// And now generate your different structs like this
//! runtextmacro GENERATE_STRUCT("Struct1")
//! runtextmacro GENERATE_STRUCT("Struct2")
//! runtextmacro GENERATE_STRUCT("Struct3")
 
You should be able to pass virtually anything to the textmacro:
JASS:
//! textmacro Set takes PARAM
    call BJDebugMsg(I2S($PARAM$))
//! endtextmacro

globals
    constant integer test = 52
endglobals

function Example takes nothing returns nothing 
    //! runtextmacro Set("5")
    //! runtextmacro Set("test")
endfunction

Heck, you can even do something as weird as:
JASS:
//! textmacro Weird takes PARAM
    set lol$PARAM$ = 52
//! endtextmacro

globals
    integer lolinteger = 0
endglobals

function Example takes nothing returns nothing 
    //! runtextmacro Weird("integer")
endfunction
 
Level 4
Joined
Sep 25, 2005
Messages
71
You should be able to pass virtually anything to the textmacro:
JASS:
//! textmacro Set takes PARAM
    call BJDebugMsg(I2S($PARAM$))
//! endtextmacro

globals
    constant integer test = 52
endglobals

function Example takes nothing returns nothing 
    //! runtextmacro Set("5")
    //! runtextmacro Set("test")
endfunction

Heck, you can even do something as weird as:
JASS:
//! textmacro Weird takes PARAM
    set lol$PARAM$ = 52
//! endtextmacro

globals
    integer lolinteger = 0
endglobals

function Example takes nothing returns nothing 
    //! runtextmacro Weird("integer")
endfunction

So I can pass values from constants, that much works.
However, say I set up:

JASS:
globals
private global constant string STRUCT_NAME = neededstruct
endglobals

JASS:
//! textmacro Set takes PARAM
call $PARAM$.create()
//! endtextmacro

//! runtextmacro Set("STRUCT_NAME")

Would it work?
 
Level 22
Joined
Sep 24, 2005
Messages
4,821
Do you want function overloading? I've reviewed your first post (carefully this time), and I'm assuming you want to overload a function.
My interpretation of your question is that you want a certain struct (or maybe a struct method?) to process data, in which the data (parameters?) passed will determine what process it would perform?

If so then I think vJass cJass has that feature. [link]
 
Last edited:
Status
Not open for further replies.
Top