| View previous topic :: View next topic |
| Author |
Message |
HomerSexual Grandmaster Cheater Supreme
Reputation: 5
Joined: 03 Feb 2007 Posts: 1657
|
Posted: Thu Jul 12, 2007 10:45 am Post subject: Problem |
|
|
| Code: | unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6:
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
Current := 'Current Location: ';
Location := 1;
//LocArray Declaration
LocArray[0] := 'Merdoth Town';
LocArray[1] := 'Dark Swamp';
LocArray[2] := 'Ergoth Mountains';
LocArray[3] := 'Gremlor Mines';
LocArray[4] := 'Haplor Docks';
//MonArray Declaration
MonArray[0] := 'Bandit';
MonArray[1] := 'Small Poison Frog';
MonArray[2] := 'Huge Poison Frog';
MonArray[3] := '';
if(Location = 1) then
begin
ListBox1.Items.Add('Dark Swamp');
ListBox1.Items.Add('Ergoth Mountains');
ListBox1.Items.Add('Gremlor Mines');
ListBox1.Items.Add('Haplor Docks');
end;
end;
procedure TForm1.ListBox1Click(Sender: TObject);
begin
if(Location = 1) then
begin
if(ListBox1.Items.Strings[ListBox1.ItemIndex] = LocArray[1]) then
begin
Label11.Caption := Current + LocArray[1];
Location := 2;
end;
if(ListBox1.Items.Strings[ListBox1.ItemIndex] = LocArray[2]) then
Label11.Caption := Current + LocArray[2];
Location := 3;
if(ListBox1.Items.Strings[ListBox1.ItemIndex] = LocArray[3]) then
Label11.Caption := Current + LocArray[3];
Location := 4;
if(ListBox1.Items.Strings[ListBox1.ItemIndex] = LocArray[4]) then
Label11.Caption := Current + LocArray[4];
Location := 5;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Memo2.Lines.Add(IntToStr(Location));
if(Location = 1) then
begin
Memo2.Lines.Clear;
Memo2.Lines.Add('You are in town silly, you cant fight here.');
end;
if(Location = 2) then
begin
Memo2.Lines.Clear;
Memo2.Lines.Add('Fight Bandit'); //This is just here to test out the if
end;
end;
end.
|
when i run this code and click on fight monster after clicking on Dark Swamp in the Listbox1 it wont run the if.
it sets the Location to 5 if i click anything in ListBox1 even though it should only set to 5 for Haplor Docks.
Am i making any sense?
i want Location to set to the right value
_________________
|
|
| Back to top |
|
 |
appalsap Moderator
Reputation: 0
Joined: 27 Apr 2006 Posts: 6753 Location: Pakistan
|
Posted: Thu Jul 12, 2007 11:21 am Post subject: |
|
|
not sure about location but there's a way you could shorten your code:
| Code: |
procedure TForm1.FormCreate(Sender: TObject);
const
LocArray : array[0..4] of string = ('Merdoth Town', 'Dark Swamp',
'Ergoth Mountains', 'Gremlar Mines', 'Haplor Docks');
begin
...
|
|
|
| Back to top |
|
 |
HomerSexual Grandmaster Cheater Supreme
Reputation: 5
Joined: 03 Feb 2007 Posts: 1657
|
Posted: Thu Jul 12, 2007 11:29 am Post subject: |
|
|
ok thanks i shortened both arrays but did it out of a procedure in the form var area
anyone help with Location?
_________________
|
|
| Back to top |
|
 |
Dark Byte Site Admin
Reputation: 471
Joined: 09 May 2003 Posts: 25815 Location: The netherlands
|
Posted: Thu Jul 12, 2007 12:08 pm Post subject: |
|
|
in the ListBox1Click put the code after if's between a begin and end
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
| Back to top |
|
 |
|