redefining sizes of dynamic arrays

Started by wynni2, Thu 22/03/2018 16:26:42

Previous topic - Next topic

wynni2

UPDATE - my apologies, after posting I reread the manual entry again, and it answered my question.

PLEASE DISREGARD. 

Hi all -

I've been looking at the manual and forums, but I can't find an answer to this question that makes sense at my (very basic) level. 

I'm writing a function that would generate a list containing multiple items (strings). 

Can I declare a dynamic array and then declare a new size for that array each time the function is called? 

This is what I'm thinking of:
Code: ags

String rstring[]; 

String MakeList(int howmanyitems) {
    rstring = new String[howmanyitems]; 
    String output = ""; 
    char i;  
    while (i<howmanyitems) {
        rstring[i] = ##SELECT FROM A PREEXISTING ARRAY#; 
        output = output.Append(rstring[i]); 
        i++; 
    }
    return output; 
}


I'd like to know if this is going to compile, or if I'm misusing dynamic arrays.

Thanks

SMF spam blocked by CleanTalk