HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

vJass Library Scope

09-28-2007, 03:00 PM#1
Strilanc
I'm having issues with the scope of a function. Why can't T in Z see Y in X?

Collapse JASS:
//trigger 1
library X
  ...
  public function Y ...
    ...
  endfunction
  ...
endlibrary

//trigger 2
struct Z
  ...
  public static method T ...
    ...
    call Y() //<=== compile error, undeclared function Y
    ...
  endmethod
  ...
endstruct

Look at the script shown with the compile error, I can see Y is changed to X_Y, which makes sense; except call Y() isn't changed and none of the other functions in X have the X_ prefix. Could it have to do with the fact that I use a struct instead of Y? Change call Y() to call X_Y() works... except that's ugly.
09-28-2007, 03:28 PM#2
Vexorian
call X_Y()
09-28-2007, 03:29 PM#3
moyack
Collapse JASS:
//trigger 1
library X
  ...
  public function Y ...
    ...
  endfunction
  ...
endlibrary

//trigger 2
struct Z
  ...
  public static method T ...
    ...
    call X_Y() //<=== it won't generate error anymore
    ...
  endmethod
  ...
endstruct

If you want to call it as only Y(), then remove the public keyword from the function.

EDIT: Damm!! Vex won me :P
09-28-2007, 03:31 PM#4
Hitchhiker
if you think thats ugly, you could remove the "public" prefix from the function Y.
But as the function is in a library i would just go with X_Y. So you see immediately that the function Y belongs to the library X.

edit: damn those fast people >_<... i think you get it now
09-28-2007, 04:57 PM#5
Strilanc
Oh, so the "public" keyword in a library means "you have to use a prefix".

Useful thing to know, I assumed public was just optional.
09-28-2007, 05:12 PM#6
Captain Griffen
Public is optional, but does something.
09-28-2007, 05:30 PM#7
moyack
Sometimes it's convenient to use the prefix (mainly when you have several libraries or scopes with functions with common names, for instance), but most of the times, it's not necessary.