Oort Posted June 27, 2016 Share Posted June 27, 2016 (edited) I have several list boxes created that each represent a slot in a formation to hold a hero. Pull down the list, select the hero, once the formation is filled out, hit the "play" button and go back to the game script. My problem is getting the list of heroes that were selected transferred back to the main program. I've tried creating a TStrArray and then going through each ComboBox.text and pulling out the hero that may be placed there and copying it to the TStrArray, however I keep getting an Out of Range crash so I know I'm missing something here. To start I have my Dropdown box where the names are in the text field, and the array I want to save them to. varHeroSlot: array[1..24] of TComboBox;HeroList : TStrArray After all the formation slots that can be used are filled the Play button becomes active and I call this routine when it is pressed (this is located in the form portion): Function TotalHeroes(FormationSlots:integer):integer; begin Case FormationSlots of 1: Result := 10; 2: Result := 9; 3: Result := 13; 4: Result := 11; 5: Result := 12; 6: Result := 14; end; end;Procedure SaveHeroes(Sender: TObject);var count,count2 : integer; Begin count2 := 0; SetArrayLength(Herolist,totalheroes(formation)); // <-- This sets the Array Length to how many For count := 1 to 24 do // slots are used in a formation begin If heroslot[count].text <> ' slot' then // <-- This identifies slots that are empty begin herolist[count2] := heroslot[count].text; // <-- Here is where the program always crashes count2 := count2 + 1; end; end; end; Been trying to figure this one out for a few days now and just not having any luck. What obvious mistake am I making this time? Edited June 27, 2016 by Oort Quote Link to comment Share on other sites More sharing options...
Wanted Posted June 30, 2016 Share Posted June 30, 2016 Out of range means you're calling an index of an array that isn't there. You should probably avoid making any arrays that don't start at 0 and also remember that count is always 1 higher than the final index (for 0...n-th arrays) Quote Link to comment Share on other sites More sharing options...
Oort Posted June 30, 2016 Author Share Posted June 30, 2016 Thanks man. Turns out it was a stupid bit of bad coding causing it. I was looking for ' slot' as an indicator for an empty formation slot, but I had also default all the slots to 'Empty' at start up. Long story short I was doing things right with the arrays, and your help made me realize that it should have worked which got me to finally stumble onto the real problem. I knew it was gonna be something stupid Quote Link to comment Share on other sites More sharing options...
Wanted Posted July 6, 2016 Share Posted July 6, 2016 What is this script you're making going to do? Quote Link to comment Share on other sites More sharing options...