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

[JASS] How to use "struct extends array"?

Status
Not open for further replies.
Level 6
Joined
Feb 19, 2008
Messages
89
Hi, in my map i trying to initialize only picked heros trigerred abilities.
(my map have over 300 trigerred abilities, i think it can decrease loading time and map initial handles significatively.)

but the 2 major problens is:

How i can declare this structs?(i don't know sintax:hohum:)
ex:
struct Heros extends array
integer id
string icon
endstruct

and, how to enable each hero spells init functions?

ex:
code spell1
code spell2

or

method init takes nothing returns nothing
call spell1()
cal spell2()
endmethod

ps: sorry if have english mistakes, my english isen't good, but i trying to improve, and thanks for any help.
 
Level 11
Joined
Feb 22, 2006
Messages
752
Declaring array structs:

JASS:
struct A extends array
    integer id
    unit u
endstruct

For the initialization functions, you would have to call them on map init, so put them in an initializer for a library or a scope. So for example:

JASS:
library L initializer init
private function spellInit1 takes nothing returns nothing
    // ...
endfunction

private function spellInit2 takes nothing returns nothing
    // ...
endfunction

private function init takes nothing returns nothing
    call spellInit1()
    call spellInit2()
   //  ...
endfunction
endlibrary
 
Level 6
Joined
Feb 19, 2008
Messages
89
I trying something like this:

JASS:
library SetHeros initializer Init

struct Heros extends array
    integer id
    boolean pic
    string icon
    string spell1
    string spell2
    string spell3
    string spell4
endstruct

private function  takes nothing returns nothing

endfunction

private function Init takes nothing returns nothing
    set Hero.id[0] = 'EC73'
    set Hero.pic[0] = false
    set Hero.icon[0] = "ReplaceableTextures\\CommandButtons\\BTNVoidWalker.tga"
    set Hero.spell1[0] = "Avalon_init"
endfunction

endlibrary

JASS:
call ExecuteFunc(Hero.spell1[i])

but, how to do it without executefunc?
I see something over function interface but i don't know how to use it =/.
 
Level 11
Joined
Feb 22, 2006
Messages
752
The syntax for function interfaces is:

JASS:
library SetHeros initializer Init
struct Heros extends array 
    integer id
    boolean pic
    string icon
    SpellInit spell1
    SpellInit spell2
    SpellInit spell3
    SpellInit spell4
endstruct

private function interface SpellInit takes nothing returns nothing

private function spell1Init takes nothing returns nothing
    // ...
endfunction

private function spell2Init takes nothing returns nothing
    // ...
endfunction

private function Init takes nothing returns nothing
    set Heros.id[0] = 'EC73'
    set Heros.pic[0] = false
    set Heros.icon[0] = "ReplaceableTextures\\CommandButtons\\BTNVoidWalker.tga"
    set Heros.spell1[0] = spell1Init
    set Heros.spell2[0] = spell2Init
    // ...
endfunction
endlibrary

Then to run the functions you just do something like:

JASS:
private function initHero takes nothing returns nothing
    call Heros[0].spell1.execute()
    call Heroes[0].spell2.execute()
    // ...
endfunction

You can also pass variables to those functions if you want (though it's an init function so there prolly isn't much point to do so). In that case you just need to specify so in the function interface declaration and use .evaluate() instead of .execute().
 
Status
Not open for further replies.
Top