HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

vJass: Structs cannot access private structs?

11-13-2007, 09:33 PM#1
The Kingpin
Private functions can access other private functions in a scope/library, but it can't do the same with structs, like in here:

Collapse JASS:
library C
    struct a
        b other
        
        method blah takes nothing returns nothing
            set this.other = b.create()
        endmethod
    endstruct
    
    private struct b
    endstruct
endlibrary

It gives me the syntax error "b is not a type that allows . syntax.".
Is this supposed to be like this or is this a bug? Is there a way around it?
11-14-2007, 01:24 AM#2
Pyrogasm
Might "b" need to be above "a"? I don't know if that is required in vJASS.
11-14-2007, 01:30 AM#3
wyrmlord
Quote:
Originally Posted by Pyrogasm
Might "b" need to be above "a"? I don't know if that is required in vJASS.
It appears it is required in vJASS. Moving the private struct b above struct a did give a successful save.
11-14-2007, 02:01 AM#4
Earth-Fury
its a... "bug" ?... things declared as private must be declared before they are used.
11-14-2007, 02:33 AM#5
Vexorian
Collapse JASS:
library C
    private keyword b

    struct a

        b other
        
        method blah takes nothing returns nothing
            set this.other = b.create()
        endmethod
    endstruct
    
    private struct b
    endstruct
endlibrary
11-14-2007, 06:25 AM#6
Pyrogasm
So that's what keywords are for?
11-14-2007, 11:12 AM#7
The Kingpin
Never knew that even existed. It's not in the manual....
Well, we all learned something.
11-14-2007, 12:41 PM#8
Vexorian
Quote:
keyword

The keyword statement allows you to declare a replacement directive for an scope without declaring an actual function/variable/etc. It is useful for many reasons, the most important of the reasons being that you cannot use a private/public member in an scope before it is declared, in most cases this limitation is no more than an annoyance requiring you to change the position of declarations, in other situations though this is a limitator of other features.

For example two mutually recursive functions may use .evaluate (keep reading this readme) to call each other, but if you also want the functions to be private it is impossible to do it without using keyword:

Collapse JASS:
scope myScope

   private keyword B //we were able to declare B as private without having to actually
                     //include the statement of the function which would cause conflicts.

   private function A takes integer i returns nothing
       if(i!=0) then
           return B.evaluate(i-1)*2 //we can safely use B since it was already
                                    //declared as a private member of the scope
       endif
       return 0
   endfunction

   private function B takes integer i returns nothing
       if(i!=0) then
           return A(i-1)*3
       endif
       return 0
   endfunction

endscope
.
11-15-2007, 06:52 AM#9
Pyrogasm
I swear that's not in the manual here: http://www.wc3campaigns.net/vexorian...permanual.html
11-15-2007, 12:26 PM#10
Vexorian
Perhaps the old version number is at fault?

Your sig is too big.
11-15-2007, 11:41 PM#11
Pyrogasm
Well where's the link to the online manual for the newest JASSHelper, then.

Fix'd the sig.