Log in

View Full Version : How to use cases in this instance?



rj
12-12-2012, 12:32 AM
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
12-12-2012, 12:44 AM
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
12-12-2012, 12:46 AM
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
12-12-2012, 01:15 AM
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('mLgAAAHicY2JgYLgKxDeAuB6Im4F43twlDD NnLmFgAbJBmBGKGRgAuZgGcQ==');
'skeleton': DTM := DTMFromString('mLgAAAHicY2JgYIhjZGCIBuK9QPZJIO7paW Joaqpk4ASyQZgRihkYAJb8BW8=');
'bat': DTM := DTMFromString('mLgAAAHicY2JgYEhhZGDIAOJlQPZSIC7ITG cozc1hYAGyQZgRihkYAIVaBLQ=');
'druid': DTM := DTMFromString('mLgAAAHicY2JgYChiZGAoAOIdQPZWIJ6R5s 6wd/MMBhYgG4QZoZiBAQCdPQWr');
'werewolf': DTM := DTMFromString('mLgAAAHicY2JgYFjEyMCwDIhNgdgIiA3UxB h83WwY2IFyIMwIxQwMAF3WAwE=');
'dwarf': DTM := DTMFromString('mLgAAAHicY2JgYIhihOBgEBuIm6uqGFq0FB lYgWwQZoRiBgYAaUADuA==');
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
12-12-2012, 01:18 AM
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('mLgAAAHicY2JgYLgKxDeAuB6Im4F43twlDD NnLmFgAbJBmBGKGRgAuZgGcQ==');
'skeleton': DTM := DTMFromString('mLgAAAHicY2JgYIhjZGCIBuK9QPZJIO7paW Joaqpk4ASyQZgRihkYAJb8BW8=');
'bat': DTM := DTMFromString('mLgAAAHicY2JgYEhhZGDIAOJlQPZSIC7ITG cozc1hYAGyQZgRihkYAIVaBLQ=');
'druid': DTM := DTMFromString('mLgAAAHicY2JgYChiZGAoAOIdQPZWIJ6R5s 6wd/MMBhYgG4QZoZiBAQCdPQWr');
'werewolf': DTM := DTMFromString('mLgAAAHicY2JgYFjEyMCwDIhNgdgIiA3UxB h83WwY2IFyIMwIxQwMAF3WAwE=');
'dwarf': DTM := DTMFromString('mLgAAAHicY2JgYIhihOBgEBuIm6uqGFq0FB lYgWwQZoRiBgYAaUADuA==');
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
12-12-2012, 06:04 AM
you missed a colon while using the breakmessage = break_message, it should be breakmessage := break_message1

P1ng
12-12-2012, 06:24 AM
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
12-12-2012, 11:57 AM
the random number doesnt anything to do with that error and even if the number is out of range it wont raise errors

masterBB
12-12-2012, 12:05 PM
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
12-12-2012, 08:50 PM
Thanks guys works great!