Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Superman95 on Mon 12/09/2005 02:31:40

Title: struct and multi-dim arrays
Post by: Superman95 on Mon 12/09/2005 02:31:40
Does the scripting language allow multi-dim arrays of user defined types?

I have this:

Fighters BattleFighters[MAX_FIGHTERS][MAX_ACTIONS];

but it doesn't work.  Is this unsupported or did i do something wrong?
Title: Re: struct and multi-dim arrays
Post by: monkey0506 on Mon 12/09/2005 02:40:59
No...unfortunately you can't have multidimensional arrays.

So,

Fighters BattleFighters[MAX_FIGHTERS * MAX_ACTIONS];

Should work, and then you can find the correct index with something like

int index = (FIGHTERS_INDEX * MAX_ACTIONS) + ACTIONS_INDEX;

[EDIT:]  Just to clarify, you can't have any multi-dimensional arrays at the moment.  So basically the format is:

TYPE NAME[a][c]...[n] becomes TYPE NAME[a * b * c * ... * n]

NAME[a_index][b_index][c_index]...[n_index] becomes (a_index * b * c * ... * n) + (b_index * c * ... * n) + (c_index * ... * n) + ... + n_index

Yeah, I think the math there is correct...I'm kind of preoccupied now though so it may not be...
Title: Re: struct and multi-dim arrays
Post by: Superman95 on Mon 12/09/2005 02:46:17
that sucks...what i really wanted was nested types, and this was an attempt to get around it.  It just keeps getting worse.  ::)
Title: Re: struct and multi-dim arrays
Post by: monkey0506 on Mon 12/09/2005 03:02:48
Big arrays aren't necessarily bad...as long as it's under 150000 total members you should be fine. :=  And if you're working with a beta version (I think beta 4+) then you can use the noloopcheck keyword as well...
Title: Re: struct and multi-dim arrays
Post by: strazer on Mon 12/09/2005 03:18:11
Technical Archive:
2D arrays (http://www.adventuregamestudio.co.uk/yabb/index.php?topic=6918.0)
3D arrays (http://www.adventuregamestudio.co.uk/yabb/index.php?topic=13897.0)

I also see no problem with this approach.
Title: Re: struct and multi-dim arrays
Post by: Superman95 on Mon 12/09/2005 03:28:12
Actually, that syntax doesn't work.

MAX_FIGHTERS * MAX_ACTIONS isn't allowed in the array statement.  you have to actually do another define with the result.
Title: Re: struct and multi-dim arrays
Post by: strazer on Mon 12/09/2005 03:37:45
True, that has bugged me too on occasion. Tracker entry (http://www.adventuregamestudio.co.uk/tracker.php?action=detail&id=500).
Title: Re: struct and multi-dim arrays
Post by: monkey0506 on Mon 12/09/2005 04:02:25
Well yes, I've experienced that error, but I'm glad that you figured out that by manually figuring out the value and using that instead it will work.

I was just typing up some code to give you the idea for how it works...and as for the math I did a much extended version of the algorithm which can be found on that 3D array page...but like I said it should work...
Title: Re: struct and multi-dim arrays
Post by: Superman95 on Tue 13/09/2005 02:21:02
grrrrr....i need nested types.  :'(
Title: Re: struct and multi-dim arrays
Post by: strazer on Tue 13/09/2005 02:56:50
That doesn't help.

Quote from: Pumaman on Tue 24/05/2005 19:19:11Yes, it's a possibility for a future version. However, I can't promise any timescales.