StrokesPlus.net Forum
»
General Discussion
»
Scripts
»
About sp.StoreHistoryScript, it always fails to run
Rank: Advanced Member
Groups: Approved
Joined: 9/26/2018(UTC) Posts: 73 Location: 北京 Thanks: 18 times Was thanked: 1 time(s) in 1 post(s)
|
Hello, Rob: I want to use sp.StoreHistoryScript loop to run history script. But it always fails. Can you give an example of sp.StoreHistoryScript? Thank you
sp.Sleep(500); sp.StoreHistoryScript('test', timer); for (i=99; i>=1;i--){ sp.Sleep(500); sp.ExecuteStoredScript('test'); }
|
|
|
|
Rank: Administration
Groups: Translators, Members, Administrators Joined: 1/11/2018(UTC) Posts: 1,359 Location: Tampa, FL Thanks: 28 times Was thanked: 419 time(s) in 356 post(s)
|
HistoryScript and StoredScripts have very special uses which don't appear to fit your situation.
What is "timer" in your example?
Can you give me a more thorough explanation of what you are looking to accomplish?
You can store scripts as strings and eval to execute. You can also create functions to call repeatedly. There's also sp.CreateTimer to execute scripts repeatedly.
|
|
|
|
Rank: Administration
Groups: Translators, Members, Administrators Joined: 1/11/2018(UTC) Posts: 1,359 Location: Tampa, FL Thanks: 28 times Was thanked: 419 time(s) in 356 post(s)
|
Quote:I just want to loop through the latest history script To store a history script, you have to first use sp.GetHistoryScript to get the HistoryScript object. In this snippet, timer doesn't appear to be defined anywhere: Code:sp.StoreHistoryScript('test', timer);
Another issue is that if sp.ExecuteStoredScript (and sp.ExecutePreviousScript) is anywhere in a script, the entire script is replaced with the requested script. So your entire script: Code:sp.Sleep(500);
sp.StoreHistoryScript('test', timer);
for (i=99; i>=1;i--){
sp.Sleep(500);
sp.ExecuteStoredScript('test');
}
Becomes only: Code:sp.ExecuteStoredScript('test');
But of course, there is no stored script named 'test' because that's never been executed (because it was replaced with just sp.ExecuteStoredScript('test');). This is because a HistoryScript object contains all data relating to the script environment, so it replaces the current script with the environment and script from the specified HistoryScript object. If the environment aspects of the last script are not important, or if you handle those independently within your loop, you can simply get the last script and use eval to execute just the script portion only: Code:sp.Sleep(500);
var lastScript = sp.GetHistoryScript(0); //Get last script
for (i=99; i>=1;i--){
sp.Sleep(500);
eval(lastScript.script); //Execute script property from the last HistoryScript
}
The environment means everything about the state when the script was executed, such as the location of the start and end of the gesture, the action.Window object, etc. So if those are not critical for the last script to execute, or if you manually store them first, then restore those variables in the for loop, the above should work fine. Edited by user Tuesday, January 26, 2021 2:14:51 PM(UTC)
| Reason: Not specified
|
|
|
|
Rank: Administration
Groups: Translators, Members, Administrators Joined: 1/11/2018(UTC) Posts: 1,359 Location: Tampa, FL Thanks: 28 times Was thanked: 419 time(s) in 356 post(s)
|
This would restore the environment of the previous script: Code:sp.Sleep(500);
var lastScript = sp.GetHistoryScript(0); //Get last script
for (i=99; i>=1;i--){
sp.Sleep(500);
//Restore previous script execution environment variables
action = lastScript.action;
click = lastScript.click;
wheel = lastScript.wheelTick;
floater = lastScript.floater;
//Execute script property from the last HistoryScript
eval(lastScript.script);
}
|
|
|
|
Rank: Advanced Member
Groups: Approved
Joined: 9/26/2018(UTC) Posts: 73 Location: 北京 Thanks: 18 times Was thanked: 1 time(s) in 1 post(s)
|
Thank you Rob.It works perfectly on my computer.
|
|
|
|
StrokesPlus.net Forum
»
General Discussion
»
Scripts
»
About sp.StoreHistoryScript, it always fails to run
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.
Important Information:
The StrokesPlus.net Forum uses cookies. By continuing to browse this site, you are agreeing to our use of cookies.
More Details
Close