Nested IF-Statement bug - page 3 - General Discussion and Assistance - CHDK Forum  

Nested IF-Statement bug

  • 30 Replies
  • 19816 Views
*

Offline reyalp

  • ******
  • 14121
Re: Nested IF-Statement bug
« Reply #20 on: 02 / December / 2009, 21:40:49 »
Advertisements
Ok, I'm finally going to get to this soon.

I know it has been in the CHDKDE build for a while. Any test feedback I should be aware of ? Is there a newer version than what has been posted here ?

Thanks.
Don't forget what the H stands for.

*

Offline msl

  • *****
  • 1280
  • A720 IS, SX220 HS 1.01a
    • CHDK-DE links
Re: Nested IF-Statement bug
« Reply #21 on: 03 / December / 2009, 11:57:30 »
I have created an updated patch (copied  ubasic.c and ubasic.h from our CHDKDE version in to the trunk version and deleted additional stuff of CHDKDE version)

The actual patch is by rudi from german CHDK forum!

In addition to here published version contains these now  detailed error messages and a little  correction for initialization of the SELECT stack.

Affected scripts working now without problems.
CHDK-DE:  CHDK-DE links

*

Offline reyalp

  • ******
  • 14121
Re: Nested IF-Statement bug
« Reply #22 on: 03 / December / 2009, 20:13:44 »
Great. Adding it now.

One thing I noticed in testing (not related to patch directly), the original ubasic sometimes doesn't care about spurious else statements, e.g.
Code: [Select]
a=1
if a=0 then
 print "a=0"
else
else
 print "a<>0"
endif
is fine.
The new code will detect this kind of thing when scanning nested ifs, e.g.
Code: [Select]
if a=0 then
 print "a=0"
 if a=1 then
 else
 else
 endif
else
 print "a<>0"
endif
will throw and "unmatched IF" error if a=1, but no error if a=0

Note, this is not something I'm saying this is a problem with the patch, it's just an oddity! If anything should be changed, it's the normal code, not the the new nested if code.
Don't forget what the H stands for.

*

Offline reyalp

  • ******
  • 14121
Re: Nested IF-Statement bug
« Reply #23 on: 03 / December / 2009, 20:34:24 »
Checked in changeset 854.

Edit:
btw if there's other stuff in CHDKDE that's well tested and ready to go in the trunk, let me know.
« Last Edit: 03 / December / 2009, 20:45:24 by reyalp »
Don't forget what the H stands for.


*

Offline rudi

  • ***
  • 129
  • A590IS_101B, SX260HS_100B
Re: Nested IF-Statement bug
« Reply #24 on: 04 / December / 2009, 12:10:57 »
Hello reyalp,

i'm rudi form german forum.

Your script-code is not usualy. But the else-statement works correct.

If the if-statement true, then is check the syntax by else-routine itself and you get an error. In the other case the else-routine give back the control to interpreter for execute next statement. Is it another else-statement, then execute it again with same result. You can't get any error.

If you want to patch the else-statement, then insert this code in ubasic.c on line 927 (build 856):
Code: (c) [Select]
     if( tokenizer_token() == TOKENIZER_ELSE) {
        DEBUG_PRINTF("ubasic.c: else_statement(): odd else-statement\n");
        ended = 1;
        ubasic_error = UBASIC_E_PARSE;
        return;
      }
I hope it's understandingly,
rudi

Re: Nested IF-Statement bug
« Reply #25 on: 26 / January / 2011, 13:29:20 »
Hello,

In first, I thank all the people who take part in CHDK.
It is an incredible work.

I use this script, which does not work with the last versions of CHDK.
http://chdk.wikia.com/wiki/UBASIC/Scripts:_an_ultra_fast_HDR_bracketing_script_for_A6xx

I think the reason is the nested IF-Statement bug, but I do not know which modification I must do.

Thanks for your help.

Steed

/////////////////  The script  //////////////////
rem Author ~SuperManu~ inspired by ~Aeropic~
rem For A610 camera
rem May work on others digicII
rem See documentation

@title HDR bracketing
@param a delta en 1/3
@default a 3
@param b (nb images-1)/2
@default b 1
@param c repetitions
@default c 1

rem test input consistency
if b<1 then b=1
if a<1 then a=1
if a>6 then a=6
if b>6 then b = 6
if c<1 then c=1

j=0

rem get the dial mode
rem if <> P, Tv, Av exit
get_prop 0 i
if i = 2 then goto "ok"
if i = 3 then goto "ok"
if i = 1 then goto "ok"
print "P, Tv ou Av ..."
goto "lend"

:ok
rem test if flash set
get_prop 16 f
if f = 2 then goto "ok2"
print "flash OFF ..."
set_prop 16 2

:ok2
rem get Exp compensation value
get_prop 25 i

rem  nb steps diaph computation
a=a*32

rem start EV computation
s=i-b*a
b=b*2

rem check focus mode
get_prop 12 y
get_prop 11 x
let v=y
let u=x
sleep 50
if y = 1 then goto "shoot_it"

