Why is type not exiting correctly? - sikuli

I am trying get Sikuli to open a chat window in a game(using t) and then close it without typing anything in (using enter).
But when I run the script Sikulu opens the menu and then types tt, then it closes the menu.
I put a delay of 1 second in between the type t and type enter in case it was running too fast but it did not help.
while True:
type("t")
sleep (1)
type(Key.ENTER)

I don't understand why are you running this in a loop. If you want to perform 2 actions:
Open chat (by hitting "t")
Close chat (by hitting "t")
Just do it outside the loop, simply like this:
type("t")
#some delay to ensure the menu has opened
type("t")
The proper way to do that though is to implicitly wait for the menu to appear. So if you can define a pattern that you can use as a reliable indicator, use it like this:
type("t")
wait(pattern, waitTime)
type("t")

Related

How can I run a command from inside another stack command?

I have a callback handler in a stack that looks for telemetry data. When it gets some, I parse it and then want to save it. However, to save it requires other functions and commands in the same stack.
I could put it on the card, but where? I use the openCard end openCard and that's about it in the card.
The stack has all the functions and commands I need. There's no button to press to run the save code - I need it to run automatically.
How can I put the chunk of code on the card and then have the stack 'call it'?
I know how to call commands from the card, but not from the stack.
Generically, you simply call either a command handler or a function handler in-line:
on mouseUp -- a "main" handler
doSomething -- a command handler
dosomethingElse -- another command handler
put doYetAnotherThing(paramList) into field 1 -- a function handler
end mouseUp
on doSomething
well, do something
end doSomething
on doSomethingElse
you get the picture
...
Try making a simple main handler that does silly trivial things for each of the three "subRoutine" calls above. You will be an expert in a matter of hours.
The placement of the three has to be managed. Generally, they reside in the script where the main handler lives. But they can be anywhere in LC.
If you want to call a handler in a card (or any other control) from another script, you can use one of the following commands:
dispatch "command" to control with param1, param2, …
send "command" to control [in time]
put value(command, control) into tResult
Dispatch happily continues even if the command isn't handled by the control. You can check that of course.
Send has the advantage that you can schedule the sending forwards in time, but is a bit harder if you want to also send some parameters.
Value is good candidate if you call a function and want the result back.
Note that ""openCard" and "preOpenCard" messages can be trapped and worked in the stack script, as long as there are no such handlers in the card script. And even if there are, you can "pass" each message after the card script handler is done with it";
Try creating a command on the stack that is called every X times while the user is on that card. This command must be called to itself and to the other manipulators that you use to obtain the data. This same manipulator will be in charge of saving the data.
# Code on the card
local sTelemetryData
on openCard
// If the card belongs to the pile where all the telemetry is or if this pile is a library.
getTelemetryData
// otherwise you will have to call the getTelemetryData command. You can use send, disparsh, or call.
// call "getTelemetryData" to stack "stack name"
end openCard
# Code on the stack
constant kTime = 100
local sPendingMessageID
on getTelemetryData
if the short name of this card is not "TelemetryData"
then exit getTelemetryData
if sPendingMessageID is a number
then cancel sPendingMessageID
// call the commands and functions that look up the telemetry data.
// The data must be stored in the sTelemetryData variable to save it and at once use this variable as a flag
if sTelemetryData is not empty then
// The data is sent to be saved
end if
put empty into sTelemetryData
send "getTelemetryData" to me in kTime milliseconds
put the result into sPendingMessageID
end getTelemetryData

How do I use a function from one lisp file to solve for something in another lisp file?

