• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!

[JASS] Random Questions

Status
Not open for further replies.
Level 13
Joined
Nov 22, 2006
Messages
1,260
Hello people, I have some questions about vJass, because I love it and I want to know all about it.

1) So, scopes are a way to have private functions, struct etc. but what about globals (globals.......endglobals)? Are they also private when they are in a scope? If yes, then what does "private integer" (example) do when in "globals"?
2) What's the point in making a spell with private structs/functions in it? (a more detailed answer here please)
3) Is there a tutorial on Dinamic Arrays? Why are they useful, what exactly do they do?
4) Why do methods differ from normal functions? Why putting them there?
5) Is there any point in converting a function that attaches only reals and integers on a handle to use structs?
6) I saw somewhere that scopes are supposed to go as comments, not directly, is that true? (//! scope........//! endscope, i think it was like that)

I wonder how people know these things (libraries/scopes) if there's no tutorial on them.

Well, thanks in advance :D

P.S. Maybe I'll be adding some more questions to this thread (editing this post) when I come up with them, I just can't remember all the things I wanted to ask, so look in this first post every now and then just in case
 
Level 14
Joined
Nov 20, 2005
Messages
1,156
1) So, scopes are a way to have private functions, struct etc. but what about globals (globals.......endglobals)? Are they also private when they are in a scope? If yes, then what does "private integer" (example) do when in "globals"?

Only if you use the 'private' keyword for the variable. You can also use 'public'. Public adds the scope name plus '_' to the front, while private also adds a random number in.

2) What's the point in making a spell with private structs/functions in it? (a more detailed answer here please)

Makes it so they don't conflict with other spells or systems, while keeping short names. That's it.

3) Is there a tutorial on Dinamic Arrays? Why are they useful, what exactly do they do?

I don't really use them, but they allow you to get and release arrays on the fly.

4) Why do methods differ from normal functions? Why putting them there?

Methods are functions that are part of classes (or scopes?). They are used differently to normal functions, with OBJECT.METHOD()

5) Is there any point in converting a function that attaches only reals and integers on a handle to use structs?

Yes. Faster.

6) I saw somewhere that scopes are supposed to go as comments, not directly, is that true? (//! scope........//! endscope, i think it was like that)

Yes.

I wonder how people know these things (libraries/scopes) if there's no tutorial on them.

Info is hosted at WC3Campaigns. Which is currently down.
 
Level 13
Joined
Nov 22, 2006
Messages
1,260
Thanks, though I didn't quite understand the first answer, can you give a more detailed answer? (I understood the first sentence)

I know methods are used differently, I just wondered are the results different.

On wc3campaigns there is a tutorial only on structs and textmacros, not on libraries or scopes

Thanks, that helped a lot! +rep
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
What griffen left off on;

-Dynamic Arrays can;

A) be arrays of arrays
B) be parameters/returns

(A) isn't practical that often, since you'll run out of space quickly. However, A's syntax would be

JASS:
type horiz extends integer array [20]
type vert extends horiz array [20]

function InitCell takes nothing returns vert
    local vert v = vert.create()
    local integer i = 0
    loop
        exitwhen i > 19
        set v[i] = horiz.create()
        set i = i + 1
    endloop
    return v
endfunction

function UseCell takes nothing returns nothing
    local vert v = InitCell()
    set v[4][3] = 2
endfunction

The syntax for (B) is demonstrated in (A), such as

JASS:
type splitstring extends string array [20]
function UseSplitString takes splitstring s returns string
    return s[5]
endfunction

Also,

6) I saw somewhere that scopes are supposed to go as comments, not directly, is that true? (//! scope........//! endscope, i think it was like that)
You can, but it's being deprecated. You can now do that sort of stuff directly, such as

JASS:
library n
endlibrary
scope s
endscope
 
Level 13
Joined
Nov 22, 2006
Messages
1,260
Thanks, I'm new to reputation system, so I don't know when exactly do you add +rep....anyways, I gave you one

Two more questions:
1) What does "public" do exactly?
2) Can you access variables under "globals"......."endglobals" from another trigger, does it act like it's really a global? What exactly is an advantage of "globals"......."endglobals"?
 
Last edited:
Level 14
Joined
Nov 20, 2005
Messages
1,156
Public addes the scope name to the front plus _. So:

JASS:
//! scope Dog

globals
    public integer Animal
endglobals

//! endscope

    set Dog_Animal = 1

Globals declared in global tags are globals (they actually get moved to the top of the script). The advantage is it is far easier to work with than the WE's own built in global declaration.
 
Status
Not open for further replies.
Top