SRL Archive - Help and Support

Form Help


Blumblebee

2009-04-02 21:35:19

Ok, so I've been making a form for a script for a while now, and I'm having difficulties saving and loading player information, could someone help me? I can do it for one player, just once it gets into extensive arrays I have been having problems and I'm not really sure how to do it. Thank you. (Btw, the code is really messy and not very efficient, this is just a rough draft)

Form:

{.include SRL/SRL.scar}
var Panel: TPanel; Main: TMainMenu; Menu: array of array of TMenuItem; Names: array of TStringArray;
ScriptReady: Boolean; MainForm: TForm; Buttons: array [0..4] of TButton;
i, ii, e: Integer; CaptionA: Array Of String; Labels: Array [0..6] Of TLabel;
Edits: Array [0..3] Of TEdit; ComboBoxes: Array [0..1] Of TComboBox; List: TListbox;
MyPlayers: Array of TUser;

var ZenForm: TForm; Button: array [0..1] of TButton;Labeles: Array [0..5] Of TLabel;
Edit: Array [0..2] Of TEdit; ComboBox: Array [0..2] Of TComboBox;

var WorldNumber, LoadsToSleep: Integer; Members, UseSleep: Boolean;

const version = '1.0.prv';

Procedure SaveSettings; // For my options form only (FormB)
var Path: String;
begin
Path := AppPath+'Scripts\Form.ini';
WriteIni('Settings', 'SRLID', Edit[0].Text, Path);
WriteIni('Settings', 'SRLPW', Edit[1].Text, Path);
WriteIni('Settings', 'SmartWorld', Edit[2].Text, Path);
WriteIni('Settings', 'Sleep', ComboBox[2].Text, Path);
WriteIni('Settings', 'Load', ComboBox[1].Text, Path);
WriteIni('Settings', 'Member', ComboBox[0].Text, Path);
end;

Procedure LoadSettings; // For Options for Only (FormB)
var Path:String;
begin
Path := AppPath+'Scripts\Form.ini';
try
Edit[0].Text := ReadIni('Settings', 'SRLID', Path);
Edit[1].Text := ReadIni('Settings', 'SRLPW', Path);
Edit[2].Text := ReadIni('Settings', 'SmartWorld', Path);
ComboBox[2].Text := ReadIni('Settings', 'Sleep', Path);
ComboBox[0].Text := ReadIni('Settings', 'Member', Path);
ComboBox[1].Text := ReadIni('Settings', 'Load', Path);
except end;
end;

Procedure OptionClick(Sender: TObject);
begin
case Sender Of
Button[0]:
begin
SaveSettings;
try
SRLID := Edits[0].Text;
SRLPassword := Edits[1].Text;
Members := StrtoBool(ComboBoxes[0].Text);
WorldNumber := StrToInt(Edits[2].Text);
UseSleep := StrToBool(ComboBoxes[2].Text);
LoadsToSleep := StrToInt(ComboBoxes[1].Text);
except end;
ShowMessage('Current settings have been saved.');
end;
Button[1]:
begin
ZenForm.ModalResult:= mrOk;
end;
end;
end;

