Is there a way to check programmatically whether the FrontEnd considers evaluation still running?
Or even better: is there a way to check whether the FrontEnd has some pending inputs to be sent to the kernel?
P.S. This question has arisen from previous question.
EDIT
When evaluating a Cell in the FrontEnd we usually create a queue of inputs for the kernel.
I need a function that will return True if the FrontEnd has sent to the kernel the last input of the queue of inputs from the EvaluationNotebook[]. Or in other words I need a function that returns True if this current input is the last input of the queue of inputs generated by the FrontEnd.
This should work. Of course, you have to run it in a different kernel than the one that is performing the evaluation you want to check for.
NotebookEvaluatingQ[nb_] := (
SelectionMove[nb, All, Notebook];
Or ## Map["Evaluating" /. # &, Developer`CellInformation[nb]]
)
Obviously, it's best to set things up before hand using a tool like Monitor. For example,
Monitor[
Do[Pause[6], {i, 10}],
i]
will allow you to observe the progress of the index variable i. If you haven't set things up before hand, you might be able to do something using the "Interrupt Evaluation" button under the Evaluation menu. For example, try the following:
Do[Pause[6], {i, 10}]
Now, wait six or more seconds and then select "Interrupt Evaluation". You can then examine the state of i to see how far along it is. You resume evaluation using Continue under "Debugger Controls".
Related
I've altered one of the popular clock skins for Rainmeter to be exactly how I want it. However, the only issue is that the '1' in the clock for hours 10, 11, and 12 gets cut off by the edge of the skin with the current margins.
I know exactly which value needs to be altered at the given times, so all I need to figure out now is how to run a Lua script to change it when the clock hits them. Problem is, after much searching I don't have the slightest clue how. It definitely seems like something that should be easily possible.
You need to run your lua script as a cron job.
In order to achieve this I'd suggest you use this cron.lua module which has the functionality you want. One example of what you can do is the following:
local clock = cron.every(time, callback, ...).
--Creates a clock that will execute callback every time, periodically. Additional parameters are passed to the callback too.
The callback variable is the code you want to be executed at every interval.
I want to send "call_language" variable from main IVR to second one. I am using blind transfer to connect this two IVR's. For both of them I have two different VDN's. Right now, the connection is going as illustrated in a picture. After transfer, main IVR goes to "SM"(Session Manager) and then to "CM"(Communicatin Manager). In "CM" it looks for VDN and then goes back to "Experience Portal" through "SM", where it finds the corresponding VDN, and transfers to second IVR.
1)Is there a way to send a variable from main to second IVR?
2)Is there a way to connect these two IVR's directly, without going back to SM and CM?
You stated the requirements as passing the chose language but not the whole context, so I give you my wild guesses:
You can have a key-value pair store. The first script sets the
chosen language as value, the key is the UCID. The second script
reads the value from the store with the key UCID. Since the call
does not leave the CM the UCID should be the same for the whole
time.
If the goal is to have the second script to speak the language the caller chose in the first one then you can use several VDN-s for it. For example the use chose 1 [en] then you transfer the call to VDN 2001. If the use chose 2 [de] then you transfer to 2002. For both VDNs the same script starts but it can decide which language to use.
You can start the second script from the first directly but you need to use hooks and some hacking in the source code so this is the most complex and needs the knowledge.
So for our computer science class, we had to write a program that randomly generates cards, i decided to do mine in batch, because im a massive noob XD
I was confident that i could do it as im quite experienced with it. Even though batch isn't by any means a good 'language' if your going to call it that. I was able to fix most of the problems by myself with some hard work. I am however, still having some issues i don't know how to resolve.
My biggest issues i don't know how to fix are...
Text not being displayed properly.
Numbers (i use for the base of the AI and card generation) sometimes not being defined properly in variables.
The point system just refuses to work not matter what i do.
It sometimes randomly just flat out decides to crash on me if i skip a 'TIMEOUT' or a 'PAUSE'.
Some 'IF' statements not being executed properly even though there exactly the same as the other ones.
I'm sorry if this question is too broad, but i really didn't know quite how to summarize it.
Here is a link to my card game: http://pastebin.com/t2S3yWk5
Here is our question:
1) Create a program that will generate two random numbers - one that maps to a suit (hearts,diamonds, clubs or spades) and one that maps to a card (Ace, 2, 3, ..... Jack, Queen, King)
*Mine is slightly different, it generates two different suits based on two random numbers.*
2) Create a program that will generate a random card and then ask the user to go Higher,Lower or Quit. If the player chooses Higher the next card must be of a higher value or theplayer is out. Likewise for Lower.
3)Extending the previous program, the user will select a trump suit at the start of the game. If the card is a trump suit card then the game continues regardless of the card’s value. The program will keep score and will save the score to a highscore file. The user will also be able to display the current highscore file.
I would like to try and do this stuff (listed above) myself. I just need help trying to fix my existing program.
I hope that if your reading this you could give me some advise or provide solutions to some of my problems. Thanks in advance! :3
Good news; nothing is super wrong with your code, it's just a bunch of little things that seem like a lot. Some off-by-one errors and a missing variable that I can only assume got replicated from copying and pasting.
Text not being displayed properly
I assume this is the "Access denied" errors that your code produces instead of the AI's comments. This is due to the fact that > and < are used for output redirection, so the emoticons you are adding are trying to create a file in a place you don't have access to. Either get rid of them (recommended) or use ^ to escape them (^>:)).
Numbers (I use for the base of the AI and card generation) sometimes not being defined properly in variables
%random% %% 5 results in one of the numbers in the set 0, 1, 2, 3, 4. You currently do not have an if statement for what should happen if 0 is randomly selected. Add an if statement or have the code go back to the top of the section if a 0 is selected.
The point system just refuses to work no matter what I do
You're going to kick yourself...
Your set statements are missing the assignment portion. SET /A %p1p% + 2 should be SET /A p1p=%p1p% + 2 and so forth (or set /a p1p+=2 if you think that looks better).
If sometimes randomly just flat out decides to crash on me if I skip a 'TIMEOUT' or 'PAUSE'
I couldn't replicate that, but the code seemed to work fine when I removed those statements.
Some 'IF' statements not being executed properly even though they're exactly the same as the other ones
Your comment indicated lines 119-132, which include the if statements that assign points. See above for why those aren't working.
Some other recommendations for your code
Your variable names should be more descriptive. For example, ctog doesn't tell me anything about what that variable should be; I can look at the code to see what it does, but without any context, that could be doing anything.
You should add the /i flag to the if statements that check which card you put down so that C1 and c1 get treated the same. On a related note, you should add a check for when the player enters something other than C1 or C2. You can even use a choice command like you did earlier.
:pvic is missing an exit command, so you automatically play again if you win. Combined with the fact that you only check if lt is equal to 2, not greater than or equal to 2, there's no way to stop playing if you win. Also on the subject of end game conditions, there's no if statement for if you tie the computer.
cp1 and num1 are effectively the same variable, there's no reason to have both (same with cp2/num2, ap1/num3, and ap2/num4).
You need some kind of goto at the end of :pc1 so that :pc2 doesn't automatically run after :pc1 finishes.
I'm writing an interpreter for a game. User enters its move to the interpreter and program executes that move.
Now I want to implement a time limit for each decision. Player shouldn't be able to think more than 30 seconds to write a move and press enter.
call_with_time_limit seemed relevant but it doesnt work properly as such:
call_with_time_limit( 30, read(X) ), Problem, write(Problem).
In this case, it waits for input, and when input is entered, timer starts afterwards. But I want the timer to start at the beginning.
How can I do it?
If you are interested in I/O related timeouts please consider wait_for_input/3 or set_stream/2. The built-in you found, call_with_time_limit/2 is not a simple and reliable interface.
Edit: I just see that you use read/1 for input. Please read in above documentation how to avoid blocking in read/1. It is not clear to me why you need this, but a user might simply enter Return, thereby circumventing the initial timeout. read/1 would now read that '\n' but then would wait for further input - without a timeout, while the user lavishly skims Wikipedia for the answer... might even ask the question on SO...
Your approach seems sensible: from the SWI-Prolog docs: 'Blocking I/O can be handled using the timeout option of read_term/3. '.
That's not really informative: changing timeout on user leads to some bug (I'll test more and will report to SWI_prolog mailing list if appropriate), even under catch/3.
The following seems to work
...,
current_input(I),
wait_for_input([I], A, 30),
...
If not input given (shorter time to test here...)
?- current_input(I), wait_for_input([I],A,5).
I = <stream>(0x7fa75bb31880),
A = [].
EDIT: the variable A will keep the list will contain the list of streams with ready input: I just reported the case where the user doesn't input anything before the timeout occurs. To get the actual input, using your supplied code:
tql :-
current_player(I),
writef('Its %d. players turn: ', [I]),
flush_output,
current_input(Input),
wait_for_input([Input], [Input], 5),
read(Input, Move),
writeln(Move).
current_player(1).
HTH
In answering this question, I suggested that the OP open a stream at the beginning of his notebook and close it at the end. However, if an Abort is generated, the stream will be left open, and will cause havoc if they attempt to open it again without checking first. If the stream was only required for a single function, the solution would be straightforward, but it's required for the entire notebook. Obviously, a check can be added to see if the stream is already open, but is there a way to tie into the global Abort handler so that this type of problem can be handled globally?
Edit: to be specific, I'm looking for a way to run arbitrary code when an Abort occurs whether, or not, the code is currently running inside of CheckAbort. Essentially, I'd like to set a global Abort handler, if possible. If this exists at the notebook level, then even better.
As an alternative, and if you want to localize the effect to a single notebook, you can do something along these lines:
SetOptions[EvaluationNotebook[],
CellEvaluationFunction ->
(ToExpression[#, StandardForm,
Function[
Null,
Module[{aborted = $Aborted},
Internal`WithLocalSettings[
Null,
aborted = (ReleaseHold[Most[Hold[##]]];Last[Hold[##]]),
AbortProtect[
If[aborted === $Aborted,
Print["Did cleanup"]; Abort[]
]]]],
HoldAll]] &)
]
NOTE: rewritten to incorporate the suggestion of #Alexey
NOTE 2 Modified to accommodate several inputs in a single cell. In that case, all outputs but the last are suppressed
where you replace the Print["Did cleanup"] code with whatever cleanup code you have.
A very simple way would be to issue the following at the start of the file:
Close /# Streams[] // Quiet
The standard streams stdout and stderr cannot be closed and you silence the warning with Quiet. However, this also assumes that you don't have any open streams that you care about.
To handle an Abort and close the stream, you can modify $Post like:
$Post := If[# === $Aborted, Close[strm], #] &
where strm is the stream that you opened.