Wardancer
2012-09-07 10:23:23
So I'm rewriting a few functions of grandexchange.simba (quite the educating process) and I came upon what I would call an aesthetic issue. First, I should say what the code does. It basically lets you pick which slot you want to buy from the GE ('any' or 1 to 6). I built in a failsafe that returns a message if the slot isn't free, but in the process I ended up writing a "begin end" with nothing in middle since I didn't want to repeat the same action for the 7 options and make this look even more atrocious. In case that wasn't clear, the action I want it to do if the value is true is the same for the 7 options. Let me show you the code (which works flawlessly as far as I can tell):
I considered coding a separate function which would be the failsafe itself (I really dislike the way I'm repeating many times the same Writeln message), but I was curious about other people's opinions. I'll more than likely be coding that other function which will act as the failsafe by the time someone replies (wondering if I can code this a simple way without using "spot" as a global variable at the moment), but I'd like to know how other people would tackle this issue.
Any suggestion regarding how I coded this is more than welcome. Also, if you have any question, feel free to ask me.
function BuyGE(spot : String): Boolean;
var
x, y : Integer;
begin
if not InGEE then
Exit;
if GEESellMenu or GEEBuyMenu then
GEEMenuExit;
case spot of
'any':
if (FindObject(x,y,BuyButton,MSX1,MSY1,MSX2,MSY2)) then
begin
end else
begin
Writeln('No slot is free');
Exit;
end;
'1':
if (FindObject(x,y,BuyButton,35,85,173,190)) then
begin
end else
begin
Writeln('This slot is not free');
Exit;
end;
'2':
if (FindObject(x,y,BuyButton,190,85,328,190)) then
begin
end else
begin
Writeln('This slot is not free');
Exit;
end;
'3':
if (FindObject(x,y,BuyButton,346,85,485,190)) then
begin;
end else
begin
Writeln('This slot is not free');
Exit;
end;
'4':
if (FindObject(x,y,BuyButton,35,200,170,310)) then
begin
end else
begin
Writeln('This slot is not free');
Exit;
end;
'5':
if (FindObject(x,y,BuyButton,190,200,330,310)) then
begin
end else
begin
Writeln('This slot is not free');
Exit;
end;
'6':
if (FindObject(x,y,BuyButton,345,200,480,300)) then
begin
end else
begin
Writeln('This slot is not free');
Exit;
end;
end;
begin;
ClickMouse2(true);
WaitOption('Buy O',500);
WaitFunc(@GEEBuyMenu,10,6000);
end;
end;I considered coding a separate function which would be the failsafe itself (I really dislike the way I'm repeating many times the same Writeln message), but I was curious about other people's opinions. I'll more than likely be coding that other function which will act as the failsafe by the time someone replies (wondering if I can code this a simple way without using "spot" as a global variable at the moment), but I'd like to know how other people would tackle this issue.
Any suggestion regarding how I coded this is more than welcome. Also, if you have any question, feel free to ask me.