SRL Archive - SRL Suggestions

Add $define SMART in Smart.scar


Grippy

2009-03-09 10:58:14

A suggestion for Smart.scar. At the top of the include, add a define for SMART:

{$define SMART}

This makes it much easier to write code that needs to know whether SMART is enabled, while having zero impact on existing code (completely backward compatible with existing scripts).

Nava2

2009-03-09 20:39:06

Erm, probably won't be used as that would take some effort from leechers.

o.O

Method

2009-03-09 21:15:55

What sort of code would need to know if SMART was enabled or not, besides the lines that open SMART and set the window handle? Or are those what you're looking to account for?

Da 0wner

2009-03-09 21:19:27

Maybe he means this. Replace SRL.scar with:

//----------------------------------------------------------------------------//
//-- Scar Standard Resource Library --//
//----------------------------------------------------------------------------//
//-- by: Azeroth, Bebe, BenLand100, benleegt, Boreas, c0de, --//
//-- Cheesehunk, dakota, Dankness, driger1592, Flyboy, Freddy1990, --//
//-- Hobbit, inferno, Kernel Klink, Knightstreak, Krazy_Meerkat, --//
//-- Krichevskoy, Liquid, Lorax, Mad Cow, Markus, masquerader, --//
//-- mastaraymond, moparisthebest, Mutant Squirrle, n3ss3s nielsie95, --//
//-- phantombmx, pups, Pyro, RAM, realrune, Renax, Ron, RsN, --//
//-- SKy Scripter, solemn wishes, Spky, SRL, Starblaster100, S --//
//-- tupid3ooo, Sumilion, tarajunky, The Claw, The_Rs_Monkey, Zephyrsfury --//
//-- Wizzup?, WT-Fakawi, XxKanexX, Yakman, YoHoJo, _ChArMz, --//
//-- --//
//-- ....... and the SRL Community. --//
//----------------------------------------------------------------------------//

{$IFDEF EnableSmart}
{.include SRL/SRL/Misc/Smart.scar}
{$ENDIF}

//----------------------------------------------------------------------------//
// -- SRL Level 1 Includes --//
// -- --//
// -- Low Level SCAR Math, Mouse Movement and Color Clicking routines. --//
//----------------------------------------------------------------------------//

{.include SRL/SRL/Core/Globals.scar}
{.include SRL/SRL/Core/Math.scar}
{.include SRL/SRL/Core/Mouse.scar}
{.include SRL/SRL/Core/Color.scar}
{.include SRL/SRL/Core/Players.scar}
{.include SRL/SRL/Core/Overwrite.scar}

//----------------------------------------------------------------------------//
// -- SRL Level 2 Includes --//
// -- --//
// -- Interface, Object and OCR routines. --//
//----------------------------------------------------------------------------//

{.include SRL/SRL/Core/Timing.scar}
{.include SRL/SRL/Core/GameTab.scar}
{.include SRL/SRL/Core/SRLLog.scar}
{.include SRL/SRL/Core/Text.scar}
{.include SRL/SRL/Core/Inventory.scar}
{.include SRL/SRL/Core/Object.scar}

//----------------------------------------------------------------------------//
// -- SRL Level 3 Includes --//
// -- --//
// -- MapWalking, AntiRandoms, Bank, Symbol and many more... --//
//----------------------------------------------------------------------------//

