resetting variable
Haplo wrote on Feb 26, 2009
Is it possible to reset a boolean variable, after it was assigned a value?
I have this (see below) construct to prematurely end a script and the answer "yes" is unfortunatly remembered... So it only works as intended the first time in the script, and on every next occurence "yes" is automatically implied...
This is the code:
I tried
I have this (see below) construct to prematurely end a script and the answer "yes" is unfortunatly remembered... So it only works as intended the first time in the script, and on every next occurence "yes" is automatically implied...
This is the code:
print ("Do you want to continue? (yes/no)")
junk = scan (answer)
if (answer == yes) {
}
else {
bye()
}I tried
answer = "", but this gave me an "ERROR: Non-boolean operand used where boolean expected".
Mike Fitzpatrick wrote on Feb 26, 2009
I tried
Code:
answer = ""
, but this gave me an "ERROR: Non-boolean operand used where boolean expected".
This is because you were setting the value to a null string, which is not a legal boolean value. If you need to reset the value to something other than yes/no to indicate it isn't set, you can use INDEF, e.g.
answer = INDEF
if (isindef (answer)) {
....set the value
} else {
....do something with it
}
-Mike
Haplo wrote on Feb 26, 2009
Thanks for the quick reply, but maybe I didn't understand you correctly, but this is still not working. I have this new code:
The cl always goes into the "else" loop, because the "scan (answer)"-part is never executed - probably because he still thinks INDEF is a defined value (which would be rather ironic)...
Could you further elaborate the "....set the value"-part of your suggestion?
Thanks again!
answer = INDEF
if (isindef (answer)) {
junk = scan (answer)
if (answer == yes) {
}
else {
bye()
}
}The cl always goes into the "else" loop, because the "scan (answer)"-part is never executed - probably because he still thinks INDEF is a defined value (which would be rather ironic)...
Could you further elaborate the "....set the value"-part of your suggestion?
Thanks again!
Mike Fitzpatrick wrote on Feb 26, 2009
Is this a procedure script or are you running it as e.g. "cl<script.cl" ? The scan() should always be executed, but it's looking to read the value from the standard input and if you're redirecting the input the scan may not be succeeding as expected. Is there more to the script that prints a prompt string of some kind?
As for "...set the value", all I mean is that if you detect an INDEF value you could do something to reset the value, e.g. print a prompt and scan for the answer, so you can keep processing. I was simply trying to show how to set a boolean variable to INDEF, and then how to detect that within the script.
-Mike
As for "...set the value", all I mean is that if you detect an INDEF value you could do something to reset the value, e.g. print a prompt and scan for the answer, so you can keep processing. I was simply trying to show how to set a boolean variable to INDEF, and then how to detect that within the script.
-Mike
Haplo wrote on Feb 26, 2009
Sorry for the long delay in answering (I had a week off)...
I run the script from the command line - "cl < script.cl".
When I run the modified script as it is shown below, the script never waits for the user input for "scan (answer)". I still presume it somehow accepts "INDEF" as a set value and does not prompt for a new one...
Here is the complete script:
Thank you for your input!
I run the script from the command line - "cl < script.cl".
When I run the modified script as it is shown below, the script never waits for the user input for "scan (answer)". I still presume it somehow accepts "INDEF" as a set value and does not prompt for a new one...
Here is the complete script:
string *dlist
string currdir,startdir
bool answer
int junk
ls -d */ > directories
dlist = "directories"
pwd | scan (startdir)
while (fscan (dlist, currdir) != EOF) {
cd (currdir//"/images")
if (!access ("../varstars.ds9")) {
display ("ref.fits", 1, >& "dev$null")
print ("Do you want to continue? (yes/no)")
answer = INDEF
if (isindef (answer)) {
junk = scan (answer)
if (answer == yes) {
}
else {
cd (startdir)
dlist = ""
bye()
}
}
}
;
cd (startdir)
}Thank you for your input!
Last post on Feb 26, 2009