Singapore
Asked — Edited

Elseif Questions

The last couple of days I have been struggling with Elseif's which do not appear to be recognized by ARC (latest version) as an Elseif but rather as an If in the structure as can be seen below:-

User-inserted image

This of course is just an example template to illustrate the issue. If I replace the

Quote:

Elseif
statements instead with an endif / if combination the structure appears fine, it is only when I introduce an elseif into the equation that the structure fails.

I have only noticed this problem since upgrading to Windows 10, and the code appears to run OK.

Actual code that exhibits this behavior also appears below:


$standRandomResult=0
:standingLoop
  if ($autonomous = true)
    print("something") 
    if ($isStanding = true)
      $standRandomResult=getRandomUnique(1,50)
      print($standRandomResult)
      $autoAction=true
      if ($standRandomResult=1)
        ControlCommand("Auto Position", AutoPositionAction, "Thinking")
        pause(3000)
      elseif ($standRandomResult=2) 
        ControlCommand("Auto Position", AutoPositionAction, "Bow")
        pause(3000) 
      endif 
      $autoAction=false
    endif 
  endif 
  SleepRandom( 5000, 20000 )
goto(standingLoop) 

The only reason for the

print("something")

statement is that I read EZ-Script does not like there to be no statements in between an If/EndIf pair.

Has anyone experienced similar before, and what could be going on here? This has occurred with multiple scripts I have written over the last 2 days and persists between saves or even if the code is pasted into a new script.


ARC Pro

Upgrade to ARC Pro

Unlock the true power of automation and robotics by becoming a proud subscriber of Synthiam ARC Pro.

PRO
Synthiam
#1  

I don't have any issues in my tests...

I would check that you don't have the variable being used somewhere else in another script.

If you press FORMAT CODE button, that is how the compiler parses the conditions.


$x = 1
$y = 2

if ($x = 1)

  if ($y = 1)
    print("1")
  ELSEif ($y = 2)
    print("2")
  ELSEif ($y = 3)
    print("3")
  ELSE
    print("4")
  endif

ELSEif ($x = 2)

  print("x2")

ELSE

  print("xelse")

endif

Singapore
#2  

Thanks DJ, weird thing is that your code looks OK when I paste it into a script, and I can add extra elseif's no problem with the bracketed indicators to the left of the line numbers correctly showing the grouping of if/endif sections.

However if I try any combination of the original script I pasted, then the bracketed indicators to the left of the line numbers show an imbalance of if/endif's once elseif is introduced.

Anyway, I guess the most important thing is that the script itself runs OK, it's just I am rather pedantic about things looking correct. Thanks for the assistance.

Incidentally I see I stupidly added pauses instead of sleeps in the sample code I pasted, I have since corrected that and pressed FORMAT CODE without any change to the original issue.

Thanks.

PRO
Synthiam
#3  

Oh - yes, do not let the bracket indicators be a source of confusion. That's actually part of the editor, which is separate than the compiler. The editor is a little silly and doesn't parse things perfectly. If you can, ignore the editor's bracketing and focus on the indent parsing and operation.

you're good to go:)

Singapore
#5  

Thanks a lot DJ and Justin, I'll ignore the editor's bracketing in future:)

Regards,