• 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.

Library requires library not working

Status
Not open for further replies.
Level 15
Joined
Aug 7, 2013
Messages
1,338
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,338
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