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.
JASS Question
- Kibiyama
- Addict
- Posts: 268
- Joined: August 20th, 2006, 7:52 pm
- Location: In your base, killing your mans
Re: JASS Question
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.
98% of all people think Perhaps is a faggot. If you are in this 98%, put this in your sig.
Tehw00tz wrote:I miss my headset. This headset only covers two of my ears.
Re: JASS Question
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
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
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.
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.
- Kibiyama
- Addict
- Posts: 268
- Joined: August 20th, 2006, 7:52 pm
- Location: In your base, killing your mans
Re: JASS Question
Otherwise, that would sort of defeat the purpose of a struct, wouldn't it?I think structures as well.
98% of all people think Perhaps is a faggot. If you are in this 98%, put this in your sig.
Tehw00tz wrote:I miss my headset. This headset only covers two of my ears.
Re: JASS Question
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. -_-
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. -_-
- Kibiyama
- Addict
- Posts: 268
- Joined: August 20th, 2006, 7:52 pm
- Location: In your base, killing your mans
Re: JASS Question
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...
I could see if they were using "globals" in a class to be an equivalent to "static" in other languages...
98% of all people think Perhaps is a faggot. If you are in this 98%, put this in your sig.
Tehw00tz wrote:I miss my headset. This headset only covers two of my ears.
Re: JASS Question
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)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? >_>
DarnYak
- Cokemonkey11
- Addict
- Posts: 306
- Joined: January 26th, 2008, 12:04 am
- Realm: Lordaeron (U.S. West)
- Battle.net name: Cokemonkey11
Re: JASS Question
arrays in the globals block are simply declared as
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
Code: Select all
globals
integer array M
endglobals
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
I miss EotA