struct and multi-dim arrays

Started by Superman95, Mon 12/09/2005 02:31:40

Previous topic - Next topic

Superman95

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?

monkey0506

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

Superman95

that sucks...what i really wanted was nested types, and this was an attempt to get around it.  It just keeps getting worse.  ::)

monkey0506

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

strazer

Technical Archive:
2D arrays
3D arrays

I also see no problem with this approach.

Superman95

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.

strazer

True, that has bugged me too on occasion. Tracker entry.

monkey0506

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

Superman95

grrrrr....i need nested types.  :'(

strazer

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.

SMF spam blocked by CleanTalk