Asked
Resolved Resolved by ptp!

Can Someone Spot The Error In My Code?

Can someone tell me why I am getting this error? I must be going code blind or I found a bug. ARC version 2020.05.18.00

Error on line 4: Missing ) in Expression


$HumanSaid = "birds can fly"
$Sentence = $HumanSaid
$xCount = 0
repeatwhile(contains($Sentence, " "))
$xStrLength = Length($Sentence)
$xIndex1 = IndexOf($Sentence, " ")
$Sentence = SubString($Sentence,$xIndex1 + 1,($xStrLength - ($xIndex1 + 1)))
$xCount = $xCount + 1
endrepeatwhile
$xCount = $xCount + 1

$WordCount = $xCount


Related Hardware (view all EZB hardware)
EZ-B V4 by EZ-Robot
EZ-B v4/2 robot controller: dual Cortex ARM, Wi-Fi, audio/video, 24 servo/digital ports, I2C/UART, camera and Synthiam ARC control for custom robots
Wi-Fi / USB
Servos 24
Camera
Audio
UART 3
I2C
ADC 8
Digital 24

Related Robot Skill (view all robot skills)
Script by Synthiam
Multi-language ARC Script: build, run and debug Blockly, JavaScript, EZ-Script or Python with Intellisense, run/save/load and Roboscratch support

ARC Pro

Upgrade to ARC Pro

Stay at the forefront of robot programming innovation with ARC Pro, ensuring your robot is always equipped with the latest advancements.

Author Avatar
PRO
USA
#1   — Edited

ASFAIK there is no error, it's an EZ-Script bug this code works:

$HumanSaid = "The quick brown fox, jumps over the @## lazy dog !!!"
$Sentence = $HumanSaid
$xCount = 0

$contains=contains($Sentence, " ")
repeatwhile($contains)
  $xStrLength = Length($Sentence)
  $xIndex1 = IndexOf($Sentence, " ")
  $Sentence = SubString($Sentence,$xIndex1 + 1,($xStrLength - ($xIndex1 + 1)))
  $xCount = $xCount + 1
  $contains=contains($Sentence, " ")
endrepeatwhile
$xCount = $xCount + 1
$WordCount = $xCount
print("Total words: " + $wordCount)

Quote:

Start

Total Words: 11 Done (00:00:00.0219259)

You should move away from EZ-Script to Javascript or Python.

Javascript version:

function countWords(str) {
  var matches = str.match(/[\w\d\’\'-]+/gi);
  return matches ? matches.length : 0;
}

text = "The quick brown fox, jumps over the @## lazy dog !!!"
print("Total words: " + countWords(text) );

Quote:

Start

Total words: 9 Done (00:00:00.0128812)

Python version:

import string 
  
text = "The quick brown fox, jumps over the @## lazy dog !!!"
words = sum([i.strip(string.punctuation).isalpha() for i in text.split()]) 
print ("Total words: " +  str(words))

Quote:

Start

Total words : 9 Done (00:00:00.0184166)

.

Author Avatar
PRO
USA
#2  

Thank you PTP, I am starting to use JavaScript. But when I can't find what I want to do it is so easy to fall back to EZ-Script. Have to start from scratch as most of my scripts just vanished when I installed ARC and I can't find any backups and I know I have made lots.

by the way what does ASFAIK mean?

Author Avatar
PRO
USA
#3  

AFAIK  =As Far As I Know

ASFAIK = PTP's version of AFAIK (All rights reserved):)

Author Avatar
PRO
Synthiam
LinkedIn Thingiverse Twitter YouTube GitHub
#5  

Are you just trying to count the number of words? Use the split() function and get the array length

Author Avatar
PRO
USA
#6  

@ DJ, Yup that is what I am doing. Thank you DJ