{.include SRL/SRL/Misc/Bitmaps.scar}
{.include SRL/SRL/Core/FlagChat.scar}
{.include SRL/SRL/Core/Login.scar}
{.include SRL/SRL/Core/Mapwalk.scar}
{.include SRL/SRL/Core/Bank.scar}
{.include SRL/SRL/Core/Symbol.scar}
{.include SRL/SRL/Core/RC.scar}
{.include SRL/SRL/Core/AutoColor.scar}
{.include SRL/SRL/Core/AntiRandoms/Common.scar}
{.include SRL/SRL/Core/Globalstats.scar}
{.include SRL/SRL/Core/CAutoRespond.scar}
{.include SRL/SRL/Core/AntiRandoms/Box.scar}
{.include SRL/SRL/Core/AntiRandoms/Certer.scar}
{.include SRL/SRL/Core/AntiRandoms/Demon.scar}
{.include SRL/SRL/Core/AntiRandoms/Forester.scar}
{.include SRL/SRL/Core/AntiRandoms/Quiz.scar}
{.include SRL/SRL/Core/AntiRandoms/Sandwich.scar}
{.include SRL/SRL/Core/AntiRandoms/EvilBob.scar}
{.include SRL/SRL/Core/AntiRandoms/Leo.scar}
{.include SRL/SRL/Core/AntiRandoms/Frog.scar}
{.include SRL/SRL/Core/AntiRandoms/ChatRandoms.scar}
{.include SRL/SRL/Core/AntiRandoms/Molly.scar}
{.include SRL/SRL/Core/AntiRandoms/Pillory.scar}
{.include SRL/SRL/Core/Antirandoms/Pinball.scar}
{.include SRL/SRL/Core/Antirandoms/Maze.scar}
{.include SRL/SRL/Core/AntiRandoms/AntiRandoms.scar}
{.include SRL/SRL/Core/AntiBan.scar}
{.include SRL/SRL/Core/Amount.scar}

{*******************************************************************************
procedure SetupSRL;
by: SRL Dev Team
Description: Sets up all variables needed to run SRL.
*******************************************************************************}

procedure SetupSRL;
begin
MouseSpeed := 15;
CheckHPFirst := True;
Reincarnate := False;
TalkAfterRandoms := False;
RoadColor := 0;
WaterColor := 0;
BankColor := 0;
LampSkill := 'mining';
SetUpSRLReport;
LoadCosineArrays;
SymbolAccuracy:= 0.8;
LoadNPCArray;
LoadSRLBitMaps;
SolveChatRandoms := True;
SetupSRLAutoResponder;
UseFindMod := True;
LogoutOnMod := True;
UseFindTrade := True;
Screenshots := False;
InitializeSRLLogFile;
Writeln ('SRL Compiled in '+ IntToStr(GetTimeRunning) + ' msec');
end;

And when making scripts you would do:

program New;
{$Define EnableSmart}
{.include SRL/SRL.scar}

begin
{$IFDEF EnableSmart}
SmartSetupEx(43, true, true, false);
SetTargetDC(SmartGetDC);
//etc...
{$ENDIF}
end.

bullzeye95

2009-03-09 21:23:39

… What he's saying is pretty straight forward. Just define SMART at the top of SMART.scar.

Grippy

2009-03-09 22:07:16

From: Nava2
Erm, probably won't be used as that would take some effort from leechers.


I don't expect leechers to be able to read code, much less understand conditional compilation.

I, however, do know what to do with it, and I'd prefer not to modify library code any more than necessary, as it makes merging vendor changes into my local SVN repository a pain.

From: Method
What sort of code would need to know if SMART was enabled or not, besides the lines that open SMART and set the window handle? Or are those what you're looking to account for?


Those are the main concern. I tend to use conditional compilation in scripts to make putting features together and debugging easier. A 'SMART' def lets me set up scripts to automatically use Smart without any reconfiguration for the user:

procedure Setup;
begin
{$ifdef GripTrace}
Trace( 'Setup', ttEnter );
{$endif}
try
{$ifdef SMART}
SMARTSetUpEx(21, False, True, False);
SetTargetDC(SMARTGetDC);
{$endif}

SetupSRL;
// ScriptID := '';

DeclarePlayers;
finally
{$ifdef GripTrace}
Trace( 'Setup', ttExit );
{$endif}
end;
end;

Admittedly, copious use of ifdef/endif can make the code a bit uglier than it otherwise might be, but it is confined mostly to core routines that a regular user won't see much of.

But there are other cases where Smart makes a difference. For example, if Smart is enabled, GetClientDimensions() returns the desktop dimensions (unless the user happened to set a target window).

This is probably a bug that should be addressed, but until it is it can be handled with the define.

That's part of the point, you don't always know what it'll be useful for, but it's free and has no adverse impacts.

nielsie95

2009-03-10 10:49:23

This was actually the idea at the beginning, but SRL decided to keep SMART separated. Now SMART comes with SRL, I guess it's a good idea to reintroduce it.