Asked — Edited

Array Index Reference Error

This script has run without errors.


ControlCommand("Answer array", ScriptStart)
#Get 1 0f 16 random phrases from the array Answers
$z = (GetRandomUnique(0,15))  
$phrase = ($Answers[$z])
ControlCommand("Script Manager"' ScriptStart, Speak (phrase")

But, now with ARC - Version 2016.02.18.02 I get:
Error on line 4: Input string was not in a correct format.

The last release that this script ran correctly was the one downloaded on 02/02/201.


ARC Pro

Upgrade to ARC Pro

Don't limit your robot's potential – subscribe to ARC Pro and transform it into a dynamic, intelligent machine.

United Kingdom
#1  

The ControlCommand is a little wrong looking at the code you posted. Is that a copy/paste or re-typed?

I ask because I don't see how that ControlCommand could ever have run without error.

#2  

@Rich,

I re-typed the code.

The ControlCommand lines were generated by the Cheat Sheet. The reported error has nothing to do with ControlCommand.

What do you think is wrong with the script?

Thank you.

#3  

This line is wrong in a couple of ways. I don't see how it could have ever passed the syntax check when you tried to save it, let alone actually run.


ControlCommand("Script Manager"' ScriptStart, Speak (phrase" )
               #               |              |_____________|
               #This should be a comma              |
                                                    |
               #This should be either a literal string or a variable
 
 #For example something like this:
$ScriptToRun ="ScriptToRunName"
ControlCommand("Script Manager", ScriptStart, $ScriptToRun)
              #                                    |
              #         Variable set to the name of the script to run
              #Or
ControlCommand("Script Manager", ScriptStart, "ScriptToRunName" )
              #                                     |
              #           Literal string for the script name

Also this line doesn't need parenthesis:


$phrase = ($Answers[$z])
  #Should be:
$phrase = $Answers[$z]

Seems to pass the syntax check either way, however.

PRO
Synthiam
#4  

Would you mind sharing your project?

There's a lot of unneeded brackets and random quotes in places. I'd like to see the names of your controls and such, to see where this is coming from if indeed it's generated by the cheat sheet.

#5  

@WBS00001,

You are correct. I miss typed the ControlCommand("Script Manager"' ScriptStart, Speak (phrase") line.
The script has:

ControlCommand("Script Manager", ScriptStart, Speak (phrase")

Again, the reported error has to do with "Input string was not in a correct format" from the

$phrase = ($Answers[$z])

line.

With this latest EZ - Builder release (2016.02.18.02) the Check Syntax button and my script do not work.

With release 2016.01.31.00 Both my script and the Check Syntax work.

With release, 2016.02.18.02 my script and Check Syntax do not work on my computer which is a Dell Latitude E6420 Lap Top running Windows 7 Professional.

#6  

@JR, My project is in the cloud as LESTER 02-19-16 No Camera.

Any help is very much appreciated.

PRO
Synthiam
#7  

This release will solve the issue: https://synthiam.com/Community/Questions/9086

I reviewed your project - neat stuff you're doing. However, i do recommend proper use of brackets. Everything appears to be in a bracket, and i mean everything:)

Brackets are only necessary for overriding order of math operations or parameters for functions.

#8  

@DJ,

How do you define the index to an array? Are they "parameters for functions"?

Is this the proper construct for an array?


DefineArray(Answers,4)
$Answers[0]=("Phrase 0")
$Answers[1]=("Phrase 1")
$Answers[2]=("Phrase 2")
$Answers[3]=("Phrase 3")

Where did the smiley faces come from?

Wouldn't the proper way to set $phrase to the third element in the array be;

$phrase=$Answers[2]

?

PRO
Synthiam
#9  

Yes - the second way is correct. Absolutely not the first way... There is an examples folder in ARC and quite a few of the examples are regarding how to use Arrays. ARC array is similar format as all programming languages, as such, and each have their own constructor...


DefineArray($Answers, 4) # your missed the $ dollar sign
$Answers[0] = "This is some data"
$Answers[1] = "Notice how there are no brackets"
$Answers[2] = "None of the examples in any languages of strings use brackets"
$Answers[3] = "Not sure where you got the bracket ideas from"

$phrase = $Answers[3]

# of

$cnt = 2

$phrase = $Answers[$cnt]

Brackets are only used for the reasons stated above, to override math operations or for function parameters. Such as...


$x = (2 / 3) + (4 * 2)

Servo(d0, 20)

You do not use brackets for absolutely any other reason - specifically never used while declaring a string...