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.
Related
In game chat start with t key and I want that after pressing t on keyboard my script will be suspend and I will can normally write on chat but if I press enter or esc my script will be unsuspended (esc - close chat, enter - send message on chat).
I have problem with this code:
t::
Suspend On
Loop
{
GetKeyState, state, Enter, P
GetKeyState, state2, Escape, P
if (state = Enter){
Suspend Off
break
}
else if (state2 = Escape){
Suspend Off
break
}
}
return
Main problem with this code is loop which not work, and I don't know how to repair it or replace it something more useful or better solution.
Another problem is t key which work but I must click it 2 times, why? First click suspends script, second click runs chat. I want after clicking 1 time t key chat will run and script will suspend. I want the same with enter and esc, to make 2 functions at the same time (enter - unsuspends script and send message on chat, esc - close chat and unsuspends script)
The problem is with the usage of the (deprecated legacy) GetKeyState command, but I must say, the whole solution could be implemented a lot better.
The output value of the command doesn't contain key names, it contains D for down, or U for up, as stated in the documentation. And also you'd need to "quote" your strings.
And the problem with your T key not working on the first press, is of course because you have a hotkey that is capturing the press of the T key.
To not consume the T key press when the hotkey runs, you want to use the ~ modifier(docs).
But anyway, I think a better implementation would be just that a press of the keys simply suspends/unsuspends.
Like so:
~t::Suspend, On
~Enter::
~Esc::Suspend, Off
As a bonus:
The usage of #IfWinActive(docs) might be desirable so the hotkeys only work when your game is active.
#IfWinActive, ahk_exe ExeOfMyGame.exe
~t::Suspend, On
~Enter::
~Esc::Suspend, Off
#IfWinActive
I change code to this:
~t::
Suspend On
Loop
if (GetKeyState("Enter", "P") || GetKeyState("Escape", "P"))
break
Suspend Off
return
Why? Because in #0x464e code was that problem when I suspended script manually and click enter / esc it unsuspended it, I needed after click T it suspend and only enter / esc will unsuspend it. When I manually suspend it in code which is above enter / esc do not unsuspend it.
I have an AppleScript application that connects to a Numbers spreadsheet.
Within a repeat loop, it records the current date every 10 seconds and updates a spreadsheet cell.
I need a way of stopping the timer, recording the final 'current date' in a different table/cell and quitting the AppleScript application (not Numbers).
This depends on the condition to exit the repeat loop.
You can leave an indeterminate repeat loop with
repeat until / repeat while if the following boolean expression is evaluated to true.
exit repeat at any time.
Here's an example of using a "stay open" application and an idle handler to do what you want without using a repeat loop.
on idle
tell me to activate
set q to display dialog "stop?" buttons {"yes"} giving up after 10
if button returned of q is "yes" then
quit
else
beep --replace with your Numbers stuff
end if
return 10
end idle
on quit
continue quit
end quit
I'm creating a card game in pygame for my college project, and a large aspect of the game is how the game's AI reacts to the current situation. I have a function to randomly generate a number within 2 parameters, and this is how long I want the program to wait.
All of the code on my ai is contained within an if statement, and once called I want the program to wait generated amount of time, and then make it's decision on what to do.
Originally I had:
pygame.time.delay(calcAISpeed(AIspeed))
This would work well, if it didn't pause the rest of the program whilst the AI is waiting, stopping the user from interacting with the program. This means I cannot use while loops to create my timer either.
What is the best way to work around this without going into multi-threading or other complex solutions? My project is due in soon and I don't want to make massive changes. I've tried using pygame.time.Clock functions to compare the current time to the generated one, but resetting the clock once the operation has been performed has proved troublesome.
Thanks for the help and I look forward to your input.
The easiest way around this would be to have a variable within your AI called something like "wait" and set it to a random number (of course it will have to be tweaked to your program speed... I'll explain in the code below.). Then in your update function have a conditional that waits to see if that wait number is zero or below, and if not subtract a certain amount of time from it. Below is a basic set of code to explain this...
class AI(object):
def __init__(self):
#put the stuff you want in your ai in here
self.currentwait = 100
#^^^ All you need is this variable defined somewhere
#If you want a static number as your wait time add this variable
self.wait = 100 #Your number here
def updateAI(self):
#If the wait number is less than zero then do stuff
if self.currentwait <= 0:
#Do your AI stuff here
else:
#Based on your game's tick speed and how long you want
#your AI to wait you can change the amount removed from
#your "current wait" variable
self.currentwait -= 100 #Your number here
To give you an idea of what is going on above, you have a variable called currentwait. This variable describes the time left the program has to wait. If this number is greater than 0, there is still time to wait, so nothing will get executed. However, time will be subtracted from this variable so every tick there is less time to wait. You can control this rate by using the clock tick rate. For example, if you clock rate is set to 60, then you can make the program wait 1 second by setting currentwait to 60 and taking 1 off every tick until the number reaches zero.
Like I said this is very basic so you will probably have to change it to fit your program slightly, but it should do the trick. Hope this helps you and good luck with your project :)
The other option is to create a timer event on the event queue and listen for it in the event loop: How can I detect if the user has double-clicked in pygame?
The flowchart I'm making doesn't look right. I've looked in my textbook for examples, but they don't seem to apply to this particular assignment. The pseudocode is right, because the Java is right, but the flowchart just looks wrong.
In this assignment the program is to display an array of items (iPod, Xbox, etc.) by using an array. The program is to ask the user which items they would like to order. The user is to enter the item. The program displays "In Stock". Then the program replaces the item from the array with an empty string. The program asks the user if they would like to make another order. If the user enters in the same item, the message "Out of Stock" is displayed.If the user enters another item, the same process repeats. (While loop) Entering the the word "No" ends the program.
You can see all this in the pseudocode, I just thought writing it all out might be easier. (Or not, maybe it just took extra work reading it.)
(Click image to enlarge)
I'm no flowchart guru, but I see that you have the 2nd WHILE as a conditional diamond with the loop completely under it. How does it ever escape that loop? The flow should always come into the top of the diamond, with the exit options on either side. This means that the first WHILE is wrong too.
Also, the third WHILE only has a single exit. And the same for the IF underneath it.
For all of these test/condition diamonds the flow should come in the top and exit either side.
Can someone shed some light on how Install4j's back button actually works? I should note at this point that I'm using install4j Multi-Platform Edition 5.1.2 (build 5492).
Loop Example
This example is based on a screen group containing 2 screens ('Screen 1' and 'Screen 2').
Start screen
Screen 1 (in the looped group)
Screen 2 (in the looped group)
End screen
Screen group properties:
Loop index start: 0
Loop index step: 1
Loop expression: (Integer)context.getVariable("i") < 2
Loop index variable name: i
As expected, clicking next repeatedly results in the following screen flow:
Start screen
Screen 1 (i=0)
Screen 2 (i=0)
Screen 1 (i=1)
Screen 2 (i=1)
Screen 1 (i=2)
Screen 2 (i=2)
End screen
I would expect the back button to step backwards through the history listed above. However, the actual behaviour is as follows:
End screen
Screen 2 (i=3)
Screen 1 (i=3)
Screen 1 (i=3)
Screen 1 (i=3)
Start screen
Clearly this is not what any rational user would expect. To complicate matters further, the change Log Install4j for 5.1 Build 5435 includes the following:
Fixed wrong behavior when going back in the screen history where
screen loops were present
The other issue raised in this example, is how do you decrement the loop counter when stepping backwards? It would appear there's no practical way of doing this when using a looped screen group.
If this is case, the only way of implementing a loop which can be stepped through backwards is to implement your own screens in order to override previous(). The side effect being that you have to hand code your screens just to get the correct back button behaviour for loops, which seems ridiculous.
Has anyone else found a decent workaround for this problem? The install4j manual is pretty lame in that the word 'history' only appears once. There's no specification for how the back button works whatsoever.
This is a bug, it will be fixed in 5.1.4. Please contact support#ej-technologies.com to get the current build where it is fixed.
The other issue raised in this example, is how do you decrement the
loop counter when stepping backwards? It would appear there's no
practical way of doing this when using a looped screen group.
This will work automatically in 5.1.4.