I was working on the AppleScript below and I was wondering if there is a way to make a repeat, repeat a variable amount of times. Here's what I tried to do but it didn't work. Does anybody have a solution? Thanks!
tell application "System Events"
set blue to 1
repeat blue times
keystroke "s"
end repeat
set blue to blue + 1
end tell
Related
I am working on a game in Corona (with Lua) where the player colours in a plant and then adds it to a box. once the player has made enough plants a dinosaur walks over and eats the plants. after which the dinosaur is supposed to change colour filtering through the colours used to colour in the plants.
-- this creates a loop that will cycle through the table "RecentColours" and "change the dinosaurs colour each time and" then stop on the last colour used
X=1
--changes dino colour
for ListColors = 1, #RecentColours do
Colour = RecentColours[X]
Dino:setFillColor(unpack(Colour))
X = X + 1
print(unpack(Colour))
--sets CurrentColour to the current colour of the dinosaur
CurrentColour = Colour
end
--emptys dinour colour list
for ListColors = 1, #RecentColours do
Y = #RecentColours
table.remove(RecentColours,Y)
end
this loop runs for the length of a list of colours but the problem is the dinosaur only changes to the last colour in the list rather then cycleing through all of them
I have tried changing the style of loop but that changed nothing and i have tried a .preformwithdelay event and I have tried putting into its own function.
I have also tested with printing to the console and It definitely adds all the colours to the list and it definitely runs through the whole list as it prints the current part of the table that it's up to
The comments helped greatly and solved the problem. but if you know a way to slow down a loop I would love to know
Ok, here's my use case. I have a form that pulls different parts of the form from a number of tables in a database. Each time I pull the info, I test to make sure there were no errors. Currently I'm using msgbox to show if there are errors, but I'm rewriting the app to instead display these messages in a "status" line area. It's just a label that I write the strings into on the form that flashes the error. This is working great in my single "You did this, and you got an error" forms. But in one of my forms it's about 6 things that could give errors, and it's on load. So it's not a single action, single error type deal.
My idea is to load any errors into an array, then display them one at a time for like 5 seconds each, then loop back and do it again, for at least 5 times. So in effect I want it to show each error, for 5 seconds, then show the next one for 5 seconds, then start over again, for 5 times, then stop.
Problem is, while I've got about 10 ideas on ways to maybe do this, they all seem really complicated and complex (and I don't want to spend 10 hours writing it only to figure out it's not going to work). I'm looking for the "best" way.
So.... Is an array even the best way? Or would a list or some other way be better? I'm looking for ideas here. How would YOU do it?
Eventually, you can use arrays for what you are trying to achieve. This could be done by following the steps :
When you are pulling the information from the tables, check for errors and if there is any, put it into an array.
Define a for loop which is going to loop 5 times
Define another nested loop to loop through the array to display the messages one by one
After each message display, put a sleep or delay of 5 seconds
If you follow these instructions, it just a matter of minutes into writing the codes
I ended up solving this by using a combobox and a list, then just having my combobox blink. On forms that can only throw one error, I use a label instead. Here is the lion's share of my code to do this:
Private Sub ErrorCheck()
If errorList.Count = 1 Then
ErrorComboBox.Visible = True
DismissErrorButton.Visible = True
For Each errors As String In errorList
ErrorComboBox.Text = (errors)
Next
ErrorBlinkTimer.Enabled = True
ElseIf errorList.Count > 1 Then
ErrorComboBox.Visible = True
DismissErrorButton.Visible = True
ErrorComboBox.Text = "There were errors, click drop down to view!"
For Each errors As String In errorList
ErrorComboBox.Items.Add(errors)
Next
Else
End If
End Sub
What I do is after each thing in a SUB that can throw errors, I have it collect the error and write it to errorList with errorList.add like so:
Catch ex As Exception
Dim errorStr = "An Error Occurred in " & Me.Name & " writing into the OpenEvents table " _
& "for setting the Alert radio button."
log(errorStr & " - " & ex.Message)
errorList.Add(errorStr)
the log function is a custom function for writing off to the log, but the rest is standard VB.net stuff. As you can see, if I get any exception (I do the same thing with each query too) it writes the error off to the errorList, then flashes the combobox with the error(s). I have some more logic to make it all nice and pretty, but you get the idea.
at the end of each sub that CAN throw errors, I just have it call:
ErrorCheck()
and like magic, if there were any errors a combobox list appears with bright red flashing text to let them know. If they click it, and there is more than one error, they can see them all in a nice list. Clicking it also makes it stop flashing, cause that would be annoying... LOL
This ended up working much better overall really, but it's not quite as pretty as my first way of doing it... but, no matter what I did, it caused issues on the form(s) to have it running through the flashing loop 5x's to display each error one after the other. I had found work arounds for most of it, but there was still a performance impact, so I dumped it for this. And it does the job well enough.
I'm currently learning LabView in college and I saw this simulated there on class notes. I've been absent the day this has been asked:
I asked my friends, but no one explained well. All they said: do not forget that when the user inputs a number to the control on front panel, he needs to press outside or enter to take effect.
Can anyone explain to me in detail the function of this program from logic design and user perspective?
There is a while loop that is controlled by the "stop 2" button. Within that outer while loop is a sequence structure that contains 3 frames.
Frame 1. A while loop that continuously samples the control named "x", adds five to the value of "x" and puts the result in the indicator named "x+y". If the user presses the stop button, the program will exit the while loop and move to the next frame for execution.
Frame 2. Pause for 10000 milliseconds.
Frame 3. After the pause, a local variable reads the value of the "x" control and writes it to an indicator named "x2"
This will repeat while the "stop 2" button is in a false state.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I'm making a pairs game. The users can click and match pairs which is working great. However, I'd like to add a timer. I'm not sure how to do this.
I already have a button "start" which is used to start and reset the game. I've added a field "counter" which I'll use to display the time. I'm just not sure how to make a timer work without blocking the game play.
Considering this is a game I would expect you're wanting to display the seconds and end the game after a certain period of time.
LiveCode has great syntax for this. The 'send' command lets you send messages in a designated amount of time. For example:
send "handlerName" to target in 1 second
So applying this principle allows us to create timers in a couple of lines of script
local sSeconds
on countSeconds
add 1 to sSeconds
send "timerIncrease" to me in 1 second
end countSeconds
This example will count forever so might not be that useful!
You described a simple game so I would imagine you want to count down from say 60 seconds to 0. When you hit 0, tell the user their time is up.T In your button you could try the following script
local sGameSeconds
local sTimerRunning
on mouseUp
if the label of me is "start" then
set the label of me to "reset"
put true into sTimerRunning
put 60 into sGameSeconds
send "timerRun" to me in 1 second
else
set the label of me to "start"
put false into sTimerRunning
put 60 into field "counter"
end if
end mouseUp
on timerRun
if sTimerRunning is true then
subtract 1 from sGameSeconds
if sGameSeconds < 1 then
put 0 into field "counter"
put false into sTimerRunning
set the label of button "start" to "start"
timerFinished
else
put sGameSeconds into field "counter"
send "timerRun" to me in 1 second
end if
end if
end timerRun
on timerFinished
answer "Time Up!"
end timerFinished
It isn't entirely clear what you are asking. You write that you want a timer, but you don't say what you want to use it for. Neither do you say if you want this timer to actually display the time or if you just want something to happen after a particular amount of time.
Here's a simple way to display the time:
on showTime
put the long time into fld "Time"
send "showTime" to me in 100 milliseconds
end showTime
By refereshing the time every 100 milliseconds, the time on display is never more than 1/10th of a second off.
Here's an efficient way to display a timer that only shows hours and minutes. It sends a showTime message just in time and uses a minimum of processing power:
on mouseUp
if showTime is in the pendingMessages then
put the pendingMessages into myMsgs
filter myMsgs with "*showTime*"
repeat for each line myMsg in myMsgs
cancel item 1 of myMsg
end repeat
else
showTime
end if
end mouseUp
on showTime
set the itemDel to colon
put the system time into myTime
put myTime into fld 1
put item 2 of myTime into myMinutes
if myMinutes is 59 then
add 1 to item 1 of myTime
if item 1 of myTime >= 24 then
put 0 into item 1 of myTime
end if
put "00" into item 2 of myTime
else
add 1 to item 2 of myTime
end if
convert myTime to seconds
put myTime - the seconds into myTime
send "showTime" to me in myTime seconds
end showTime
You can start the timer by clicking on the button containing the mouseUp handler and you can stop it by clicking the same button again.
If this isn't what you need, please explain more.
I'm a teacher and would like to use Keynote slides as flashcards for spelling. I cannot script and am looking for something to be copy/pasted into Applescript Editor and run from there. I came across the following script in another thread and it is close to what I need.
tell application "Keynote"
tell slideshow 1
show slide 3
show slide 2
show slide 1
show slide 4
end tell
end tell
However, there are two problems for my purposes:
1. It is not a random order and would be tedious to write out for several different presentations of different lengths.
2. There is no control for the length of time each card is shown.
Any advice would be greatly appreciated.
Here is a script that mixes the indexes and wait between each slide
set tdelay to 5 -- seconds -- the length of time each card is shown.
tell application "Keynote"
activate
tell slideshow 1 to repeat with i in my mixIndexes(count slides)
show slide i
delay tdelay
end repeat
end tell
on mixIndexes(n)
set l to {1}
if n is 1 then return l
repeat with i from 2 to n
set end of l to i
set j to some item of l
tell item i of l to set {item i of l, item j of l} to {item j of l, it}
end repeat
return l
end mixIndexes