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

[JASS] 3 Jass Questions

Status
Not open for further replies.
Level 10
Joined
Jan 21, 2007
Messages
576
Alright, I've been learning jass recently (today >.>) and I have gone through vex's tut completly and understand everything, and I skimmed Daelians. What I'm wondering is what the difference between:
JASS:
private constant integer AID
and
JASS:
constant integer AID
and
JASS:
integer AID
is.

I know what the bottom one does, but vex's tutorial didn't explain private or constant, (it started using constant at the end but never really said why.)

I think constant means the value doesn't change ever, and private means it can only be accessed from within the "library" it is declared in.

In addition I am unaware of the purpose of a library.

So anyone that can answer any of these is welcome here, I didn't find solutions in Daelians, Vex's, 56k's, emjlrs, or a things tutorial to these questions, so if there is a tutorial out there that has this information feel free to link it.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
private means it can only be referenced within the area it was declared, weather struct, library, scoop or even one of those within one of those. The main reason to use it is to avoind variable name clashes for commonly used variable names.

constant purly means you can not change its value after decleration. I have have been told that it does not alter the opperation of the variable in anyway during actual gameplay in WC3 and is purly a syntax restriction for WE.

private constant integer AID will only be usable and not updatable within a certain vJASS structure. Unlike the other 2, it needs a vJASS enhanced editor like JNGP to compile into JASS so WC3 can run it and will appear in the global decleration section of your map's trigger script as something different.

constant integer AID will be usable in any function within your map but will not be updatable. This is also how the line would appear in the global decleration section of the map trigger script.

integer AID will be usable and updatable in any function within your map. This is also how the line would appear in the global decleration section of the map trigger script.
 
Level 10
Joined
Jan 21, 2007
Messages
576
Thanks triggerhappy, so my understanding now of libraries is that they are used to simply make a code easier to read, moving its contents to the top when compiled, above all calls to its contents.

In addition that tutorial was very helpful but also brings up another question
Scopes act in the exact same way as libraries do, with the exception that scopes are not moved to the top of the code. Defining scopes is also done in a similar way to libraries; the word 'library' is just replaced with the word 'scope'. So, this is what a scope could look like
Then when would you use a scope... why not just use a library if it doesn't change anything except having it being called something different (obviously I'm missing something here)?
EDIT: Ooo, is it that it still runs its contents at map init, but doesn't move it to top? That makes more sense.

HINDYhat, Inlined?

EDIT: And thanks DSG for clearing that all up, very informative post ;] +rep
 
Level 20
Joined
Apr 22, 2007
Messages
1,960
Libraries are used for systems and such. You could use a library instead of a scope, but that doesn't make any sense. But you cannot use a scope instead of a library.

Inlined means basically that the value will be replaced when the script is compiled. Like let's say this is your script:
JASS:
private constant integer LOL = 5

// somewhere in a function
set omghax = LOL

Compiled would yield:
JASS:
// somewhere in a function
set omghax = 5

Useful for custom spells and systems where constants need to be defined.
 
Level 21
Joined
Aug 21, 2005
Messages
3,699
A scope basically defines "where" you can use a certain variable or function. For instance:

JASS:
function Test takes nothing returns nothing
    local integer i = 15
    // do stuff with i
endfunction

function Test2 takes nothing returns nothing
    // I cannot use i here
endfunction

In this script, the scope of "i" is function "test". I.e. "i" in this context is only defined in the test function and cannot be used in Test2 for obvious reasons. Global variables have a "global scope", i.e. they can be used anywhere. In jass, these scopes are automatically handled by the compiler (so you can't use "i" in Test2)

Often you'd want to give functions a scope as well, so they can only be used in certain parts of your script and are only visible in those parts of the script. This wasn't possible yet in jass, so the extended language vjass added scope functionality...

Libraries are a different thing. A library (imo) encourages modularity. While in warcraft 3 you have 1 huge script with all functions and variables, you probably want to keep things clean and modular because reading through a 1000 lines of code isn't a lot of fun.

A library basically is a collection of functions and variables that provide you an interface to a complex system. A typical advantage of a library is the possibility of simply copying the library and pasting it in another map, and it works perfectly as it is supposed to, without having to be busy with cutting a function here and pasting it there, making your code a mess.

Some examples are: a save/load system (I don't want to be busy copying triggers and functions scattered over the whole map, I want my save/load system to be plug-and-play), a camera system, spells, etc.
 
Status
Not open for further replies.
Top