• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[vJASS] Where to put init function in library?

Status
Not open for further replies.
Level 15
Joined
Aug 7, 2013
Messages
1,338
Hi,

I would like to know if this library would compile / work under my expected behavior.

I would test it myself but both my Windows machines are in repair and I haven't yet been able to compile/syntax check on the mac.

JASS:
library myLib initializer init

globals
endglobals

function A …
…
endfunction

function init takes nothing returns nothing
call B()
…
endfunction

function B …
…
endfunction

endlibrary

In most code I always see the init function as the last. But I hope it does not matter where it is placed?
 
Level 13
Joined
Mar 19, 2010
Messages
870
JASS:
library myLib initializer init

globals
endglobals

function A …
…
endfunction

function B …
…
endfunction

function init takes nothing returns nothing
call B()
…
endfunction

endlibrary

Always on the bottom.
 
Basicly your init does not have to be the last function, but it would be more messy just to put it anywhere.

But still your problem is the restriction in jass that you can't use functions that are below in compiled code. So no matter if it's init or any other function, but if you call function B inside function X then B must be above function X.

That's the sense of libraries... to move the code above all others to make the functions inside available for all triggers. But inside a library the rule is of course the exactly same.
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
Basicly your init does not have to be the last function, but it would be more messy just to put it anywhere.

But still your problem is the restriction in jass that you can't use functions that are below in compiled code. So no matter if it's init or any other function, but if you call function B inside function X then B must be above function X.

That's the sense of libraries... to move the code above all others to make the functions inside available for all triggers. But inside a library the rule is of course the exactly same.

you can use(not directly call) functions that are below yours, but its about 4 times slower.
http://www.hiveworkshop.com/forums/submissions-414/system-customhero-251313/index2.html#post2522070

The rest of what Iceman said applies
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
no, unfortunarely it is not that smart. It will try to create copy of the function at the top of the map's script right below endglobals keyword, but at certain cases it can fail to call it and it will instead call trigger evaulation/exection with yet another copy of the function, which is a bit modified.

Check the post Ive made, it is apperant that one function got placed at the top and the other had to be TriggerEvaluate/Executed
 
Status
Not open for further replies.
Top