- Joined
- Aug 7, 2013
- Messages
- 1,338
Hi,
Can we declare an array of some struct?
struct t
endstruct
t array struct_array[5]
Can we declare an array of some struct?
struct t
endstruct
t array struct_array[5]
local t array var
local integer array var
myStruct array s
.
.
.
struct myStruct
endstruct
struct myStruct
endstruct
.
.
.
myStruct array S
But if I make an array of some struct, how do I ensure that the array is declared AFTER the struct is declared?
e.g. if I try to initialize an array of some struct which doesn't exist yet, shouldn't I get an error?
type
orrequires
keywords.type SomeStruct extends integer
globals
SomeStruct var
endglobals
struct SomeStruct
endstruct
library other requires lib
globals
SomeStruct var
endglobals
endlibrary
library lib
struct SomeStruct
endstruct
endlibrary
If I have a chain of dependent structs though will it not get a bit annoying to read all the require statements?
type somestruct extends integer
Then usetype somestruct extends integer
globals
integer array FS_result_t2[79]
integer array FS_result_t3[79]
integer array FS_result_sp[MAX_SP_FUSIONS]
integer array FS_req1_sp[MAX_SP_FUSIONS]
integer array FS_req2_sp[MAX_SP_FUSIONS]
integer array FS_fl_sp[MAX_SP_FUSIONS]
.
.
.
.
endglobals
JASS_MAX_ARRAY_SIZE
(8191)struct Test
unit u
endstruct
local unit u
call KillUnit(u)
call BJDebugMsg("This message won't display.")
Struct members are internally global arrays, so that determines what their initial values are. The internal code won't initialize it to anything unless you write it out. For example:
When you call Test.create(), it won't set u to anything at all. By default, it will return null because global arrays default to null.JASS:struct Test unit u endstruct
For integers, they default to 0. For booleans, they default to false. I don't remember whether strings refer to "" or null.
Note that this is only true for arrays (struct members are internally arrays, so that is why it is fine). If you have a local variable or a global variable, they count as uninitialized (unless you give them a value to point to):
JASS:local unit u call KillUnit(u) call BJDebugMsg("This message won't display.")
struct myStruct A
endstruct
...
globals
myStruct array s
endglobals
//are all the members of s initialized to 0 or null?
s[0] == 0 //returns true?
s[0] == null //returns true?
Thank you. That makes perfect sense.
But if I make an array of some struct, how do I ensure that the array is declared AFTER the struct is declared?
e.g. if I try to initialize an array of some struct which doesn't exist yet, shouldn't I get an error?
Can structs have arrays as members? I read in the manual which comes with jass gen pack that array members are not supported yet...
JASS:myStruct array s . . . struct myStruct endstruct
should given an error, but
JASS:struct myStruct endstruct . . . myStruct array S
should be ok?
Thanks you again--sorry but had a quick question on a point you made, that you can't declare sizes of arrays in JASS. If that is true, I am wondering why the previous developer had this code:
JASS:globals integer array FS_result_t2[79] integer array FS_result_t3[79] integer array FS_result_sp[MAX_SP_FUSIONS] integer array FS_req1_sp[MAX_SP_FUSIONS] integer array FS_req2_sp[MAX_SP_FUSIONS] integer array FS_fl_sp[MAX_SP_FUSIONS] . . . . endglobals
You can use thetype
orrequires
keywords.
JASS:type SomeStruct extends integer globals SomeStruct var endglobals struct SomeStruct endstruct
JASS:library other requires lib globals SomeStruct var endglobals endlibrary library lib struct SomeStruct endstruct endlibrary
Then usetype somestruct extends integer
keyword MyStruct
. public
/private
modifiers are allowed.library
and requires
but not for simple things as struct-decleration.