Incommodious Posted November 18, 2012 Share Posted November 18, 2012 (edited) How can I set a timer for my script to restart by using a const like [sCAR]const ResetTimer=60; // How many seconds before reset?[/sCAR] and for however long that is it will reset and also if it is [sCAR]const ResetTimer=0; //How many seconds before reset?[/sCAR] then it will be deactivated by useing like, [sCAR] if ResetTimer=0 then movemouse(x,y); // also how do you make it do nothing if the if then statement is false? end; [/scar] Edited November 18, 2012 by Incommodious Quote Link to comment Share on other sites More sharing options...
Bixby Sayz Posted November 18, 2012 Share Posted November 18, 2012 (edited) Are you looking for the script to just idle until your time is reached, then do something? [sCAR]const ResetTimer = 60; //How many seconds before reset? var T: Integer; // This will do the action over and over and over every ResetTimer seconds T := GetSystemTime + (ResetTimer * 1000); // Time is in milliseconds repeat Wait(100); // Wait 100ms (1/10th second) between time checks if (GetSystemTime > T) then begin MoveMouse(X, Y); T := GetSystemTime + (ResetTimer * 1000); // Reset timer and start again end; until False; // This will do it one time when ResetTimer seconds has passed T := GetSystemTime + (ResetTimer * 1000); // Time is in milliseconds repeat Wait(100); // Wait 100ms (1/10th second) between time checks until (GetSystemTime > T); MoveMouse(X, Y)[/sCAR] Edited November 18, 2012 by Bixby Sayz Quote Link to comment Share on other sites More sharing options...
Incommodious Posted November 18, 2012 Author Share Posted November 18, 2012 (edited) I need one that will restart the entire script over whenever the timer/countdown is up, and one that will restart a specific procedure or more than one procedure, so maybe have an option at the begining of the Restart procedure to set to make it either restart the entire script, 1 procedure, or 2 procedures. EDIT: To be more specific im going to make it into a Relog timer so a person can set how long for his character to relog and when he relogs it needs to have either 1 other procedure restart with it or maybe 2 different procedures go with it along with restarting the Relog procedure so thats a total of 3 procedures for it to restart. Or just the entire script ingeneral. Edited November 18, 2012 by Incommodious Quote Link to comment Share on other sites More sharing options...
Bixby Sayz Posted November 18, 2012 Share Posted November 18, 2012 I don't know if you can restart a script from inside the script itself. If I needed to do something like that I would make a procedure that setups the script (and resets vars back to beginning when needed). Don't entirely understand what you are trying to do here. [sCAR]program new; const ResetTimer = 60; //How many seconds before reset? var T: Integer; procedure ScriptSetup; begin // Do script setup in here, reseting any vars that // need resetting. end; begin repeat ScriptSetup; T := GetSystemTime + (ResetTimer * 1000); repeat // Do script actions here until (GetSystemTime > T); until False; end.[/sCAR] Quote Link to comment Share on other sites More sharing options...
Incommodious Posted November 19, 2012 Author Share Posted November 19, 2012 (edited) I dont know why I didn't do this before but here is my script and i need this to reset whenever told. [scar]Program Relog; var x, y :Integer; const User='no user'; //Username, dont touch to keep relog features off Pass='no pass'; //Password, dont touch to keep relog features off Character=1; //Character 1=Top 2=Middle 3=Bottom RelogTimer=60; //RelogTimer by seconds. Set to 0 for no Timer Procedure Relog; begin Findcolor(x,y,8107462,69,359,161,385); ClickMouse(x,y,true); Wait(100) ClickMouse(412,359,true); Wait(100) TypeText(User); Wait(100) ClickMouse(412,395,true); Wait(100) TypeText(Pass+chr(13)); FindColor(x,y,8109518,380,425,433,443); ClickMouse(x,y,true); Wait(200) ClickMouse(542,141,true); if (findcolor(x,y,10079232,359,312,439,336)) then begin ClickMouse(x,y,true); Findcolor(x,y,8107462,69,359,161,385); ClickMouse(x,y,true); Wait(100) ClickMouse(412,359,true); Wait(100) TypeText(User); Wait(100) ClickMouse(412,395,true); Wait(100) TypeText(Pass+chr(13)); end else begin MoveMouse(542,139) end; if (character=1) then begin Wait(300) ClickMouse(543,142,TMouseLeft); end; if (character=2) then begin Wait(300) ClickMouse(543,267,TMouseLeft); if (character=3) then begin Wait(300) ClickMouse(543,388,TmouseLeft); end; end; end; begin Relog; end. [/scar] can you just put it into this procedure? also i know that in the user, pass if you dont change it from no user or no pass it will disable the relog all togeather but i havnt put that in yet but ill get to it. Edited November 19, 2012 by Incommodious Quote Link to comment Share on other sites More sharing options...
LordJashin Posted November 19, 2012 Share Posted November 19, 2012 Your options: Repeat, For, label goto statements. But they all do the same thing, they just repeat. This "reset" thing is the same thing, but if you have any variables that you set. You can set them to their default values (usually 0 or '' or false)... Quote Link to comment Share on other sites More sharing options...
Incommodious Posted November 19, 2012 Author Share Posted November 19, 2012 I dont understand Quote Link to comment Share on other sites More sharing options...
LordJashin Posted November 19, 2012 Share Posted November 19, 2012 Have you not seen this yet? http://wiki.scar-divi.com/index.php?title=The_Official_SCAR_Scripting_Guide Quote Link to comment Share on other sites More sharing options...
Incommodious Posted November 19, 2012 Author Share Posted November 19, 2012 Ive seen it i just dont understand the way you put it, can you give me an example? Quote Link to comment Share on other sites More sharing options...
LordJashin Posted November 19, 2012 Share Posted November 19, 2012 Yep and I'll rip it straight from the original's masterpiece: The repeat loop is a construct where you loop until something is true. This condition contrary to the while loop is checked at the end of the loop, not the start. This loop does not use a begin..end construct so it will always work on multiple lines. This example shows the example from the while loop adapted for the repeat loop. The condition is not checked at the start of the loop, so if the variable is 5, it will loop infinitely as it will be increased to 6 inside of the loop before it's checked. [scar] var Int: Integer; begin Int := 0; repeat WriteLn('Hello World ' + IntToStr(Int) + '!'); Inc(Int); until Int = 5; WriteLn('Out of the loop'); end.[/scar] Quote Link to comment Share on other sites More sharing options...
Incommodious Posted November 19, 2012 Author Share Posted November 19, 2012 (edited) But wouldn't that just keep running the script until Int=5 which would be it saying 'Hello World' 5 times then the script would end? and if so i need it to run until the RelogTimer*1000 = Int. But instead of ending the procedure i just want it to restart it. EDIT: I mean the Int = RelogTime*1000. Int=1 Edited November 19, 2012 by Incommodious Quote Link to comment Share on other sites More sharing options...
LordJashin Posted November 19, 2012 Share Posted November 19, 2012 Well...If you want it to repeat for a certain time of the day, this could be arranged. Restarting it, just means your looping it more. You could have multiple loops as well. Maybe you can do label and goto... [scar] program aaa; label aaaaaaaaaa; begin aaaaaaaaaa: WriteLn('Booo'); goto aaaaaaaaaa; end. [/scar] Quote Link to comment Share on other sites More sharing options...
FHannes Posted November 19, 2012 Share Posted November 19, 2012 You should use labels with goto's only if you've exploited every other possibility... So essentially, pretty much never. Quote Link to comment Share on other sites More sharing options...
Incommodious Posted November 19, 2012 Author Share Posted November 19, 2012 i like that skit haha. But the easiest way to put it (what i need), is basicly a relogtimer for reloging. When the timer is up (say 60 seconds) it will restart or do the procedure Relog. I need it to relog to minimize lag in game. Quote Link to comment Share on other sites More sharing options...
FHannes Posted November 19, 2012 Share Posted November 19, 2012 So essentially, if RelogTimer is not 0, wait 60 seconds and then call Relog, then repeat? [scar]Program Relog; var x, y :Integer; const User='no user'; //Username, dont touch to keep relog features off Pass='no pass'; //Password, dont touch to keep relog features off Character=1; //Character 1=Top 2=Middle 3=Bottom RelogTimer=60; //RelogTimer by seconds. Set to 0 for no Timer Procedure Relog; begin Findcolor(x,y,8107462,69,359,161,385); ClickMouse(x,y,true); Wait(100) ClickMouse(412,359,true); Wait(100) TypeText(User); Wait(100) ClickMouse(412,395,true); Wait(100) TypeText(Pass+chr(13)); FindColor(x,y,8109518,380,425,433,443); ClickMouse(x,y,true); Wait(200) ClickMouse(542,141,true); if (findcolor(x,y,10079232,359,312,439,336)) then begin ClickMouse(x,y,true); Findcolor(x,y,8107462,69,359,161,385); ClickMouse(x,y,true); Wait(100) ClickMouse(412,359,true); Wait(100) TypeText(User); Wait(100) ClickMouse(412,395,true); Wait(100) TypeText(Pass+chr(13)); end else begin MoveMouse(542,139) end; if (character=1) then begin Wait(300) ClickMouse(543,142,TMouseLeft); end; if (character=2) then begin Wait(300) ClickMouse(543,267,TMouseLeft); if (character=3) then begin Wait(300) ClickMouse(543,388,TmouseLeft); end; end; end; begin repeat if RelogTimer = 0 then Exit; Wait(RelogTimer * 1000); Relog; until False; end.[/scar] Quote Link to comment Share on other sites More sharing options...
Incommodious Posted November 19, 2012 Author Share Posted November 19, 2012 (edited) Not only 60 seconds cause it will be in the setting of the script for users to change to their liking. I started to use the script LordJashin posted at the top ^^^ and then started to changed it a lot and seems like its working by saying 'Reloging....' but instead of saying that I can just put the relog script that I posted into that line. Does this seem like it would work? [scar]program TimerTest; var t, i :Integer; const Timer=5; procedure Booo; begin repeat i:=1 t:=(i + timer*1000) WriteLn('Reloging....'); // Instead of using this as WriteLn I will just put my whole Relog script that i already have into this wait(t) until (t>timer); Booo // then replace this with the my reloging procedure name end; begin Booo; end.[/scar] EDIT: And if the timer is 0 then the reset is diactivated [scar]program TimerTest; var t, i :Integer; const Timer=5; procedure Booo; begin if Timer=0 then Exit; begin repeat i:=1 t:=(i + timer*1000) WriteLn('Reloging....'); wait(t) until (t>timer); Booo; end; end; begin Booo; end.[/scar] Edited November 19, 2012 by Incommodious Quote Link to comment Share on other sites More sharing options...
LordJashin Posted November 19, 2012 Share Posted November 19, 2012 You can use timing functions as well. For instance: This will stop running if 5 seconds has passed: [scar] program aaa; var i: Integer; begin i := GetTimeRunning; Repeat wait(1000); WriteLn('boo'); until (GetTimeRunning > i + 5000); end. [/scar] You have to remember what you can do in SCAR. You can have global variables for people to set at will within a setup procedure. Or never changing constants. Variables can change while the script is running. Now here's an example where you can change this "Time to repeat the script thing". [scar] program aaa; const TimeToRunScript = 60; // In seconds var i: Integer; begin i := GetTimeRunning; Repeat wait(1000); WriteLn(GetTimeRunning); until (GetTimeRunning > (TimeToRunScript * 1000)); WriteLn('Time Running now minus the time we got at the beginning in milliseconds: ' + IntToStr(GetTimeRunning - i)); end. [/scar] Quote Link to comment Share on other sites More sharing options...
FHannes Posted November 19, 2012 Share Posted November 19, 2012 (edited) Not only 60 seconds cause it will be in the setting of the script for users to change to their liking. EDIT: And if the timer is 0 then the reset is diactivated Did you even look at what I posted? I wait "RelogTimer seconds" before relogging, and don't relog is RelogTimer is 0. The 60 seconds is an example obviously... As you set this as default. Edited November 19, 2012 by Freddy Quote Link to comment Share on other sites More sharing options...
Incommodious Posted November 20, 2012 Author Share Posted November 20, 2012 Ok well i took a break from scripting for a little bit and when I came back today I made the script work 100% for the Timer part of it. But i started to make some changed inside the script and im getting the Error "Variable Expected". Also when you find why its wrong can you make a note saying what was wrong so I can watch out not to do that again in the future. Also another little thing I think would be nifty is when the timer is counting down can you make it write it out in the debug box? [scar]Program Relog; var i, t, x, y :Integer; const User='account99'; //Username, dont touch to keep relog features off Pass='password'; //Password, dont touch to keep relog features off Character=1; //Character 1=Top 2=Middle 3=Bottom RelogTimer=20; //RelogTimer by seconds. Set to 0 for no Timer Procedure Relog; begin repeat i:=1 t:=(i + RelogTimer*1000) ClickMouse(600,58,false); Wait(250) ClickMouse(326,228,false); Wait(500) Findcolor(x,y,8107462,69,359,161,385); Wait(500) ClickMouse(x,y,false); Wait(200) ClickMouse(412,359,false); Wait(100) TypeText(User); Wait(100) ClickMouse(412,395,false); Wait(100) TypeText(Pass+chr(13)); Wait(500) FindColor(x,y,8109518,380,425,433,443); ClickMouse(x,y,false); Wait(200) ClickMouse(542,141,false); if (findcolor(x,y,10079232,359,312,439,336)) then begin ClickMouse(x,y,false); Findcolor(x,y,8107462,69,359,161,385); ClickMouse(x,y,false); ClickMouse(412,359,false); Wait(100) TypeText(User); Wait(100) ClickMouse(412,395,false); Wait(100) TypeText(Pass); Wait(250) ClickMouse(407,436,false); end else begin WriteLn('Lets Login!'); end; if (character=1) then begin Wait(300) FindColor(1959605,505,134,530,154); ClickMouse(x,y,false); end; if (character=2) then begin Wait(300) FindColor(1959605,508,258,528,276); ClickMouse(x,y,false); if (character=3) then begin Wait(300) FindColor(1959605,507,382,530,401); ClickMouse(x,y,false); end; end; wait(t) until (t>RelogTimer); Relog; end; begin GetClient.Activate wait(1000) Relog; end. [/scar] Quote Link to comment Share on other sites More sharing options...
Janilabo Posted November 20, 2012 Share Posted November 20, 2012 (edited) You forgot to add X, Y coordinate variables to FindColor's. Click the error message in Messages tab and it will show you the problematic line. Also, here is your script with standards + using CASE statements: program Relog; const User = 'account99'; //Username, dont touch to keep relog features off Pass = 'password'; //Password, dont touch to keep relog features off Character = 1; //Character 1=Top 2=Middle 3=Bottom RelogTimer = 20; //RelogTimer by seconds. Set to 0 for no Timer procedure Relog; var i, t, x, y: Integer; begin repeat i := 1; t := (i + RelogTimer * 1000); ClickMouse(600, 58, False); Wait(250); ClickMouse(326,228,false); Wait(500); Findcolor(x, y, 8107462, 69, 359, 161, 385); Wait(500); ClickMouse(x, y, False); Wait(200); ClickMouse(412, 359, False); Wait(100); TypeText(User); Wait(100); ClickMouse(412, 395, False); Wait(100); TypeText(Pass + Chr(13)); Wait(500); FindColor(x, y, 8109518, 380, 425, 433, 443); ClickMouse(x, y, False); Wait(200); ClickMouse(542, 141, False); if (FindColor(x, y, 10079232, 359, 312, 439, 336)) then begin ClickMouse(x, y, False); FindColor(x, y, 8107462, 69, 359, 161, 385); ClickMouse(x, y, False); ClickMouse(412, 359, False); Wait(100); TypeText(User); Wait(100); ClickMouse(412,395,false); Wait(100); TypeText(Pass); Wait(250); ClickMouse(407, 436, False); end else begin WriteLn('Lets Login!'); end; case character of 1: begin Wait(300); FindColor(x, y, 1959605, 505, 134, 530, 154); ClickMouse(x, y, False); end; 2: begin Wait(300); FindColor(x, y, 1959605, 508, 258, 528, 276); ClickMouse(x, y, False); end; 3: begin Wait(300); FindColor(x, y, 1959605, 507, 382, 530, 401); ClickMouse(x, y, False); end; end; Wait(t) until (t > RelogTimer); Relog; end; begin GetClient.Activate; Wait(1000) Relog; end. -Jani Edited November 20, 2012 by Janilabo Quote Link to comment Share on other sites More sharing options...
Incommodious Posted November 20, 2012 Author Share Posted November 20, 2012 Why Case statements instead of If Then statements? Quote Link to comment Share on other sites More sharing options...
Janilabo Posted November 20, 2012 Share Posted November 20, 2012 Why Case statements instead of If Then statements?Keeps it cleaner + its easier to add more stuff in it. Quote Link to comment Share on other sites More sharing options...
Incommodious Posted November 20, 2012 Author Share Posted November 20, 2012 I see i went to the Scar guide and it says this: Case statements allow you to replace a big amount of if..else statements when using some basic types. The logic of this construct is very simple, you examine a value and then simple check if it matches different cases and provide a code block to execute for each case. You can also execute a single code block in several different cases. It makes more sense using a Case statements. If you have 2+ If Then statements should u make it a Case or keep it a If Then or should it be 3+? Quote Link to comment Share on other sites More sharing options...
Bixby Sayz Posted November 20, 2012 Share Posted November 20, 2012 There is no hard and fast rule. Personally I will use it even just for 2 if it makes my code easier to read and maintain. If it looks more cluttered/is harder to read with the case then I'll stick with the if/then/else structure. In the end it boils down to personal preference. Quote Link to comment Share on other sites More sharing options...
LordJashin Posted November 20, 2012 Share Posted November 20, 2012 I see i went to the Scar guide and it says this: It makes more sense using a Case statements. If you have 2+ If Then statements should u make it a Case or keep it a If Then or should it be 3+? On your endeavor of scripting with SCAR you will basically be learning the fundamentals of programming and computers. In the computer world, to know how things work is paramount. Programmers make programs that non programmers can use if they know how to. Changing the world as we know it, for the longest time now computers have impacted industry, and then the world with these programs. From the first internet brokerage programs to 3D to HD Nvidia uber graphics games. For SCAR, the rule is that whatever is smaller when coding is best to use usually. But sometimes, get lazy with that. Like a case statement might be less lines then an if then statement. Quote Link to comment Share on other sites More sharing options...