YES! It's time we actually make the big major procedure! Procedure LoadFP();! This is the place where all your player info gets loaded, and saved into the FP array. And most important of all, here will all your stuff get visualized!
What this procedure is going to do is:
- Save your player info form your latest edit
- Load the players info of the player you want to edit now
- Show in the listbox all your players
- Show all the players data in the form for the current player (CurFP)
This procedure is the key to everything in your code.
So the first thing we are going to do, is create the new form procedure: (make sure you create it above the ItemClicked procedure)
Procedure LoadFP(WhatPlayer: Integer; SaveCurrentInfo: Boolean);
As you can see I have added 2 variables in the procedure. WhatPlayer; this is the integer the script need of wish player it has to load this time. SaveCurrentInfo; Does the script want to save the info of the player wish is currently displayed.
When you have created this procedure you'll see that your script has no errors anymore
And that makes it time to make the procedure actually do something.
The first thing the scripts need to do, is to save the current player, before we change all the boxes, else it won't saved correctly, or just not saved at all. We start with the following code:
If SaveCurrentInfo Then
FP[CurFP].Name := Edits.Text;
FP[CurFP].Pass := Edits.Text;
FP[CurFP].Nick := Edits.Text;
FP[CurFP].Pin := Edits.Text;
FP[CurFP].Loads := ComboBoxes.Text;
FP[CurFP].Active := ComboBoxes.Text;
Now we are sure new player info has been saved and we can start loading an other player! The first thing I would like to do is giving the TListBox an update, so users can overview there players when changes are made. We do that by first clearing the box, and then loading the player list in again:
I: Integer; // add this at the top of the procedure!
// add this below the save player (in LoadFP)
For I := 0 To High(FP) Do
If (FP[I].Name = '') Then
PlayerList.Items.Add(IntToStr(I) + ': ?')
PlayerList.Items.Add(IntToStr(I) + ': ' + FP[I].Name);
That will show a clear list of your players, numbered and players without a name yet will get a "?".
The next step in LoadFP is that we need to load in the player we want to see now. We will fill the Edits and ComboBoxes up with the new CurFP:
* Here we highlight the new CurFP in the listbox
CurFP := WhatPlayer;
PlayerList.ItemIndex := CurFP; // *
Edits.Text := FP[CurFP].Name;
Edits.Text := FP[CurFP].Pass;
Edits.Text := FP[CurFP].Nick;
Edits.Text := FP[CurFP].Pin;
ComboBoxes.Text := FP[CurFP].Loads;
ComboBoxes.Text := FP[CurFP].Active;
The last, but also very important thing, is to disable the "delete player" button, when there are less then 2 players. This is to prevent out of range errors, because you can't delete players if they don't exist. We will make a check like this:
Buttons.Enabled := (GetArrayLength(FP) > 1);
That line might look a bit weird, but this is what it does: When there is more then 1 form player, it will enable the delete button, if there is only one, it will disable it.
Congrats! LoadFP should be done for now! But you might have noticed, when you click the "add player" button you have 2 players? That's correct, because you already had one when you loaded the form, but you didn't see it yet. To fix this you'll have to add this at the bottom of your InitForm; procedure: