SRL Archive - OSR Help

Or Statement


Sk1nyNerd

2013-10-22 20:39:44

how do you properly use the or statement in this situation, i cant seem to find my way through it

I am checking to see if the Text in the Combobox matches what it needs to match in order for the script to work. Its a failsafe

The below code works for checking the text of one of the Options but i have multiple Options that could be a possibility i need to check for. for example if the text is not 'Man' 'Woman' 'Spider' 'Vampire' 'Billy Bob' then i want to display the message to pick a valid Npc

                  
if(not(Comboboxes[0].Text = 'Man')) then
begin
ShowMessage('Please choose a valid NPC.');
Exit;
end;

thanks

Ian

2013-10-22 21:09:15

From: ibot_dung11
how do you properly use the or statement in this situation, i cant seem to find my way through it

I am checking to see if the Text in the Combobox matches what it needs to match in order for the script to work. Its a failsafe

The below code works for checking the text of one of the Options but i have multiple Options that could be a possibility i need to check for. for example if the text is not 'Man' 'Woman' 'Spider' 'Vampire' 'Billy Bob' then i want to display the message to pick a valid Npc

                  
if(not(Comboboxes[0].Text = 'Man')) then
begin
ShowMessage('Please choose a valid NPC.');
Exit;
end;

thanks


I think this is what you're looking for:

if(not((Comboboxes[0].Text = 'Man') or (Comboboxes[0].Text = 'Woman') or (Comboboxes[0].Text = 'Spider'))) then
begin
ShowMessage('Please choose a valid NPC.');
Exit;
end;

Also if I remember correctly comboboxes have a set list to choose from, so you could make a default option called 'Monster' and then do

if (Comboboxes[0].Text = 'Monster') then
begin
ShowMessage('Please choose a valid NPC.');
Exit;
end;

Sk1nyNerd

2013-10-22 22:48:32

From: BMWxi
I think this is what you're looking for:

if(not((Comboboxes[0].Text = 'Man') or (Comboboxes[0].Text = 'Woman') or (Comboboxes[0].Text = 'Spider'))) then
begin
ShowMessage('Please choose a valid NPC.');
Exit;
end;


nice, it works. i only had 1 parenthesis after the not when i tried it that way:P. any idea how to make the default list? cause the next one i have over 10 options to pick from ha

*i guess ive +1ed ur rep to much so it wont let me haha thanks

Ian

2013-10-22 23:21:25

From: ibot_dung11
any idea how to make the default list? cause the next one i have over 10 options to pick from ha


This is from my boot crafter (outdated now, was for srl5/ascalscript)

ComboBox:= TComboBox.Create(settingsForm);
ComboBox.Parent:= settingsForm;
ComboBox.Left:= 270;
ComboBox.Top:= 108;
ComboBox.Width:= 110;
ComboBox.Style:= csDropDownList;
ComboBox.Items.Add('Duel Arena');
ComboBox.Items.Add('Gamer''s Grotto');
ComboBox.Items.Add('Burthorpe');
ComboBox.Items.Add('Falador West');
ComboBox.Items.Add('Varrock East');
ComboBox.Items.Add('Varrock West');
ComboBox.Items.Add('Draynor');
ComboBox.Items.Add('Lumbridge');
ComboBox.ItemIndex:= 0;

The 'Duel Arena' option would be the default.

Sk1nyNerd

2013-10-22 23:49:50

From: BMWxi

ComboBox.Style:= csDropDownList;


thats the part i needed! :D

i didnt have that so it let you type inside the combo box. now i dont need to make the failsafe and 50 or statements whoop whoop

thanks man:)

Mark

2013-10-23 07:54:05

I'm a fan of using the case statement

Case ComboBox.index of
'Man':code for if man selected
'Blah':blah blah
'None':default in none selected
End;
To set a default ComboBox.Caption:= 'None';

Short and brief hope you understand.
If not hit me up on this thread i will be more than willing to help.

bg5

2013-10-23 10:59:23

In such situation just make custom function:
program new;

function IsStrOnList (s:string; list:TstringArray) :boolean;
var h,i:integer;
begin
h := High(list);
for i:=0 to h do
if s = list[i] then
begin
Result := TRUE;
exit;
end;
end;

begin
if not IsStrOnList('blah blah',['NPC','Monster','Women','Man']) then
ShowMessage('Please choose a valid NPC.');
end.

Sk1nyNerd

2013-10-23 12:16:09

From: bg5
In such situation just make custom function:
program new;

function IsStrOnList (s:string; list:TstringArray) :boolean;
var h,i:integer;
begin
h := High(list);
for i:=0 to h do
if s = list[i] then
begin
Result := TRUE;
exit;
end;
end;

begin
if not IsStrOnList('blah blah',['NPC','Monster','Women','Man']) then
ShowMessage('Please choose a valid NPC.');
end.


nice thanks! what I was originally looking for but bmwxi gave a line to avoid it. saved for future use tho:P

Sk1nyNerd

2013-10-25 21:34:14

anyone know how to make it so the user can only type integers in a text box? that way they cant enter like 56bk for their bank pin or some similiar situation

thanks