Dynamic Array of Struct?

Started by Ryan Timothy B, Fri 06/05/2011 17:00:54

Previous topic - Next topic

Ryan Timothy B

I could've sworn you can make a dynamic struct array? I'm 90% certain I had done it before.

Code: ags

struct sTest {
  Character *theCharacter;
};
sTest test[];

function game_start() 
{ 
  test = new sTest[Game.CharacterCount];
}


Results in the error: cannot create dynamic array of unmanaged struct

Khris

http://www.adventuregamestudio.co.uk/manual/DynamicArrays.htm  ;D

QuoteAlso, at present you can create arrays of basic types (int, char, etc) and of built-in types (String, Character, etc) but not of custom structs.

Ryan Timothy B

#2
I did read that part in the manual. But like I said.. I was 90% certain I had done it before because of a thread I made about how I couldn't use Game.InventoryItemCount to define the indexes in an array struct. But then ended up figuring it out... Or maybe I found another solution. Now I'm trying to remember what it was that I did (this was a year ago. lol).

Oh well. Maybe I'm remembering wrong.

Ryan Timothy B

Oi. I think I remember what I had done.

I Defined a value that was equal to the amount of InventoryItems, and on GameStart I had it check whether Game.InventoryItemCount was equal to the Defined value. If it wasn't, I aborted the game.

It was much better than an unfriendly crashing glitch or having an array with an arbitrary value of 1000 or something.

monkey0506

An alternative would be to use dynamic arrays outside of the struct and simply use a struct interface (specifically, struct functions) for getting/setting the items you need. I've essentially done this in my Verbcoin module which also uses the unsupported concept of indexers..but the official word would probably be that I shouldn't be using attributes like that, so I won't recommend doing that. Anyway, managing dynamic arrays that are associated with a struct yet exist outside of said struct is messy business, so it's debatable whether you would want to do that either.

JoelCBarker

Sorry to bump something four years old, but this seems like the spot to ask my question.

In my global script I declare a normal array, then in my global script header I define it as a struct of integers. That works fine as a fixed struct array (different room scripts assign values to the integers depending on the player's current room)...

...but now I want to make it a dynamic array whose size and values are reassigned by each room. I could declare a different fixed struct array in each room, but I was really hoping I could keep the info it stores in my global script so I can export and use it in other scripts. I can't use global variables because the size of the array ranges from 400 to 6400.

I just want a struct array whose size can be changed by each room, without losing the ability to use its values in other scripts or a workaround.

Quote from: monkey_05_06 on Fri 06/05/2011 19:50:14
use dynamic arrays outside of the struct and simply use a struct interface (specifically, struct functions) for getting/setting the items you need

the contents of the array are character values being parsed from strings, so during parsing I would store each value one at a time in a global variable and then (?)pass it(?) to a dynamic array within my global script?

I hope that makes sense, I'm really tired and I can barely remember what problem I had in the first place. Cannot create dynamic array of unmanaged struct.

Thanks!

Monsieur OUXX

Quote from: monkey_05_06 on Fri 06/05/2011 19:50:14
An alternative would be to use dynamic arrays outside of the struct and simply use a struct interface (specifically, struct functions) for getting/setting the items you need.

Yes, it's the closest thing you have to an array of structs.
 

JoelCBarker

I slept on it and changed my approach, there wasn't a real need for it but at the time I thought it might be a tidier way to do it. Thanks for responding however :-D

SMF spam blocked by CleanTalk