This App is No Longer Maintained. Visit the Replacement at StrokesPlus.net

StrokesPlus Forum
                       
StrokesPlus Forum
Home | Profile | Active Topics
Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General Discussion
 General Discussion
 IF EXIST in Strokesplus?
 Forum Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

Daniel

13 Posts

Posted - 06/02/2018 :  23:12:11  Show Profile
I was hoping to create a script in Strokesplus that would do something different depending on whether or not a file existed in a certain folder.

So something like...

IF "Documents/Files/Example.txt" Exists
Do this
else
Move on to next thing

Or even better would be if strokesplus could set a variable within its own memory that it could reference and switch back and forth like in a batch file.

if %variable% = 1
do set variable=2
if %variable% = 2
do set variable=1

The whole point of this script is to act like a toggle where it just switches back and forth between actions. Thank you

Daniel

13 Posts

Posted - 06/02/2018 :  23:30:41  Show Profile
Well I figured out how to use the SetNumberVariable to a limited degree and so here is my simple example toggle script.

if acGetNumberVariable("Test") == 1 then
acSendKeys("Variable 1")
acSetNumberVariable("Test", 2)
else
acSendKeys("Variable 2")
acSetNumberVariable("Test", 1)
end

So this will alternate between typing out "Variable 1" and "Variable 2"
I'm trying to figure out how to have more than 2 toggles. Alternating between potentially 3 states. I'm not sure if I'll actually end up using this information but I want to have it just in case. I'll work on it and get back if I figure it out.

Edited by - Daniel on 06/02/2018 23:53:05
Go to Top of Page

Daniel

13 Posts

Posted - 06/03/2018 :  01:46:19  Show Profile
I'm still learning Lua but there wasn't much I had to change in order to get 3+ states. Just a goto command at the end. So for 3 or more toggles, here is the example.

if acGetNumberVariable("Test") == 1 then
acSendKeys("Variable 1")
acSetNumberVariable("Test", 2)
goto done
end
if acGetNumberVariable("Test") == 2 then
acSendKeys("Variable 2")
acSetNumberVariable("Test", 3)
goto done
end
if acGetNumberVariable("Test") == 3 then
acSendKeys("Variable 3")
acSetNumberVariable("Test", 1)
goto done
end
::done::
Go to Top of Page

Rob

USA
2615 Posts

Posted - 06/05/2018 :  04:20:48  Show Profile  Visit Rob's Homepage
It's very common in programming languages to use if/else if/else (or switch, which Lua doesn't support) blocks for this purpose, see here for Lua's implementation: https://www.lua.org/pil/4.3.1.html

It's also generally considered bad programming to use goto. I mean, for a simple script like this in application processed code, it really isn't a big deal, just mentioning it in case this leads you down the road of programming in some way :)

I haven't tested this, but using if/elseif would look something like this:
if acGetNumberVariable("Test") == 1 then
	acSendKeys("Variable 1")
	acSetNumberVariable("Test", 2)
elseif acGetNumberVariable("Test") == 2 then
	acSendKeys("Variable 2")
	acSetNumberVariable("Test", 3)
elseif acGetNumberVariable("Test") == 3 then
	acSendKeys("Variable 3")
	acSetNumberVariable("Test", 1)
end
Only one condition can be met at any time, or none in this code if none match. Adding an else block before the end would allow you to do something if no other conditions are met, like a catch all.

Also, the reason goto is considered evil by many is that except for some very specific/rare circumstances, a goto is never needed and only serves to make the code harder to read/follow.
Go to Top of Page
  Previous Topic Topic Next Topic  
 Forum Locked
 Printer Friendly
Jump To:
StrokesPlus Forum © 2011-2018 Rob Yapchanyk Go To Top Of Page
Snitz Forums 2000