Page 1 of 1
JASS Question
Posted: October 26th, 2008, 11:29 pm
by Perhaps
How the hell is the syntax to set array size for variables creating them in JASS?
globals
integer array A[9]
endglobals
...would seem like the way I'd do it, but apparently isn't the case.
Yes, yes... I know I can make globals in the variable editor and use them in JASS via adding "udg_" as a prefix. However, I'd prefer not to use the variable editor simply because it's quicker for me to get around to them. I'd also like to set a size for local arrays, rather than have them be 8192 by default. I've looked all over the place for this and it feels like a well kept secret.
Re: JASS Question
Posted: October 27th, 2008, 10:55 am
by Kibiyama
I don't know JASS, but if declarations are separate from initializations, I'd say it goes like this:
Code: Select all
globals
integer array A // A variable that can refer to any array of integers.
endglobals
...
A = new integer array[9] // Assign it to this specific array, of length 5.
Re: JASS Question
Posted: October 27th, 2008, 5:50 pm
by DarnYak
First, I assume you're using one of the jass language add on things. (is there even more then one?) Because in standard world editor, there can only be one global section and you basicly can't touch it.
Second, the actual size doesn't matter because WC3 arrays are all 8096 (2^14) in size.
And since there is no pointers or anything, you dont need to acutaly allocate it as kibi suggested
So, "integer array x" should suffice.
DarnYak
Re: JASS Question
Posted: October 27th, 2008, 8:56 pm
by Perhaps
I didn't realize globals, endglobals wasn't in normal editor. I knew struct, endstruct, method, endmethod weren't in normal. I'm using NewGen. I suppose public, private, constant, library, endlibrary, scope, and endscope aren't in normal either? >_>
If array variables are all 8192 in size no matter what, then why does the variable editor have it so you can set size, or even for the matter, why do you have to set a size if it doesn't matter? >_>
I like declaring variables via JASS not just because I don't have to goto the variable editor, but also because I don't have to do "udg_" when referencing to them. I can also declare them within scopes, libraries, and I think structures as well.
Re: JASS Question
Posted: October 28th, 2008, 9:43 am
by Kibiyama
I think structures as well.
Otherwise, that would sort of defeat the purpose of a struct, wouldn't it?
Re: JASS Question
Posted: October 28th, 2008, 4:07 pm
by Perhaps
I haven't seen globals declared yet in structures. >_>
I've seen...
library blah
globals
...
endglobals
struct blah
method blah takes blah returns blah
...
endmethod
endstruct
endlibrary
But not...
struct blah
globals
...
endglobals
method blah takes blah returns blah
...
endmethod
endstruct
But then again I haven't quite learned structures yet. -_-
Re: JASS Question
Posted: October 28th, 2008, 4:34 pm
by Kibiyama
You looked like you were talking about variables in general, not global variables. Having a global with class scope doesn't really make sense, since then it's not really a global.
I could see if they were using "globals" in a class to be an equivalent to "static" in other languages...
Re: JASS Question
Posted: October 28th, 2008, 10:40 pm
by DarnYak
If array variables are all 8192 in size no matter what, then why does the variable editor have it so you can set size, or even for the matter, why do you have to set a size if it doesn't matter? >_>
Because the editor initializes stuff automaticly up to the size of the array in the global editor, based on the default value you set. Most of the time, it just produces a bunch of loops on startup setting things to 0 (wc3 automaticly sets them to 0 anyway, so far as i've ever seen)
DarnYak
Re: JASS Question
Posted: November 7th, 2008, 10:03 pm
by Cokemonkey11
arrays in the globals block are simply declared as
Code: Select all
globals
integer array M
endglobals
the globals block is a vJass component yes, along with structs, libraries, methods, 2d arrays, text macros, private and public functions, etc.
In the latest pJass syntax checker (available in JNGP), globals can be defined anywhere, and private globals can even by defined within structs and libraries.
Hope this helps
