JASS Question

A place to talk about non-EotA-related topics.
Post Reply
Message
Author
User avatar
Perhaps
Retired
Retired
Posts: 811
Joined: September 14th, 2007, 1:24 am
Contact:

JASS Question

#1 Post 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.
Image

User avatar
Kibiyama
Addict
Addict
Posts: 268
Joined: August 20th, 2006, 7:52 pm
Location: In your base, killing your mans

Re: JASS Question

#2 Post 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.
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.

User avatar
DarnYak
Site Admin
Site Admin
Posts: 2364
Joined: August 12th, 2006, 2:54 pm

Re: JASS Question

#3 Post 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

User avatar
Perhaps
Retired
Retired
Posts: 811
Joined: September 14th, 2007, 1:24 am
Contact:

Re: JASS Question

#4 Post 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.
Image

User avatar
Kibiyama
Addict
Addict
Posts: 268
Joined: August 20th, 2006, 7:52 pm
Location: In your base, killing your mans

Re: JASS Question

#5 Post by Kibiyama »

I think structures as well.
Otherwise, that would sort of defeat the purpose of a struct, wouldn't it?
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.

User avatar
Perhaps
Retired
Retired
Posts: 811
Joined: September 14th, 2007, 1:24 am
Contact:

Re: JASS Question

#6 Post 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. -_-
Image

User avatar
Kibiyama
Addict
Addict
Posts: 268
Joined: August 20th, 2006, 7:52 pm
Location: In your base, killing your mans

Re: JASS Question

#7 Post 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...
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.

User avatar
DarnYak
Site Admin
Site Admin
Posts: 2364
Joined: August 12th, 2006, 2:54 pm

Re: JASS Question

#8 Post 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

User avatar
Cokemonkey11
Addict
Addict
Posts: 306
Joined: January 26th, 2008, 12:04 am
Realm: Lordaeron (U.S. West)
Battle.net name: Cokemonkey11

Re: JASS Question

#9 Post 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 :)
Image
I miss EotA :(

Post Reply