In this tutorial we are going to go more in depth into records.
I made a small introduction on them in the syntax tutorial but that was just scratching the surface.
A cool thing about record for example is that they can inherit from each others.
I'm going to give you actual examples from my WaspLib.
In the basescript.simba file of WaspLib you have
type TBaseScript = record Name: String; Version: String; IsSetup: Boolean; TimeRunning: TStopwatch; StatsDebugTick: Int64; Action: String; ExtraInfo: String; ActionProfit: Int32; TotalActions: Int32; TotalProfit: Int32; end; TBaseWalkerScript = record(TBaseScript) //inherits all variables, functions and procedures of TBaseScript. RSW: TRSWalker; end; TBaseBankScript = record(TBaseWalkerScript) //inherits all variables, functions and procedures of TBaseWalkerScript. ScriptBank: PRSObject; //Current bank for the script. BankTab: Int32; //BankTab cache.
So you have
TBaseScript which is the base record I use for all my scripts and it contains all the base variables my scripts use.
Then you have
TBaseWalkerScript which is used by all my scripts that use RSWalker.
It inherits all the variables
TBaseBankScript which inherits from
TBaseWalkerScript so it will have all of it's variables, procedures, functions and also all of
So when I'm making a new script first I decide which kind of script it will be, if it's a script that uses the bank, lets say a woodcutting script I do:
type TWoodcutter = record(TBaseBankScript) //all variables of TBaseBankScript are already part of this. now we add extra stuff we need. LogType: TRSItem; AxeType: TRSItem; end;
If the script just needs walker I use
TBaseWalkerScript instead and if it doesn't need walking I use
As I said previously, records that inherit from another also inherit their procedures and functions.
TBaseScript I have this procedure:
procedure TBaseScript.Init; //override me to add more stuff. begin if IsSetup then Exit; IsSetup := True; if RemoteInputEnabled then RSClient.RemoteInput.Setup(); SRL.Setup; Antiban.Setup; WL.Activity.Init(260000); TimeRunning.Start; //override me to add more stuff. end;
This is the base init function for all my scripts. But
TBaseBankScript need some extra things set up on it's init function along with everything
TBaseScript.Init already did.
So what do we do? We override it and inherit from the previous function like so:
procedure TBaseBankScript.Init; override;//override me to add more stuff. begin inherited; BankTab := -1; CollectTimer.Init(600000); //override me to add more stuff. end;
And when I'm making a script, like the woodcutter example I gave above, if I need to setup extra things for that specific script I do the same:
procedure TWoodcutter.Init; override; begin inherited; RSW.Setup('world'); LogType := 'Willow logs'; AxeType := 'Rune axe'; end;
And that's it for this tutorial 😄