Procedure InitFormB;
begin
ZenForm := CreateForm;
with ZenForm do
begin
Position := poDesktopCenter;
Width := 200;
Height := 330;
BorderStyle := BSToolWindow;
Caption := 'Options';
Color := ClWhite;
Font.Color := ClBlack;
end;
CaptionA := ['Save Settings', 'Exit'];
for I := 0 to 1 do
begin
Button[i] := TButton.Create(ZenForm);
Button[i].Parent := ZenForm;
Button[i].Height := 20;
Button[i].OnClick := @OptionClick;
Button[i].Caption := CaptionA[i];
case I of
0..1:
begin
Button[i].Left := 45;
Button[i].Top := 250 + I * 30;
Button[i].Width := 100;
end;
end;
end;
CaptionA := ['SRL ID', 'SRL Pass', 'Smart World', 'Sleep?', 'Members?', 'Loads'];
for I := 0 to 5 do
begin
Labeles[i] := TLabel.Create(ZenForm);
Labeles[i].Parent := ZenForm;
Labeles[i].Caption := CaptionA[i];
case I of
0..5:
begin
Labeles[i].Top := 50 + 30 * I;
Labeles[i].Left := 10;
end;
end;
end;
for I := 0 to 2 do
begin
Edit[i] := TEdit.Create(ZenForm);
Edit[i].Parent := ZenForm;
Edit[i].Width := 100;
Edit[i].Height := 20;
case I of
0..2:
begin
Edit[i].Left := 80;
Edit[i].Top := 50 + 30 * I;
end;
end;
end;
for I := 0 to 2 do
begin
ComboBox[i] := TComboBox.Create(ZenForm);
ComboBox[i].Parent := ZenForm;
ComboBox[i].width := 100;
ComboBox[i].Height := 20;
case i of
0..1:
begin
ComboBox[i].Left := 80;
ComboBox[i].Top := 170 + 30 * I;
end;
0..2:
begin
ComboBox[i].Left := 80;
ComboBox[i].Top := 140;
end;
end;
end;
ComboBox[1].Items.Add('8');
ComboBox[1].Items.Add('9');
ComboBox[1].Items.Add('10');
ComboBox[1].Items.Add('11');
ComboBox[1].Items.Add('12');
ComboBox[0].Items.Add('True');
ComboBox[0].Items.Add('False');
ComboBox[2].Items.Add('True');
ComboBox[2].Items.Add('False');
LoadSettings;
end;

Procedure SafeInitFormB;
var v: TVariantArray;
begin
SetArrayLength(V, 0);
ThreadSafeCall('InitFormB', v);
end;

Procedure ShowFormModalB;
begin
ZenForm.ShowModal;
end;

Procedure SafeShowFormModalB;
var v: TVariantArray;
begin
setarraylength(V, 0);
ThreadSafeCall('ShowFormModalB', v);
end;

Procedure ShowPlayerFormB;
begin
SafeInitFormB;
SafeShowFormModalB;
end;

Procedure SetMyPlayerLength(Number: Integer);
var I: Integer; ManyPlayers: Integer;
begin
SetLength(MyPlayers, Number);
ManyPlayers := Number;
for i := 0 to Length(MyPlayers) - 1 do
begin
SetLength(MyPlayers[i].Booleans, 1);
end;
end;

Procedure CopyPlayers;
var i: Integer;
begin
NumberOfPlayers(Length(MyPlayers));
for i := 0 to High(MyPlayers) do
begin
Players[i] := MyPlayers[i];
end;
SetMyPlayerLength(Length(MyPlayers) + 1);
end;

procedure AddPlayerHandle;
var
i: Integer;
begin
for i := 0 to High(MyPlayers) do
if (MyPlayers[i].Name = Edits[0].Text) then
begin
ShowMessage('There is already a Player with this Username.');
Exit;
end;
i := High(MyPlayers);
try
MyPlayers[i].Name := Edits[0].Text;
MyPlayers[i].Pass := Edits[1].Text;
MyPlayers[i].Nick := Edits[2].Text;
MyPlayers[i].Active := True;
MyPlayers[i].Booleans[0] := StrtoBool(ComboBoxes[0].Text);
List.Items.add(Edits[0].Text);
except
WriteLn('Fill out the form properly');
end;
Inc(HowManyPlayers);
CopyPlayers;
end;

Procedure GetPlayer;
begin
Edits[0].Text := MyPlayers[List.ItemIndex].Name
Edits[1].Text := MyPlayers[List.ItemIndex].Pass
Edits[2].Text := MyPlayers[List.ItemIndex].Nick
ComboBoxes[0].Text := BooltoStr(MyPlayers[List.ItemIndex].Booleans[0]);
end;

Procedure DeletePlayer;
begin
if (Length(MyPlayers) > 1) then
SetMyPlayerLength(Length(MyPlayers) - 1);
end;

