pwnaz0r
2007-10-07 21:40:07
If you like, please ++ rep me!
Well, as some of you know, I had to take a 8 hour car ride to a football game that I went to see and I knew I would be bored. Right before I left, I saw The Claw's tutorial "Making a Flawless Script". I printed it off and read some of it in my car, and I started thinking about how people are always so concerned with who has the fastest function, and who's function can do this and that etc. If you think about it, it doesn't matter who's functions are the best or who can do which things if the mainloop isn't correct. The mainloop is the most important part of the script. It would be like saying that the engine is not the most important part of a car - the car would not fulfill its purpose of transporting you somewhere if the engine did not run.
SO, i stopped at a rest stop, picked up a notepad and a pencil, and started doing some research. In my opinion, the research is very thorough, taking 9+ hours of my driving time, so I hope you will not let my works go in vain and read the whole tutorial. The research takes up the entire notebook (50 pages), but I will not be copying the entire notebook to this tutorial because it's too long and it is simply me double checking and running through every mainloop I designed. On this note, I give you my tutorial :D:
In your script, you should at least have these components:
- Player time break out (declared in the script constants).
- Every Task should have a breakout
- Mining, Dropping, etc.
I recommend these be time related and that you give the user the option to set them.
For every procedure you should
- Have a time breakout.
- If notlogged in breakout (if you dont understand this, please check The Claw's tutorial. In short, it is just saying to skip the procedure if you are not logged in to prevent the random waiting of a script.
- Every procedure that a random could occur should have unconditional randoms. This simply means that it looks for randoms, even if it shouldn't break out because of it (EX. break out of a mining loop because you saw a random).
Let us start out with a fresh ScarScript screen. Make a procedure called NewLoop. We will be making our mainloop as a procedure so we just have to call that procedure when we want it. Now to start off your mainloop, you must ask yourself "what tasks do I want accomplished, and in which order do I want to do them. Then you must split them up into sections. Here is my list (for my miner):
Everyloop will contain the loop under it. Hopefully you understand this, and you should, since this is the intermediate section :D. Now you will create a begin and end to encompass each loop, like so:
you also need to comment it like so. I believe that the key to creating a good loop is organization. Now you need to ask yourself the following questions (We will answer them during the tutorial).
- Player Logged out( will cover all errors in not finding something / unsolvable randoms / etc).
- Before every loop, there will be a breakout until the last cycle of the loop (changing players most likely). I will then change players True or False depending on an error. There wont be a random/error in mining that will allow you to continue. I will also add
Hint - every non - RS Complaint procedure (recallibration of colors, etc) should be based on a boolean. Then, put this procedure inside the recallibration procedure. Recallibration function must be a boolean.
I took the liberty of adding the repeats into the procedure for you.
This is what we call "the shell" of your mainloop. You will start to put things inside it now. First, you need to add the breakouts. I will now cleanup (take out the comments) and add the "if not loggedin" line to every loop.
PS. If would still keep the begin and ends in there. I like to think of them as "the bones" that keep your shell upright :D.
Now I will add all my breakouts (I commented them in the Shell so I would know what they are.)
**Note** Instead of if not loggedin then break, I will be using a custom procedure I made to handle if not loggedin, if inunsolvablerandom, and if not FindRS all into one called "Problem".
While Mining Rocks, Before Mining Rocks, While Dropping.
I find that the best time to do a report is during dropping, so thats when I will do it.
And now, on to the fun part. You get to fill in this "failsafe shell" with your own procedures and functions. Don't forget to add the if not loggedin line to every single RS related procedure and function!
List what every loop should do:
Here is my final procedure and where I leave you to branch out on your own. Please check and recheck, test and retest your loops before releasing. Hopefully in this way, we will revolutionize the way we script and improve the quality of all script we produce!
- Cheers,
Pwnaz0r
Well, as some of you know, I had to take a 8 hour car ride to a football game that I went to see and I knew I would be bored. Right before I left, I saw The Claw's tutorial "Making a Flawless Script". I printed it off and read some of it in my car, and I started thinking about how people are always so concerned with who has the fastest function, and who's function can do this and that etc. If you think about it, it doesn't matter who's functions are the best or who can do which things if the mainloop isn't correct. The mainloop is the most important part of the script. It would be like saying that the engine is not the most important part of a car - the car would not fulfill its purpose of transporting you somewhere if the engine did not run.
SO, i stopped at a rest stop, picked up a notepad and a pencil, and started doing some research. In my opinion, the research is very thorough, taking 9+ hours of my driving time, so I hope you will not let my works go in vain and read the whole tutorial. The research takes up the entire notebook (50 pages), but I will not be copying the entire notebook to this tutorial because it's too long and it is simply me double checking and running through every mainloop I designed. On this note, I give you my tutorial :D:
Loop Design 101
[LEFT]The following tutorial will present you with enough information to design and modify a standard, functional mainloop for your script. It will not make it for you, it will only show you the steps. You should always run through a checklist of what could happen and what should happen in your mainloop. If you follow the design I give you, your mainloop will be near flawless. I will discuss the mainloop used in my PowerMiner, which I did design while making this tutorial. I hope it is as informative to you as it was to me.
[/LEFT]
[LEFT]The following tutorial will present you with enough information to design and modify a standard, functional mainloop for your script. It will not make it for you, it will only show you the steps. You should always run through a checklist of what could happen and what should happen in your mainloop. If you follow the design I give you, your mainloop will be near flawless. I will discuss the mainloop used in my PowerMiner, which I did design while making this tutorial. I hope it is as informative to you as it was to me.
[/LEFT]
In your script, you should at least have these components:
- Player time break out (declared in the script constants).
- Every Task should have a breakout
- Mining, Dropping, etc.
I recommend these be time related and that you give the user the option to set them.
For every procedure you should
- Have a time breakout.
- If notlogged in breakout (if you dont understand this, please check The Claw's tutorial. In short, it is just saying to skip the procedure if you are not logged in to prevent the random waiting of a script.
- Every procedure that a random could occur should have unconditional randoms. This simply means that it looks for randoms, even if it shouldn't break out because of it (EX. break out of a mining loop because you saw a random).
Let us start out with a fresh ScarScript screen. Make a procedure called NewLoop. We will be making our mainloop as a procedure so we just have to call that procedure when we want it. Now to start off your mainloop, you must ask yourself "what tasks do I want accomplished, and in which order do I want to do them. Then you must split them up into sections. Here is my list (for my miner):
All Players(this is basically the whole loop)
Single Players Loop(the single players task)
Doing a load(mining a inventory) and then dropping loop.
Mining Loop.Everyloop will contain the loop under it. Hopefully you understand this, and you should, since this is the intermediate section :D. Now you will create a begin and end to encompass each loop, like so:
procedure NewLoop;
begin // begin All players loop
begin // begin Single Players loop
begin // Begin Load and Dropping loop
begin // Begin Mining loop
end; // End mining loop
end; // End Load loop
end; // End Single Players loop
end; // End All Players loop
you also need to comment it like so. I believe that the key to creating a good loop is organization. Now you need to ask yourself the following questions (We will answer them during the tutorial).
- How will I determine when to switch players?
- How will I implement (put) this into my script?
- Which of these do I want to repeat?
- Which of these will focus on RS?
- Which of these wil need random support?
- Which will focus on players?
- Which will contain your report?
How will I determine when to switch players?- Player Logged out( will cover all errors in not finding something / unsolvable randoms / etc).
How will I implement (put) this into my script?- Before every loop, there will be a breakout until the last cycle of the loop (changing players most likely). I will then change players True or False depending on an error. There wont be a random/error in mining that will allow you to continue. I will also add
if not Loggedin then exit
to every RS-Complaint procedure. Hint - every non - RS Complaint procedure (recallibration of colors, etc) should be based on a boolean. Then, put this procedure inside the recallibration procedure. Recallibration function must be a boolean.
procedure Recallibrate;
var
NeedToRecallibrate: boolean;
begin
NeedToRecallibrate:= not FindOre;
if NeedtoRecallibrate then
begin
I took the liberty of adding the repeats into the procedure for you.
procedure NewLoop;
begin // begin All players loop
repeat // Will end on all playersinactive(procedure I made to tell when no more players are active;
begin // begin Single Players loop
repeat // Will end on Playertime is up(breakout) or LoadsDone.
begin // Begin Load and Dropping loop
repeat // Will end on InvFull or LoadBreakout(breakout).
begin // Begin Mining loop
repeat // Will end on RockGone or TimeBreakout(breakout)
Until(RockGone);
end; // End mining loop
Until(InvFull);
end; // End Load loop
Until(LoadsFinished(Players[CurrentPlayer].Integers[0]));
end; // End Single Players loop
Until(AllplayersInactive);
end; // End All Players loop
This is what we call "the shell" of your mainloop. You will start to put things inside it now. First, you need to add the breakouts. I will now cleanup (take out the comments) and add the "if not loggedin" line to every loop.
PS. If would still keep the begin and ends in there. I like to think of them as "the bones" that keep your shell upright :D.
procedure NewLoop;
begin
repeat
if not LoggedIn then LoginPlayer;// at this point, if he is not loggedin, there was just an error because he just loggedin.
begin
repeat
if not LoggedIn then break;
begin
repeat
if not LoggedIn then break;
begin
repeat
if not LoggedIn then break;
Until(RockGone)
end;
Until(InvFull)
end;
Until(LoadsDone(Players[CurrentPlayer].Integers[0]);
end;
Until(AllplayersInactive);
end;
Now I will add all my breakouts (I commented them in the Shell so I would know what they are.)
procedure PlayerLoop; // Renamed
var
PlayerTime, LoadTime, RockTime: integer; //Failsafe vars. Timers.
begin
repeat
if not LoggedIn then LoginPlayer;
begin
MarkTime(PlayerTime);
repeat
if not LoggedIn then break;
begin
MarkTime(LoadTime);
repeat
if not LoggedIn then break;
begin
MarkTime(RockTime);
repeat
if not LoggedIn then break;
if TimeOver(RockTime) then break;// not a real procedure, you must use timefrommark and set a failsafe time for this one.
Until(RockGone)
end;
if TimeOver(LoadTime) then break;
Until(InvFull)
end;
if TimeOver(PlayerTime) then break;
Until(LoadsDone(Players[CurrentPlayer].Integers[0]);
end;
Until(AllplayersInactive);
end;
**Note** Instead of if not loggedin then break, I will be using a custom procedure I made to handle if not loggedin, if inunsolvablerandom, and if not FindRS all into one called "Problem".
Which functions need randoms support?While Mining Rocks, Before Mining Rocks, While Dropping.
Which will focus on report?I find that the best time to do a report is during dropping, so thats when I will do it.
And now, on to the fun part. You get to fill in this "failsafe shell" with your own procedures and functions. Don't forget to add the if not loggedin line to every single RS related procedure and function!
List what every loop should do:
All Players- Execute all loops below it, Change Players.
Single Players Loop- Execute all loops below it, Drop and do report.
Doing a load(mining a inventory)- Execute mining loop, find fast randoms after dropping.
Mining Loop- Mine a rock.Here is my final procedure and where I leave you to branch out on your own. Please check and recheck, test and retest your loops before releasing. Hopefully in this way, we will revolutionize the way we script and improve the quality of all script we produce!
procedure PlayerLoop(MaxplayerTime, MaxLoadTime, MaxRockTime: integer);
var
PlayerTime, LoadTime, RockTime: integer; //Failsafe vars. Timers.
begin
repeat
if not LoggedIn then LoginPlayer;
begin
MarkTime(PlayerTime);
repeat
if not LoggedIn then break;
begin
MarkTime(LoadTime);
repeat
if not LoggedIn then break;
begin
MarkTime(RockTime);
repeat
if not LoggedIn then break;
if TimeOver(RockTime, MaxRockTime, 1000) then break;
// Do mining things. You must have them in this loop because the marking and breaking out etc wouldn't work if they are not in that procedure.
Until(RockGone);
FindNormalRandoms;
end;
if TimeOver(LoadTime, MaxLoadTime, 60000) then break;
Until(InvFull);
end;
DropAndReportStatus;
FindNormalRandoms;
if TimeOver(PlayerTime, MaxPlayerTime, 60000) then break;
Until(LoadsDone(Players[CurrentPlayer].Integers[0]));// <-- Must log you out!!!
end;
if Not Loggedin then Nextplayer(false) else
NextPlayer(true);
Until(AllplayersInactive);
end;
- Cheers,
Pwnaz0r