Using private globals outside a textmacro

Builder Bob

Live free or don't
Reaction score
249
Let's say I have some code like this:

JASS:
library SomeLibrary

globals
	public integer ParentGlobal = 0
endglobals

//! textmacro SomeGenericTextMacro takes Name
function $Name$Function takes nothing returns nothing
	local integer i = SomeLibrary_ParentGlobal
endfunction
//! endtextmacro

endlibrary


Is there any way of making the ParentGlobal variable private and still have the function within the text macro able to utilize it?
 

Azlier

Old World Ghost
Reaction score
461
First, you could try private and __ instead of _. If that doesn't work, it really isn't possible.
 

Azlier

Old World Ghost
Reaction score
461
Ah, but modules only work inside structs. What we need is a module that works outside structs. Let's go bug Vex for them.
 

Builder Bob

Live free or don't
Reaction score
249
Try

JASS:
SomeLibrary___<PrivateName>
(Three underscores)

[del]Using three underscores actually worked! (compiled at least. going to test it further)[/del]


[del]I'm really surprised it worked.[/del]
Quote from the Jasshelper manual:
The way private work is actually by automatically prefixing scopename(random digit)__ to the identifier names of the private members. The random digit is a way to let it be truly private so people can not even use them by adding the preffix themselves.

[del]However, I am pleased :)[/del]

After further testing it seems it compiles some times, and other times not. Probably the random number factor or maybe some error on my account. Who knows.
 

Azlier

Old World Ghost
Reaction score
461
Vex lied to us. I knew something was up when I checked compiled vJass code and there was a severe lack of lolnumbers.
 

_whelp

New Member
Reaction score
54
I noticed it when there were errors in some code that wasn't vJass and Jasshelper showed the vJass code differently...
 

Builder Bob

Live free or don't
Reaction score
249
Vex lied to us. I knew something was up when I checked compiled vJass code and there was a severe lack of lolnumbers.

Could be. Something's up in any case.
JASS:
library CrashTest

globals
	private integer TestVar = 0
	crash!
endglobals

endlibrary

When I check the name of this private variable after the compiler shows syntax errors, it's name varies between



CrashTest__TestVar and CrashTest___TestVar (2 and 3 underscores)
 

Builder Bob

Live free or don't
Reaction score
249
Put that keyword thing in your textmaco?

you mean like this?
JASS:
library SomeLibrary

globals
	private integer ParentGlobal = 0
endglobals

endlibrary

//! textmacro SomeGenericTextMacro takes Name
private keyword ParentGlobal

function $Name$Function takes nothing returns nothing
	local integer i = ParentGlobal
endfunction
//! endtextmacro

scope Outside
//! runtextmacro SomeGenericTextMacro("Test")
endscope


I get syntax error: Undeclared variable Outside___ParentGlobal
 

Azlier

Old World Ghost
Reaction score
461
SomeLibrary___ defeats the entire point of the keyword, doesn't it?
 

Builder Bob

Live free or don't
Reaction score
249
SomeLibrary___ defeats the entire point of the keyword, doesn't it?

Yup.

Also, having private keyword SomeLibrary___ParentGlobal inside the textmacro will compile into:

JASS:
scope Outside

function $Name$Function takes nothing returns nothing
        local integer i = Outside___SomeLibrary___ParentGlobal
endfunction

endscope


I'll give this up. Any variables declared within the macro will only have relations to the scope the //! runtextmacro call originated from.

Public variables will have to do. Thanks for all the input.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top