Array Index Reference Error

 
#1

This script has run without errors.

Code:


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 EZ-Builder - 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.

#2

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.

#3

@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.

#4

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.

Code:


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:

Code:


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


Seems to pass the syntax check either way, however.

#5

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.

#6

@WBS00001,

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

Code:

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



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

Code:

$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.

#7

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

Any help is very much appreciated.

#8

This release will solve the issue: http://www.ez-robot.com/Community/Forum/Thread?threadId=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 Smile

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

#9

@DJ,

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

Is this the proper construct for an array?

Code:


DefineArray(Answers,4)
$Answers[0]=("Phrase 0"Winky
$Answers[1]=("Phrase 1"Winky
$Answers[2]=("Phrase 2"Winky
$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;

Code:

$phrase=$Answers[2]


?

#10

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

Code:


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...

Code:


$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...