Procedure OnButtonClick(Sender: TObject);
begin
case sender of
Buttons[0]:
begin
ScriptReady := True;
MainForm.ModalResult:= mrOk;
end;
Buttons[1]:
begin
ScriptReady := False;
MainForm.ModalResult:= mrOk;
end;
Buttons[2]:
begin
AddPlayerHandle;
for i := 0 to High(Edits) do
Edits[i].Clear;
end;
Buttons[3]:
begin
case GetApplication.MessageBox('Are you sure you want to delete this player?', 'Delete Player', 1) of
MrOK:
begin
DeletePlayer;
List.Items.Delete(List.ItemIndex);
for i := 0 to High(Edits) do
Edits[i].Clear;
ShowMessage('Player has been deleted');
end;
end;
end;
Buttons[4]:
begin
case GetApplication.MessageBox('Do you wish to save the current settings?', 'Save', 1) of
MrOK:
begin
if (Edits[0].Text <> '') then List.Items.Append(Edits[0].Text);
ShowMessage('Settings Saved to a .ini file.');
end;
end;
end;
List: GetPlayer;
end;
end;

Procedure MenuClick(Sender: TObject);
begin
case sender of
Menu[0][1]:
begin
case GetApplication.MessageBox('Would you Like to save the current settings?', 'Save', 3) of
MrYes:
begin
end;
MrNo:
begin
end;
end;
end;
Menu[0][2]:
begin
case GetApplication.MessageBox('Do you wish to save the current settings?', 'Save', 1) of
MrOK:
begin
end;
end;
end;
Menu[0][3]:
begin
ScriptReady := False;
MainForm.ModalResult:= mrOk;
end;
Menu[1][1]: OpenWebPage('http://www.villavu.com/forum/index.php');
Menu[1][2]: OpenWebPage('http://www.villavu.com/forum/member.php?u=8349');
Menu[1][3]: OpenWebPage('http://www.villavu.com/forum/showthread.php?t=17890&highlight=how+to+install+srl');
Menu[1][4]: OpenWebPage('http://www.villavu.com/forum/showthread.php?t=39031');
Menu[2][1]:
begin
ShowPlayerFormB;
end;
Menu[3][1]:
begin
end;
Menu[3][2]:
begin
end;
Menu[3][3]: GetApplication.MessageBox(' Blumblebees ZenCrafter'+Version
+#10+' Type: AirCrafter'+#10+' Date Released:'+#10+' April, 9, 2009'
+#10+' SCAR REV: 3.20 RC3 '+#10+' SRL Rev: #32'+#10+' Author: Blumblebee', 'About', 0)
end;
end;

Procedure InitForm;
begin
MainForm := CreateForm;
with MainForm do
begin
Position := poScreenCenter;
Left := 100;
Top := 100;
Width := 550;
Height := 325;
BorderStyle := BSToolWindow;
Autoscroll := false;
Caption := 'ZenCrafter'+version;
Color := clBtnFace;
Font.Color := ClBlack;
end;
try
SetArrayLength(Names, 4);
Names[0] := ['File', 'New', 'Save', 'Exit'];
Names[1] := ['Links', 'Villavu', 'About me', 'SRL Download', 'ZenCrafter Thread'];
Names[2] := ['Options', 'Options'];
Names[3] := ['Help', 'Help', 'Manual', 'About'];
SetArrayLength(Menu, GetArrayLength(names));
Main := TMainMenu.Create(MainForm);
for ii := 0 to high(names) do
begin
SetArrayLength(Menu[ii], GetArrayLength(Names[ii]));
for e := 0 to high(names[ii]) do
begin
Menu[ii][e] := TMenuItem.Create(MainForm);
Menu[ii][e].Caption := Names[ii][e];
if e = 0 then
Main.Items.Add(Menu[ii][e])
else
Main.Items.Items[ii].add(Menu[ii][e]);
Menu[ii][e].OnClick := @MenuClick;
end;
end;
except end;
List := TListBox.Create(MainForm);
with List do
begin
Parent := MainForm;
Left := 400;
Top := 50;
Width := 100;
Height := 200;
OnClick := @OnButtonClick;
end;
Panel := Tpanel.Create(MainForm);
with panel do
begin
Parent := MainForm;
Left := 25;
Top := 190;
Width := 325;
Height := 75;
end;
CaptionA := ['Start Script', 'Exit Form', 'New Player', 'Delete Player','Save Player'];
for I := 0 to 4 do
begin
Buttons[i] := TButton.Create(MainForm);
Buttons[i].Height := 20;
Buttons[i].OnClick := @OnButtonClick;
Buttons[i].Caption := CaptionA[i];
case I of
0..1:
begin
Buttons[i].Parent := Panel;
Buttons[i].Left := 15;
Buttons[i].Top := 10 + I * 30;
Buttons[i].Width := 100;
end;
2..4:
begin
Buttons[i].Parent := MainForm;
Buttons[i].Left := 200;
Buttons[i].Top := 10 + I * 30;
Buttons[i].Width := 100;
end;
end;
end;
CaptionA := ['Username', 'Password', 'Nick', 'Tiara', 'Members?', 'Smart World', 'Player List'];
for I := 0 to 6 do
begin
Labels[i] := TLabel.Create(MainForm);
Labels[i].Caption := CaptionA[i];
case I of
0..3:
begin
Labels[i].Parent := MainForm;
Labels[i].Top := 50 + 30 * I;
Labels[i].Left := 10;
end;
4:
begin
Labels[i].Parent := Panel;
Labels[i].Top := 45;
Labels[i].Left := 130;
end;
5:
begin
Labels[i].Parent := Panel;
Labels[i].Top := 15;
Labels[i].Left := 130;
end;
6:
begin
Labels[i].Parent := MainForm;
Labels[i].Top := 25;
Labels[i].Left := 400;
end;
end;
end;
for I := 0 to 3 do
begin
Edits[i] := TEdit.Create(MainForm);
Edits[i].Width := 100;
Edits[i].Height := 20;
case I of
0..2:
begin
Edits[i].Parent := MainForm;
Edits[i].Left := 80;
Edits[i].Top := 50 + 30 * I;
end;
3:
begin
Edits[i].Parent := Panel;
Edits[i].Left := 200;
Edits[i].Top := 10;
end;
end;
end;
for I := 0 to 1 do
begin
ComboBoxes[i] := TComboBox.Create(MainForm);
ComboBoxes[i].width := 100;
ComboBoxes[i].Height := 20;
case i of
0:
begin
ComboBoxes[i].Parent := MainForm;
ComboBoxes[i].Left := 80;
ComboBoxes[i].Top := 140;
end;
1:
begin
ComboBoxes[i].Parent := Panel;
ComboBoxes[i].Left := 200;
ComboBoxes[i].Top := 40;
ComboBoxes[i].Text := 'False';
end;
end;
end;
ComboBoxes[1].Items.Add('True');
ComboBoxes[1].Items.Add('False');
ComboBoxes[0].Items.Add('True');
ComboBoxes[0].Items.Add('False');
end;

Procedure SafeInitForm;
var v: TVariantArray;
begin
SetArrayLength(V, 0);
ThreadSafeCall('InitForm', v);
end;

Procedure ShowFormModal;
begin
MainForm.ShowModal;
end;

Procedure SafeShowFormModal;
var v: TVariantArray;
begin
setarraylength(V, 0);
ThreadSafeCall('ShowFormModal', v);
end;

Procedure ShowPlayerForm;
begin
try
GetSelf.WindowState := wsMinimized;
SafeInitForm;
SafeShowFormModal;
if not ScriptReady then
begin
GetSelf.WindowState := wsMaximized;
TerminateScript;
end;
finally
begin
GetSelf.WindowState := wsMaximized;
FreeForm(MainForm);
end;
except
end;
end;

begin
SetUpSRL;
SetMyPlayerLength(1);
ShowPlayerForm;
end.

any help is appreciated

Nava2

2009-04-06 18:32:42

Look at my abyssal crafters form… might help? :)

Or my Mirror fight, it has some crazy ini shit. :p

Quickmarch

2009-04-07 05:13:31

Use loops to save and load your players. There are forms in two of my scripts if you need any help. :)