HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Public/Private

02-13-2008, 12:40 AM#1
Joker
This is just a question on publics. I just put private so people knew what I'm going to talk about.

How come I get an syntax error saying "the variables is undeclared" when i put a public prefix? It works fine w/o it. I thought public prefix allowed it to be declared out of the function?
Collapse JASS:
public constant string CL_P = "CLPB"
02-13-2008, 12:53 AM#2
moyack
is because you need to call the public data in this way:

<Name of the library/scope that contains the variable>_<your public vatriable name>

So, in your example, if the scope or library which contains the variable is called "blabla" the variable must be called blabla_CL_P
02-13-2008, 01:03 AM#3
Anitarf
Let's try an example:
Collapse JASS:
scope foo
    globals
        public string bar = "a"
    endglobals

    public function Display takes nothing returns nothing
        call BJDebugMsg(bar)
    endfunction
    public function DisplayBJ takes nothing returns nothing
        call Display()
    endfunction
endscope

scope foocopy
    globals
        public string bar = "b"
    endglobals

    public function Display takes nothing returns nothing
        call BJDebugMsg(bar)
    endfunction
    public function DisplayBJ takes nothing returns nothing
        call Display()
    endfunction
endscope

function Test takes nothing returns nothing
    call foo_DisplayBJ()
    call foocopy_Display()
    call BJDebugMsg(foo_bar)
endfunction
Calling the function test displays the following:

a
b
a
02-13-2008, 01:56 AM#4
Av3n
Common sense maybe?

Like others stated above, you must use these keywords in a scope or library

-Av3n
02-13-2008, 12:37 PM#5
Vexorian
Quote:
Originally Posted by Joker
This is just a question on publics. I just put private so people knew what I'm going to talk about.

How come I get an syntax error saying "the variables is undeclared" when i put a public prefix? It works fine w/o it. I thought public prefix allowed it to be declared out of the function?
Collapse JASS:
public constant string CL_P = "CLPB"
Try moving the global declaration before the function that uses it.
02-13-2008, 08:23 PM#6
Joker
Quote:
Originally Posted by Av3n
Common sense maybe?

Like others stated above, you must use these keywords in a scope or library

-Av3n
Can't say this is common sense to someone with absolutely no programming background or any skill with vJass. Moyack's comment along with Aniarf's example was enough. I don't see a point of your post. >.>

@Vex
It was declared in a library. I think that solves that.