:ok3
rem try to focus
press "shoot_half"

rem wait for focus (prop 67)
p = 0
set_prop 67 0
do
 p = p +1
 get_prop 67 j
 if p = 100 then
   print "focus impossible"
   release "shoot_half"
   get_prop 11 x
   if x=0 then set_prop 11 1 else set_prop 11 0 endif
   print "change focus mode"
   goto "ok3"
 endif
until j = 1

rem switch to manual focus
do
 sleep 500
 click "down"
 sleep 500
 get_prop 12 y
until y=1
release "shoot_half"
sleep 300

:shoot_it
rem data take loop based on prop 205
rem initial set of 25 & 26 for the first shot
z=1
set_prop 25 s
set_prop 26 s
for n=1 to (b+1)*c
  print "repetition " z "/" c
  click "shoot_full"
  do
   get_prop 205 w
  until w=1
  if z=c then
   s=s+a
   set_prop 25 s
   set_prop 26 s
   z=0
  else if z<c then z=z+1
  else if z>c then z=1
  endif
 do
   get_prop 205 w
  until w<>1
next n

rem switch back to previous focus mode
do
 sleep 500
 click "down"
 sleep 500
 get_prop 12 y
 get_prop 11 x
until y=v and x=u
set_prop 11 u
set_prop 12 v

rem reset initial values for EV and flash
set_prop 25 i
set_prop 26 i
set_prop 16 f
sleep 300

:lend
let j=0
end
////////////////////////////////////////////

*

Offline SkyWalker9

  • ****
  • 301
  • SX20 IS (fw 1.02b)
Re: Nested IF-Statement bug
« Reply #26 on: 26 / January / 2011, 15:01:07 »
...I use this script, which does not work with the last versions of CHDK.
http://chdk.wikia.com/wiki/UBASIC/Scripts:_an_ultra_fast_HDR_bracketing_script_for_A6xx

I think the reason is the nested IF-Statement bug, but I do not know which modification I must do...
Code: [Select]
rem Author ~SuperManu~ inspired by ~Aeropic~
rem For A610 camera
rem May work on others digicII
rem See documentation

@title HDR bracketing
@param a delta en 1/3
@default a 3
@param b (nb images-1)/2
@default b 1
@param c repetitions
@default c 1

rem test input consistency
if b<1 then b=1
if a<1 then a=1
if a>6 then a=6
if b>6 then b = 6
if c<1 then c=1

j=0

rem get the dial mode
rem if <> P, Tv, Av exit
get_prop 0 i
if i = 2 then goto "ok"
if i = 3 then goto "ok"
if i = 1 then goto "ok"
print "P, Tv ou Av ..."
goto "lend"

:ok
rem test if flash set
get_prop 16 f
if f = 2 then goto "ok2"
print "flash OFF ..."
set_prop 16 2

:ok2
rem get Exp compensation value
get_prop 25 i

rem  nb steps diaph computation
a=a*32

rem start EV computation
s=i-b*a
b=b*2

rem check focus mode
get_prop 12 y
get_prop 11 x
let v=y
let u=x
sleep 50
if y = 1 then goto "shoot_it"

:ok3
rem try to focus
press "shoot_half"

rem wait for focus (prop 67)
p = 0
set_prop 67 0
do
 p = p +1
 get_prop 67 j
 if p = 100 then
   print "focus impossible"
   release "shoot_half"
   get_prop 11 x
   if x=0 then set_prop 11 1 else set_prop 11 0 endif
   print "change focus mode"
   goto "ok3"
 endif
until j = 1

rem switch to manual focus
do
 sleep 500
 click "down"
 sleep 500
 get_prop 12 y
until y=1
release "shoot_half"
sleep 300

:shoot_it
rem data take loop based on prop 205
rem initial set of 25 & 26 for the first shot
z=1
set_prop 25 s
set_prop 26 s
for n=1 to (b+1)*c
  print "repetition " z "/" c
  click "shoot_full"
  do
   get_prop 205 w
  until w=1
  if z=c then
   s=s+a
   set_prop 25 s
   set_prop 26 s
   z=0
  else if z<c then z=z+1
  else if z>c then z=1
  endif
 do
   get_prop 205 w
  until w<>1
next n

rem switch back to previous focus mode
do
 sleep 500
 click "down"
 sleep 500
 get_prop 12 y
 get_prop 11 x
until y=v and x=u
set_prop 11 u
set_prop 12 v

rem reset initial values for EV and flash
set_prop 25 i
set_prop 26 i
set_prop 16 f
sleep 300

:lend
let j=0
end
Using your original script above, I created a modified version you might try on you camera. Because you are using some camera specific propcas statements, using UBDB will only get down to the third print statement. I've added print statements to test values at various steps so that you'll know what the script is using at various lines. There are "print_screen" statements that will save all of the output to a LOG file in your CHDK/LOGS folder for later reference - usually many of the print statements print and are gone before you can actually grasp what happened. To view the Log file, you may need to use a different txt editor than NotePad so that the text doesn't get jammed together. Hope this helps. Good Luck!

