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

Library requires library not working

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

Suppose we have 2 libraries, A and B.

Library B requires Library A, as Library A fills up a special table that B needs to do its work correctly.

JASS:
library A initializer init
globals
  integer array INTS[5]
endglobals

private function main takes nothing returns nothing
  set INTS[0] = -555
endfunction

private function init takes nothing returns nothing
  local timer t = CreateTimer()
  call StartTimer(t, 1.0, false, function main)
endfunction

endlibrary

and our second library

JASS:
library B initializer init requires A

globals
endglobals

private function init
  call print(I2S(INTS[0])) //this should print "-555"
  //instead it prints "0"
endfunction

endlibrary

So, even though B requires A, somehow B's init fires off before A fills up its data structure. This is impossible given the documentation I've read, which promises that all of B's work, etc. will be started only AFTER A.

Or is the timer somehow messing things up? (should be in manual...)
 
Level 15
Joined
Aug 7, 2013
Messages
1,337
Silly of me to ask. I was thinking (wrongly) that it would have to wait for the timer to finish before A.init gave up its thread, but I guess the timer actually sleeps it for whatever amount of time, and then moves onto the next job, by which time the data structures are made out of place. More efficient, because otherwise we're waiting a second doing nothing.

This would all be so much simpler if dialogs could be made in initializations. I ended up just calling the init function of library B inside A's main function.
 
Status
Not open for further replies.
Top