SRL Archive - OSR Help

Case statement help needed.


bud_wis_er_420

2012-01-01 15:12:08

I'm a little confused on how I would write a case statement for the procedure below. Instead of using an if statement over and over. Thanks for the help.

procedure Check_for_text;
begin

if(FindChatBoxText(Players[0].Nick, 8, clBlue))or
if(FindChatBoxText('hello', 8, clBlue))or
if(FindChatBoxText('Hello', 8, clBlue))or
if(FindChatBoxText('WC lvl', 8, clBlue))or
if(FindChatBoxText('bot', 8, clBlue))then
begin
Writeln('Texted Found')
end;

end;

PatDuffy

2012-01-01 15:14:55

Well I think there is a function that looks for multiple strings in the chatbox that would accomplish the same thing.

Home

2012-01-01 15:27:33

You should use TStringArray;
then Loop it through.

I will post example in a while, can't atm.

~Home

shnk

2012-01-01 15:31:36

i'm not sure but just get rid of all the ifs except the first one? i think there unnecessary and will cause syntax error
procedure Check_for_text;
begin

if(FindChatBoxText(Players[0].Nick, 8, clBlue))or
(FindChatBoxText('hello', 8, clBlue))or
(FindChatBoxText('Hello', 8, clBlue))or
(FindChatBoxText('WC lvl', 8, clBlue))or
(FindChatBoxText('bot', 8, clBlue))then
begin
Writeln('Texted Found')
end;

end;

Markus

2012-01-01 15:35:07

Simple loop:

procedure Check_for_text;
var i : integer;
searchme : TStringArray;
begin
searchme := [players[0].nick, 'hello', 'Hello', 'WC lvl', 'bot'];
for i := 0 to high(searchme) do
if(FindChatBoxText(searchme[i], 8, clBlue)then
begin
Writeln('Texted Found')
end;

end;
Also, may I suggest using Players[currentplayer].nick? Just makes for cleaner code and makes it way easier in case you decide to implement multiplayer.

bud_wis_er_420

2012-01-01 15:42:46

From: Home
You should use TStringArray;
then Loop it through.

I will post example in a while, can't atm.

~Home


Well the idea is to not call the slow if statement so many times, right? I read using the if statement so many times like this is bad scripting.

From: shnk
i'm not sure but just get rid of all the ifs except the first one? i think there unnecessary and will cause syntax error
procedure Check_for_text;
begin

if(FindChatBoxText(Players[0].Nick, 8, clBlue))or
(FindChatBoxText('hello', 8, clBlue))or
(FindChatBoxText('Hello', 8, clBlue))or
(FindChatBoxText('WC lvl', 8, clBlue))or
(FindChatBoxText('bot', 8, clBlue))then
begin
Writeln('Texted Found')
end;

end;


My bad, that was the code I ment to post. Was just in a hurry to post. But like I said above I don't think I should use so many if statements in a row.

From: PatDuffy
Well I think there is a function that looks for multiple strings in the chatbox that would accomplish the same thing.
What function is this?

I tried this but I didn't do something right.

program new;
{$i srl/srl.scar}
var
text :TStringArray;
begin
SetupSRL();
text := ['Hello', 'hello', 'bot', 'sup', 'wcing', 'fire']
if(FindChatBoxText(text, 8, clBlue))then
begin
Writeln('Texted Found')
end;
end.

Swatarianess

2012-01-01 16:29:37

From: bud_wis_er_420


program new;
{$i srl/srl.scar}
var
text :TStringArray;
begin
SetupSRL();
text := ['Hello', 'hello', 'bot', 'sup', 'wcing', 'fire']
if(FindChatBoxText(text, 8, clBlue))then
begin
Writeln('Texted Found')
end;
end.


The text variable is a TStringArray so it contains more than one string and in this code with;

If(FindChatBoxText(text,8,clblue)

You should probably have it as;

For I:= 0 to high(text) do
If(FindChatBoxText(text[I],8,clblue)) then
Begin
WriteLn('Found Text: ' + text[I]); // Reports on found text
end else
WriteLn('Text was not Found!'); // either goes here or after the other "end;"
End;

Just to explain what's going on abit
So this will go through all the strings in your array from the first string 'hello' through all the rest until the last string called 'fire'. It will Report what string it'd found by using the WriteLn(); function.



for I:=0 to high(text)
/\
This goes through all string in the given array from 0 (which is always the starting string,integer,Boolean etc. In a array! The high(text) finds the last integer,string,Boolean etc. That's what it does but what it means is that it gets the highest number hence the word high… This is a type of loop as it will cycle through whatever is in it as many times starting from "0" in this example to the number "5" as it counts up from "0" so that'd be the numbers;

0
1
2
3
4
5


There are 6 (integers which represent each value in the array). So to sum up it will go through each string looking for a similar one! Very helpful and time saving aswell as good for anti-ban and much more.

Ps. Sorry if the code I'd made doesn't work I haven't tested it and checked it :/ it mostly from memory a I'm not on Laptop :( any ques just post below or PM

~Bro433

bud_wis_er_420

2012-01-01 17:19:04

Awesome, thx very much. I understand now.

HardRockers

2012-01-01 17:57:37

Instead of starting another thread, I am going to ask my question here. I am trying to use a case statement to basically use the method that the botter chose.

Like I have the Constant Method= whatever

I want to use that Constant to determine which method it uses out of this case statement:


Case Method
1: Begin
repeat;
MineOre;
if (InvFull) Then
Begin
DropAll;
end;
ProgressReport;
Stats_Commit;
Until (false);
end;
2: Begin
repeat
MineOre;
If InvCount= PlusOne Then
DropOre;
ProgressReport;
Stats_Commit;
if(Invfull) Then
DropAll;
AntiBan;
Until (false);
end;
3: Begin
Repeat
Repeat
MineOre;
Until (InvFull);
WalkToBank;
Until (false);
End;
end

I have only seen cases with the use of Random() of I want it to be set. Is this even possible?