Here is the modified script:
Code: [Select]
rem Author ~SuperManu~ inspired by ~Aeropic~
rem For A610 camera
rem May work on others digicII
rem See documentation

@title HDR bracketing
@param a delta en 1/3
@default a 3
@param b (nb images-1)/2
@default b 1
@param c repetitions
@default c 1

  print_screen 1

rem test input consistency

    print "check 1  a="a"  b="b"  c="c

if b<1 then b=1
if a<1 then a=1
if a>6 then a=6
if b>6 then b = 6
if c<1 then c=1

    print "check 2  a="a"  b="b"  c="c

j=0

rem get the dial mode
rem if <> P, Tv, Av exit
get_prop 0 i

    print "check 3  i="i

if i = 2 then goto "ok"
if i = 3 then goto "ok"
if i = 1 then goto "ok"
print "P, Tv ou Av ..."
goto "lend"

:ok
rem test if flash set
get_prop 16 f

    print "check 4  f="f

if f = 2 then goto "ok2"
print "flash OFF ..."
set_prop 16 2

:ok2
rem get Exp compensation value
get_prop 25 i

rem  nb steps diaph computation
a=a*32

rem start EV computation
s=i-b*a
b=b*2

rem check focus mode
get_prop 12 y
get_prop 11 x
let v=y
let u=x

    print "check 5  v="v"  u="u"  x="x"  y="y  

sleep 50
if y = 1 then goto "shoot_it"

:ok3
rem try to focus
press "shoot_half"

rem wait for focus (prop 67)
p = 0
set_prop 67 0

    print "check 6  p="p"  x="x"  j="j

do
 p = p +1
 get_prop 67 j
 if p = 100 then
   print "focus impossible"
   release "shoot_half"
   get_prop 11 x
   if x=0 then set_prop 11 1 else set_prop 11 0 endif
   print "change focus mode"
   goto "ok3"
 endif
until j = 1

rem switch to manual focus
do
 sleep 500
 click "down"
 sleep 500
 get_prop 12 y
until y=1
release "shoot_half"
sleep 300

:shoot_it
rem data take loop based on prop 205
rem initial set of 25 & 26 for the first shot
z=1
set_prop 25 s
set_prop 26 s

    print "check 7  s="s"  b="b"  c="c"  z="z"  w="w"  n="n

for n=1 to (b+1)*c
  print "repetition " z "/" c
  click "shoot_full"
  do
   get_prop 205 w
  until w=1
  if z=c then
   s=s+a
   set_prop 25 s
   set_prop 26 s
   z=0
  else if z<c then z=z+1
  else if z>c then z=1
  endif
 do
   get_prop 205 w
  until w<>1
next n

    print "check 8  s="s"  b="b"  c="c"  z="z"  w="w"  n="n

rem switch back to previous focus mode

    print "check 9  y="y"  x="x"  u="u"  v="v

do
 sleep 500
 click "down"
 sleep 500
 get_prop 12 y
 get_prop 11 x
until y=v and x=u
set_prop 11 u
set_prop 12 v

rem reset initial values for EV and flash

    print "check 10  i="i"  f="f"  j="j

set_prop 25 i
set_prop 26 i
set_prop 16 f
sleep 300

:lend
let j=0

  print_screen 0

end
« Last Edit: 26 / January / 2011, 15:05:25 by SkyWalker9 »

*

Offline msl

  • *****
  • 1280
  • A720 IS, SX220 HS 1.01a
    • CHDK-DE links
Re: Nested IF-Statement bug
« Reply #27 on: 26 / January / 2011, 15:09:16 »
Hello,

for the nested if patch you must change this line:
Code: [Select]
if x=0 then set_prop 11 1 else set_prop 11 0 endif in
Code: [Select]
if x=0 then set_prop 11 1 else set_prop 11 0
CHDK-DE:  CHDK-DE links


Re: Nested IF-Statement bug
« Reply #28 on: 30 / January / 2011, 15:06:38 »
Thank you for your answers.
-SkyWalker9, Thank for the modified script.I try it in a few days.
-msl, I modified the line which you indicate.But it is not sufficient.
Is the other nested if statement correct?
if z=c then
   s=s+a
   set_prop 25 s
   set_prop 26 s
   z=0
  else if z<c then z=z+1
  else if z>c then z=1
  endif

Thanks for your help.

Steed

*

Offline msl

  • *****
  • 1280
  • A720 IS, SX220 HS 1.01a
    • CHDK-DE links
Re: Nested IF-Statement bug
« Reply #29 on: 30 / January / 2011, 15:54:58 »
Is the other nested if statement correct?
Yes, the test-program say it's clean.

What error message you get? Maybe you've forgotten a blank line at the end of the script.

msl



CHDK-DE:  CHDK-DE links

 

Related Topics


SimplePortal 2.3.6 © 2008-2014, SimplePortal