SRL Archive - Help

How to use cases in this instance?


rj

2012-12-11 19:32:35

In my script the user name pick the monster they want to kill by editing

MONSTER_KILL = ('ghost');  

And based off what they enter this procedure directs it to other procedure

procedure Chooseproc;
begin
if MONSTER_KILL = ('ghost') then
begin
ClickGhost;
end;
if MONSTER_KILL = ('skeleton') then
begin
Clickskeleton;
end;
if MONSTER_KILL = ('bat') then
begin
ClickBat;
end;
if MONSTER_KILL = ('druid') then
begin
ClickDruid;
end;
if MONSTER_KILL = ('warewolf') then
begin
Clickwarewolf;
end;
if MONSTER_KILL = ('dwarf') then
begin
Clickskeleton;
end;
end;

How would i shorten this up using cases? I read the thread but I don't understand how it would apply here.

euphemism

2012-12-11 19:44:02

In a case statement format, your procedure would look like:


procedure Chooseproc;
begin
case (Lowercase(MONSTER_KILL)) of
'ghost': ClickGhost;
'skeleton': ClickSkeleton;
'bat': ClickBat;
'druid': ClickDruid;
'werewolf': Clickwarewolf;
'dwarf': Clickskeleton;
end;
end;

If you are going to be doing more than one thing (Like, running more than one function/procedure, or assigning more than one variable, you need to add begins and ends for each case:


procedure Chooseproc;
begin
case (Lowercase(MONSTER_KILL)) of
'ghost':
begin
ClickGhost;
end;
'skeleton':
begin
ClickSkeleton;
end;
'bat':
begin
ClickBat;
end;
'druid':
begin
ClickDruid;
end;
'werewolf':
begin
Clickwarewolf;
end;
'dwarf':
begin
Clickskeleton;
end;
end;
end;

rj

2012-12-11 19:46:34

Thanks gonna save so much room when/if i add more monsters! now how would i choose a random case?

So far i got:

 case Random(4) of
1: BreakMessage = BREAK_MESSAGE1;
2: BreakMessage = BREAK_MESSAGE2;
3: BreakMessage = BREAK_MESSAGE3;
4: BreakMessage = BREAK_MESSAGE4;
end;

To randomize break message

But i get this error:
[Error] C:\Users\****\Desktop\simba\Combat\Soulsplit autofighter.simba(41:39): Internal error (20) at line 40
Compiling failed.

euphemism

2012-12-11 20:15:16

Just saw your other help thread. Why did you not post the entire script here? The comment about using cases was not directed towards the code you posted in this thread, but rather to your very repetitive 'ClickX' procedures. Using case statements, you can remove every single one of those procedures and replace them with just the single:


procedure ClickMonster;
var
DTM, X, Y: Integer;
begin
case (Lowercase(MONSTER_KILL)) of
'ghost': DTM := DTMFromString('mLgAAAHicY2JgYLgKxDeAuB6Im4F43twlDDNnLmFgAbJBmBGKGRgAuZgGcQ==');
'skeleton': DTM := DTMFromString('mLgAAAHicY2JgYIhjZGCIBuK9QPZJIO7paWJoaqpk4ASyQZgRihkYAJb8BW8=');
'bat': DTM := DTMFromString('mLgAAAHicY2JgYEhhZGDIAOJlQPZSIC7ITGcozc1hYAGyQZgRihkYAIVaBLQ=');
'druid': DTM := DTMFromString('mLgAAAHicY2JgYChiZGAoAOIdQPZWIJ6R5s6wd/MMBhYgG4QZoZiBAQCdPQWr');
'werewolf': DTM := DTMFromString('mLgAAAHicY2JgYFjEyMCwDIhNgdgIiA3UxBh83WwY2IFyIMwIxQwMAF3WAwE=');
'dwarf': DTM := DTMFromString('mLgAAAHicY2JgYIhihOBgEBuIm6uqGFq0FBlYgWwQZoRiBgYAaUADuA==');
end;
if FindDTM(DTM, x, y, 4, 6, 512, 333) then
begin
ClearDebug;
status := ('Attacking ');
writeln('Status:' + status + monsterkill + '.');
Writeln('Kills:' + Tostr(kills));
Writeln('Time running: ' + IntToStr(Round(t/3600))+ ':' + IntToStr(Round(t/60))+ ':' + IntToStr(Round(t)));
MouseSpeed:=45;
mmouse(x, y,1,1);
Wait(20 + Random(50));
ClickMouse(X, Y, Mouse_Left);
Wait(1800 + Random(500));
CheckCombat;
end;
FreeDTM(DTM);
end;

Granted, this won't work, because in this thread you said you had a constant named "MONSTER_KILL", which is used in the above procedure, but in the script you posted in the other thread the constant is actually named "monsterkill".

As for the above post, Random(4) will return 0, 1, 2, or 3. So keep that in mind.

rj

2012-12-11 20:18:40

From: euphemism
Just saw your other help thread. Why did you not post the entire script here? The comment about using cases was not directed towards the code you posted in this thread, but rather to your very repetitive 'ClickX' procedures. Using case statements, you can remove every single one of those procedures and replace them with just the single:


procedure ClickMonster;
var
DTM, X, Y: Integer;
begin
case (Lowercase(MONSTER_KILL)) of
'ghost': DTM := DTMFromString('mLgAAAHicY2JgYLgKxDeAuB6Im4F43twlDDNnLmFgAbJBmBGKGRgAuZgGcQ==');
'skeleton': DTM := DTMFromString('mLgAAAHicY2JgYIhjZGCIBuK9QPZJIO7paWJoaqpk4ASyQZgRihkYAJb8BW8=');
'bat': DTM := DTMFromString('mLgAAAHicY2JgYEhhZGDIAOJlQPZSIC7ITGcozc1hYAGyQZgRihkYAIVaBLQ=');
'druid': DTM := DTMFromString('mLgAAAHicY2JgYChiZGAoAOIdQPZWIJ6R5s6wd/MMBhYgG4QZoZiBAQCdPQWr');
'werewolf': DTM := DTMFromString('mLgAAAHicY2JgYFjEyMCwDIhNgdgIiA3UxBh83WwY2IFyIMwIxQwMAF3WAwE=');
'dwarf': DTM := DTMFromString('mLgAAAHicY2JgYIhihOBgEBuIm6uqGFq0FBlYgWwQZoRiBgYAaUADuA==');
end;
if FindDTM(DTM, x, y, 4, 6, 512, 333) then
begin
ClearDebug;
status := ('Attacking ');
writeln('Status:' + status + monsterkill + '.');
Writeln('Kills:' + Tostr(kills));
Writeln('Time running: ' + IntToStr(Round(t/3600))+ ':' + IntToStr(Round(t/60))+ ':' + IntToStr(Round(t)));
MouseSpeed:=45;
mmouse(x, y,1,1);
Wait(20 + Random(50));
ClickMouse(X, Y, Mouse_Left);
Wait(1800 + Random(500));
CheckCombat;
end;
FreeDTM(DTM);
end;

Granted, this won't work, because in this thread you said you had a constant named "MONSTER_KILL", which is used in the above procedure, but in the script you posted in the other thread the constant is actually named "monsterkill".

As for the above post, Random(4) will return 0, 1, 2, or 3. So keep that in mind.


How would i make a random case like above?

KingKong

2012-12-12 01:04:30

you missed a colon while using the breakmessage = break_message, it should be breakmessage := break_message1

P1ng

2012-12-12 01:24:31

To use the random case, you simply need to remember the case starts at 0 as euphemism said. So Random(4) will return a number from 0 to 3. 4 Would not be included in that range, so the random case would become -

case Random(4) of
0: BreakMessage = BREAK_MESSAGE1;
1: BreakMessage = BREAK_MESSAGE2;
2: BreakMessage = BREAK_MESSAGE3;
3: BreakMessage = BREAK_MESSAGE4;
end;

KingKong

2012-12-12 06:57:05

the random number doesnt anything to do with that error and even if the number is out of range it wont raise errors

masterBB

2012-12-12 07:05:12

how about using :=

so

case Random(4) of
0: BreakMessage := BREAK_MESSAGE1;
1: BreakMessage := BREAK_MESSAGE2;
2: BreakMessage := BREAK_MESSAGE3;
3: BreakMessage := BREAK_MESSAGE4;
end;

e:

Didn't noticed kingkong his post.

rj

2012-12-12 15:50:40

Thanks guys works great!