I'm new to lisp and my professor gave some .lisp files to play around with.
http://pastebin.com/eDPUmTa1 (search functions)
http://pastebin.com/xuxgeeaM (water jug problem saved as waterjug.lisp)
The problem is I don't know how to implement running functions from one file to solve problems from another. The most I've done is compiled functions from one file and played around with it in the terminal. I'm not sure how to load 2 files in this IDE as well as how I should run the function. I'm trying, for example, to run the breadth-first-search function to solve the problem to no avail.
I'm currently using emacs as the text editor SBCL as the common lisp implementation along with quicklisp and slime.
Assuming each file is in its own buffer, say f1.lisp and f2.lisp, then you only have to call slime-compile-and-load-file when you are in each buffer. This is bound by default to C-c C-k. You have to compile the first file first, because it contains definitions for the second one.
But, your second file (f2.lisp) has two problems: search for (break and (bread and remove those strings. Check if the forms around them have their parenthesis well balanced.
Take care of warning messages and errors while compiling your file.
Then, if you want to evaluate something directly from the buffer, put your cursor (the point) after the form you want to evaluate, and type C-x C-e (imagine the cursor is represented by % below):
(dump-5 (start-state *water-jug*))%
This will print the result in the minibuffer, in your case something like #<JUG-STATE {1004B61A63}>, which represents an instance of the JUG-STATE class. Keep a window open to the REPL buffer in case the functions write something to standard output (this is the case with the (describe ...) expression below).
If instead you do C-c I, this will ask you which expression you want to inspect, already filled with the form before the point. When you press enter, the inspector buffer will show up:
#<JUG-STATE {1004BD8F53}>
--------------------
Class: #<STANDARD-CLASS COMMON-LISP-USER::JUG-STATE>
--------------------
Group slots by inheritance [ ]
Sort slots alphabetically [X]
All Slots:
[ ] FIVE = 0
[ ] TWO = 2
[set value] [make unbound]
Read http://www.cliki.net/slime-howto.

How to redirect Octave's console output to a separate console?

If I have a function that displays a large amount of output, is there a way to display it all in the terminal separately (maybe using more or less), such that, upon exiting the pager, I get the Octave's console as is?
Like so:
octave:159> retVal = func_with_lotsa_output();
octave:160>
I seem to remember a previous version of Octave doing that by default (I'm currently on 3.8.1). Right now, the output is displayed before getting the prompt at line 160 (in between 159 and 160, that is).
I tried fiddling with PAGER, but to no avail.
EDIT: I've tried PAGER("more"), PAGER("less"), PAGER("pg"). I am unsure of what flags to try in PAGER_FLAGS(). Nothing has made a difference.
"When I exit the pager, I don't want to see the pager's output lying there."
Either your pager is broken, or you just need to activate the pager, with
page_screen_output(true)
or equivalently
more on
which, according to the documentation,
Turn output pagination on or off. Without an argument, more toggles the current state. The current state can be determined via page_screen_output.
If it still does not work, try with the "less" pager:
PAGER("less")

How to use do in lisp?

What I'm trying to do is to write a function that which will restart a game of tic-tac-toe after it ends.
What is supposed to happen is that the player will be asked if they want to play another game. If they do, then they click yes and a function is called that will start the game over. If they choose no, then the program terminates.
Here is what i have so far...
(defun play-again ()
(do (y-or-n-p "Would you like to play again? ")
((play-one-game) nil)))
The play-one-game is the function that i want to run if the user clicks"yes" from the prompt. Otherwise the game terminates since no other function is called. By the way, just in case you need to know, i am using Allegro.
Assuming your y-or-n-p nil only when the user pressed n you could write your main loop as
(defun main ()
(loop :while (y-or-n-p "Would you like to play again? ")
:do (play-one-game)))
or at the end of play-one-game, which I would rename play, prompt the user and if he wants to play again just call play one more time.
(defun play-one-game ()
....
(when (y-or-n-p "Would you like to play again? ")
(play-one-game)))
If you don't understand a form in CL you should read in the CLHS (http://www.lispworks.com/documentation/lw60/CLHS/Body/m_do_do.htm)
Here a solution using do:
(defun play-again ()
(do ((again t (y-or-n-p "Would you like to play again? ")))
((not again) nil)
(play-one-game)))
(this function calls play-one-game the first time without a question)

How do I put delay/sleep between executing two external programs using pascal?

I have code like:
begin
RunProgram:=TProcess.Create(nil);
RunProgram.Commandline:='calc.exe';
RunProgram.Execute;
RunProgram.Commandline:='notepad.exe';
RunProgram.Execute;
RunProgram.Free;
end.
and I would like to put a sleep or delay after executing calc.exe
You had the right idea - it's Sleep.
begin
RunProgram:=TProcess.Create(nil);
RunProgram.Commandline:='calc.exe';
RunProgram.Execute;
Sleep(1000); // Adds a 1 second delay
RunProgram.Commandline:='notepad.exe';
RunProgram.Execute;
RunProgram.Free;
end.
You may need to add the Windows unit (or possibly a different one - I'm not familiar with FreePascal's unit arrangement) to your uses clause to be able to compile the Sleep function.