I'm new to Groovy and came to Groovy and grails from Java.
I cannot explain this:
boolean boolVar = false
if (boolVar) {
print "ok"
}
but code execution run inside "if" block, nut boolVar is false
debugger session screenshot
I think the screenshot is a bit wrong as you have nothing after the condition so intelliJ highlight this line but it does not execute it, it seems it goes to the block but it does not print the ok, can you show the result of the run window ?
for example add this to your code
boolean boolVar = false
def output = "I start here"
if (boolVar) {
output += "\noops in loop"
println "ok"
}
print output
only I start here is being printed
I'm not sure I get it by 100%, did you try this?
boolean boolVar = false
if (!boolVar) {
println "ok"
}
if(boolVar) and if(boolVar == true) is the same
1.) Remove all breakpoints from your project (Run->View Breakpoints and delete all breakpoints)
2.) Clean the target directory.
3.) Add a new breakpoint at the "print" statement and check if it works now.
Related
I recently discovered AutoHotKey, this scripting language seemed to be amazing !
Unfortunately, I can't manage to make my script find an image on a window (BlueStacks in my case).
Can someone please help me, my script is :
CoordMode, Pixel, screen
CoordMode, Mouse, screen
*ESC::ExitApp
ImgFound := false
while(ImgFound = false)
{
ImageSearch, ButtonX, ButtonY, 0, 0, A_ScreenWidth, A_ScreenHeight, *50 C:\Users\...\Documents\...\test.png
if (ErrorLevel = 2)
{
MsgBox Could not execute script.
ExitApp
}
else if (ErrorLevel = 1)
{
ImgFound := false
}
else
{
MsgBox Found.
click, %ButtonX%, %ButtonY%
ImgFound := true
}
}
Your while loop is unreachable code.
The code execution stops when the first hotkey label is encountered. This is called the Auto-execute Section.
Move your hotkey definition to be at the very bottom.
(All hotkeys always defined by hotkeys labels get always created regardless of being in the auto-execute section or not)
The script is intended to break the loop on XButton1, but fails.
I am a newbie in AHK scripting and a really simple script I made is not working as intended. I googled it and it works on everyone.
ended = false
XButton1::
ended = true
return
$XButton2::
ended = false
Loop
{
if (ended = true)
{
break
}
MouseClick left
Sleep 10
}
return
It was supposed to click infinitely until Mouse4 (XButton1) is pressed. But it does not stop when I click it.
I also checked other StackOverflow posts and nothing solved it.
Your code uses legacy-syntax which was a major headache for me (and I believe many others) when I was starting with AHK.
To make your code work change:
if (ended = true)
to
if (ended = "true")
Consider switching to := (SetExpression) instead of =
For example:
ended = false
should become
ended := false
In my plugin, I execute a network query, get the result
and show the processing step.
CoreProgressManager.getInstance().runProcessWithProgressSynchronously(Runnable {
//runnable block
CoreProgressManager.getInstance().progressIndicator.text = "Start loading"
val result = MyProvider.getObjects() // this network request
CoreProgressManager.getInstance().progressIndicator.text = "Finish"
result.forEach {
//processing result
CoreProgressManager.getInstance().progressIndicator.text = "Processing is $result"
}
}, taskTitle, true /* canBeCanceled */, project)
Sometimes the query is performed by the network for a long time, and I want to stop working all block (runnable block).
For this, in runProcessWithProgressSynchronously I passed the parameter canBeCanceled = true
and naively thought that IDEA would stop executing my executable block, but this did not happen.
How do I catch the clicking of a Cancel button and stop my runnable block?
You need to periodically call ProgressIndicator.checkCanceled() from your block. This method will throw a ProcessCanceledException if the Cancel button has been pressed.
I have a question that bothers me for a long time, here some code as below,
if (flag) {
// some code here
}
else | // cursor here
when I press shift + command + enter (on Mac) to complete automatically, it restyled my code as
if (flag) {
// some code here
} else {
|
}
and I just wanna it complete but never effect on my own style, i.e.
if (flag) {
// some code here
}
else {
|
}
is there any settings about this manner for IntelliJ IDEA? thanks in advance:)
It's likely a setting in your code style that had forced this. By default, IntelliJ does not force the else statement to go to a separate line.
Navigate to Settings > Editor > Code Style > Java, select the Wrapping and Braces tab, and tick the "'else' on new line" checkbox. This will then force all of your else statements to be on their own separate line as you wish.
I'm having a problem with a variable I'm using to track the status of a user activity. In a GUI I have a button that, on clicking the button launches a second GUI. In that GUI, the user can either complete the activity started in the first GUI or not.
If the user cancels the second GUI, then the idea is to go back to the first GUI, leaving all variables and lists with their current values. If the second GUI completes the activity of the first GUI, then all variables and lists should be reset.
To track this, I have a variable (Boolean complete) initially set to FALSE. In the second GUI, when the "OK" button is clicked (rather than the "Cancel" button), the second GUI calls a method in the first GUI, changing the value of "complete" to TRUE.
To see what the heck is going on, I have System.out.println at several points allowing me to see the value of "complete" along the way. What I see is this:
Launching first GUI - complete = FALSE
Launching second GUI - complete = FALSE
Clicking "OK" in second GUI - complete = TRUE
Second GUI closes itself, returning to complete first GUI activity
First GUI finishes activity with complete = FALSE
I'm assuming it is because I am launching the second GUI with a showandwait, and when the method containing the showandwait begins, the value of "complete" = FALSE. The value changes in the WAIT part of show and wait, then the method continues and that is where I get the value still being FALSE, though it was changed to TRUE.
Here is a summary of the code in question (if you need exact code, it's longer, but I can post on request):
completeButton.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent t) {
try {
System.out.println("b4 calc = " + complete); // complete = FALSE
// all the code to create the calcStage
calcStage.showAndWait(); // second GUI, which calls a method in THIS
// class that changes complete to TRUE. That method
// (in THIS file) also has a println that shows the change.
getComplete(); // tried adding this method to check the value of
// "complete" after the change made by the calcStage
// (which calls a method in this same file)
System.out.println("Complete? " + complete);
// this shows complete = FALSE,
// though in the calcStage it was changed to TRUE
if (salecomplete) {
// code that should reset all variables and lists if the activity was completed
}
}
}
}
The question here is why does the second GUI successfully change the value of "complete", but when I return to the first GUI it still sees complete as FALSE? And how can I get around this?
Try having the controller of the second GUI calling a method in the first GUI's controller to modify that complete variable
For example:
// Code to handle the OK button being pressed
#Override
public void handle(ActionEvent t) {
// Do validation and work
//reference to the first controller object
firstController.setComplete(true);
}