Welcome to Synthiam!

Program robots using technologies created from industry experts. ARC is our free-to-use robot programming software that makes features like vision recognition, navigation and artificial intelligence easy.

Get Started
Asked — Edited
Resolved Resolved by DJ Sures!

Expression Parser Broken - Length Function

The code below does not work:

Code:


1: ClearVariables()
2: $buffer = "foo;bar;quux"
3: $sepPos = 3
4: $len0 = Length($buffer)-$sepPos-1


error:

Quote:


Error on line 4: Operator '-' invalid for strings.


1st attempt with a different code:

Code:


1: ClearVariables()
2: $buffer = "foo;bar;quux"
3: $sepPos = 3
4: $len1 = Length($buffer) - $sepPos
5: $len1 = $len1 - $sepPos


same error.

2nd attempt (success)

Code:


1: ClearVariables()
2: $buffer = "foo;bar;quux"
3: $sepPos = 3
4: $len2 = Length($buffer)
5: $len2 = $len2 - $sepPos - 1


it seems the the parser assumes Length function returns a string ?

AI Support Bot
Related Content
Synthiam
#1  

Quote:

1st attempt with a different code:

Code:

Code:


1: ClearVariables()
2: $buffer = "foo;bar;quux"
3: $sepPos = 3
4: $len1 = Length($buffer) - $sepPos
5: $len1 = $len1 - $sepPos



I ran into this issue myself, if you don't want to separate it over multiple lines you can cast the length in an int. I guess it is just one of the limitations of not declaring variable types.

Code:

Code:

ClearVariables()
$buffer = "foo;bar;quux"
$sepPos = 3
$len0 = CInt(Length($buffer)) - $sepPos-1
Print( $len0 )
PRO
USA
#2  
yes is another away to skin the cat...

i had other similar issues with other functions too.

I don't agree with "it's just one of the limitations of not declaring variable types" mainly because of this:

Code:


$rLen1 = IndexOf($buffer, ";")-$len1-1


and it works, one function and two math operations.

Length() is returning the correct type (integer), only when combined behaves differently i'm guessing is really a parser issue.
#3  

Code:

 Length() is returning the correct type (integer), only when combined behaves differently i'm guessing is really a parser issue. 
Makes sense.
PRO
Synthiam
#4  
fixed in next release
PRO
USA
#5  
Thanks
#6  
It seems I'm facing the same issue. I just installed the latest version of EZB...

Code:


$encoderBVAR = $encoderB - $var

if ($encoderA < $encoderBVAR)
$forwardmustwait = 1
$pwmFR = $pwmFR +$mod
$pwmRR = $pwmRR +$mod
$pwmFL = $pwmFL -$mod
$pwmRL = $pwmRL -$mod
$forwardmustwait = 0

endif


Code:


> Error on line 45: Operator '-' invalid for strings.
Done (00:00:00.5009241)
#7  
Just a guess here but try

Code:


$encoderBVAR = $encoderB - $var

if ($encoderA < $encoderBVAR)
$forwardmustwait = 1
$pwmFR = $pwmFR + $mod
$pwmRR = $pwmRR + $mod
$pwmFL = $pwmFL - $mod
$pwmRL = $pwmRL - $mod
$forwardmustwait = 0

endif
PRO
Synthiam
#8  
Elfge, Dave is right. You will need spaces between the operation commands.
#9  
lol I just spent 4 minutes looking and I can't figure where my spaces are missing. It's time I take a break I guess... thank you DJ and Dave...
PRO
Synthiam
#10  
Haha I hear u! That regex parser is a little wonky sometimes for the script compiler. I spend so much time in there with little tweaks - the way it is now is the most optimal for performance.
#11  
Eventually found where the spaces were missing. But in fact the problem was not at these lines, but at the definition of the variable. Anyway, it fixed itself it seems, just after ARC crashed, I restarted it and could use the minus function, without adding spaces. I did add them after though, just in case.

Thanks a lot Dj! Again, really, I appreciate the incredible dedication and, in my particular case, the incredible patience! Sorry again for this day when I went nuts on the DHCP issue... I still think about it...:(
PRO
Synthiam
#12  
We all learn and progress:) me, doubly so! My dicioline is patience to hear what others have to say and understand what to do about it. With everyone having very specific needs, I'm challenged to invent solutions to accommodate the group. I want you to build robots, so you're conversations are incredible relevant. Never feel bad:)