Rank: Newbie
Groups: Approved
Joined: 1/24/2021(UTC) Posts: 2 Was thanked: 1 time(s) in 1 post(s)
|
im a heavy user of StrokePlus for years.
I have many hotkeys which have similar pattern of scripts.
Is it possibly to create a macro (or something like a function) then I can reuse my scripts across multiple hotkeys?
Thanks
|
1 user thanked szhielelp for this useful post.
|
|
|
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)
|
Sure, there are a few ways to accomplish this. 1. MacrosIn the example below, I've created a category in Macros named Functions. In that category, I've created two macros named Test1 and Test2: Macro: Functions > Test1:Code:sp.MessageBox("Test1", "Test1");
Macro: Functions > Test2:Code:sp.MessageBox("Test2", "Test2");
Then in a hot key or action script, you can pull in those scripts and use the JavaScript function eval to execute them. Code:eval(sp.GetMacroScript("Functions", "Test1"));
eval(sp.GetMacroScript("Functions", "Test2"));
Just make sure to be consider variable scope within eval (research via Google if needed), but for most situations it will behave as you would expect. 2. Global Actions > Load/Unload > LoadThe Load script is run in each script engine and can be used to define global functions or variables available to all scripts. In this example, I've added these functions in the Load script tab: Code:function globalTest1() {
sp.MessageBox("Test1", "Test1");
}
function globalTest2() {
sp.MessageBox("Test2", "Test2");
}
Now from a hot key or action script, they can be called anywhere: Code:globalTest1();
globalTest2();
3. Options > Advanced > External ScriptYou can select an external js file to hold any code, variables, or functions you want and have them available to all scripts. This behaves exactly the same as the Load scripts, but may be helpful for someone who wants to manage the scripts in an external editor, for example. Code://C:\Temp\externalscripts.js
function externalTest1() {
sp.MessageBox("Test1", "Test1");
}
function externalTest2() {
sp.MessageBox("Test2", "Test2");
}
Then in hot key or action script: Code:externalTest1();
externalTest2();
|
3 users thanked Rob for this useful post.
|
|
|
Rank: Newbie
Groups: Approved
Joined: 1/24/2021(UTC) Posts: 2 Was thanked: 1 time(s) in 1 post(s)
|
Cool! This really make my life earlier.
Thanks for the detailed guidance. :)
|
|
|
|
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