# Brightscrpt says this is a error

**URL:** <https://forum.developer.roku.com/t/brightscrpt-says-this-is-a-error/5107>\
**Category:** Archived\
**Tags:** roku-developer-program\
**Created:** [May 20, 2016, 2:58pm UTC](https://forum.developer.roku.com/t/brightscrpt-says-this-is-a-error/5107 "2016-05-20T14:58:58Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![railfan](https://avatars.discourse-cdn.com/v4/letter/r/87869e/32.png) [@railfan](https://forum.developer.roku.com/u/railfan)\
**Post date:** [May 20, 2016, 2:58pm UTC](https://forum.developer.roku.com/t/brightscrpt-says-this-is-a-error/5107/1 "2016-05-20T14:58:58Z")

</div>

Bridght Script gives me errors on this but the channel works ok. So I am wondering is it really a issue or ???

Multiple markers at this line

- Syntax error: unexpected token “)”, expected one of , or “:”

firstAsInt = val(first, 10)

sub startAnimation()  
’ don’t start animation on devices that don’t support it  
m.model = createObject(“roDeviceInfo”).getModel()  
'Get the first character of the model number. Anything less than a 4 corresponds to a device not suited to animations.  
first = Left(m.model, 1).trim()  
if first \<\> invalid and first.Len() = 1  
firstAsInt = val(first, 10)  
if (firstAsInt) \> 3  
m.rotationAnimation.control = “start”  
m.top.state = “running”  
end if  
end if  
end sub

---

<div class="post-metadata">

**Author:** ![joetesta](https://avatars.discourse-cdn.com/v4/letter/j/85e7bf/32.png) [@joetesta](https://forum.developer.roku.com/u/joetesta)\
**Post date:** [May 20, 2016, 4:23pm UTC](https://forum.developer.roku.com/t/brightscrpt-says-this-is-a-error/5107/2 "2016-05-20T16:23:11Z")

</div>

I think your structure of using “Left” is incorrect; [https://sdkdocs.roku.com/display/sdkdoc/ifStringOps#ifStringOps-Left(lenasInteger)asString](https://sdkdocs.roku.com/display/sdkdoc/ifStringOps#ifStringOps-Left(lenasInteger)asString)  
should be STRING.LEFT(1), no?

Here’s how I’m doing this in the app I’m working on;

```auto
    deviceInfo = CreateObject("roDeviceInfo")
    deviceName = deviceInfo.GetModel() 
    modelFirstDigit = deviceName.Left(1).ToInt()

```

---

<div class="post-metadata">

**Author:** ![belltown](https://avatars.discourse-cdn.com/v4/letter/b/8edcca/32.png) [@belltown](https://forum.developer.roku.com/u/belltown)\
**Post date:** [May 20, 2016, 4:29pm UTC](https://forum.developer.roku.com/t/brightscrpt-says-this-is-a-error/5107/3 "2016-05-20T16:29:43Z")

</div>

> “joetesta” wrote:  
> I think your structure of using “Left” is incorrect; [https://sdkdocs.roku.com/display/sdkdoc/ifStringOps#ifStringOps-Left(lenasInteger)asString](https://sdkdocs.roku.com/display/sdkdoc/ifStringOps#ifStringOps-Left(lenasInteger)asString)  
> should be STRING.LEFT(1), no?  
> Left(s, n) is correct, too: [https://sdkdocs.roku.com/display/sdkdoc/Global+String+Functions#GlobalStringFunctions-Left%28sasString,nasInteger%29asString](https://sdkdocs.roku.com/display/sdkdoc/Global+String+Functions#GlobalStringFunctions-Left%28sasString,nasInteger%29asString)

---

<div class="post-metadata">

**Author:** ![joetesta](https://avatars.discourse-cdn.com/v4/letter/j/85e7bf/32.png) [@joetesta](https://forum.developer.roku.com/u/joetesta)\
**Post date:** [May 20, 2016, 5:15pm UTC](https://forum.developer.roku.com/t/brightscrpt-says-this-is-a-error/5107/4 "2016-05-20T17:15:41Z")

</div>

Thanks belltown - funny how there’s two pages of documentation with conflicting info.  
[https://sdkdocs.roku.com/display/sdkdoc/Global+String+Functions](https://sdkdocs.roku.com/display/sdkdoc/Global+String+Functions)  
[https://sdkdocs.roku.com/display/sdkdoc/ifStringOps#ifStringOps-Left(lenasInteger)asString](https://sdkdocs.roku.com/display/sdkdoc/ifStringOps#ifStringOps-Left(lenasInteger)asString)

---

<div class="post-metadata">

**Author:** ![belltown](https://avatars.discourse-cdn.com/v4/letter/b/8edcca/32.png) [@belltown](https://forum.developer.roku.com/u/belltown)\
**Post date:** [May 20, 2016, 5:30pm UTC](https://forum.developer.roku.com/t/brightscrpt-says-this-is-a-error/5107/5 "2016-05-20T17:30:16Z")

</div>

> “joetesta” wrote:  
> Thanks belltown - funny how there’s two pages of documentation with conflicting info.  
> [https://sdkdocs.roku.com/display/sdkdoc/Global+String+Functions](https://sdkdocs.roku.com/display/sdkdoc/Global+String+Functions)  
> [https://sdkdocs.roku.com/display/sdkdoc/ifStringOps#ifStringOps-Left(lenasInteger)asString](https://sdkdocs.roku.com/display/sdkdoc/ifStringOps#ifStringOps-Left(lenasInteger)asString)  
> One is a BrightScript Language construct, the other an ifStringOps interface method. There are several other similar String things. Where it gets confusing is the BrightScript Language constructs, Instr and Mid, for example, are “1” based, whereas the “equivalent” ifStringOps interface methods, Instr and Mid, are zero-based!

---

<div class="post-metadata">

**Author:** ![RokuMarkn](https://avatars.discourse-cdn.com/v4/letter/r/ac8455/32.png) [@RokuMarkn](https://forum.developer.roku.com/u/RokuMarkn)\
**Post date:** [May 20, 2016, 5:37pm UTC](https://forum.developer.roku.com/t/brightscrpt-says-this-is-a-error/5107/6 "2016-05-20T17:37:16Z")

</div>

Yes, this is mentioned on the page that joetesta linked to.

> ifStringOps provides various methods for manipulating string objects. Some of these duplicate functionality also available in the global string functions.  
> Note however that ifStringOps string indices start at zero, not one as the global string functions do.

–Mark

---

<div class="post-metadata">

**Author:** ![railfan](https://avatars.discourse-cdn.com/v4/letter/r/87869e/32.png) [@railfan](https://forum.developer.roku.com/u/railfan)\
**Post date:** [May 20, 2016, 5:59pm UTC](https://forum.developer.roku.com/t/brightscrpt-says-this-is-a-error/5107/7 "2016-05-20T17:59:12Z")

</div>

Ya for a new-be this is what the code had for a error in it when I downloaded it yesterday from the SDK area page. I was bummed and I don’t know what to do to fix it.

[https://sdkdocs.roku.com/download/attac … \_Video.zip](https://sdkdocs.roku.com/download/attachments/1608528/Simple_Grid_with_Details_and_Video.zip)

When i saw the error after installing the brighscript stuff I was like hum how do I fix this???

---

<div class="post-metadata">

**Author:** ![belltown](https://avatars.discourse-cdn.com/v4/letter/b/8edcca/32.png) [@belltown](https://forum.developer.roku.com/u/belltown)\
**Post date:** [May 20, 2016, 9:17pm UTC](https://forum.developer.roku.com/t/brightscrpt-says-this-is-a-error/5107/8 "2016-05-20T21:17:27Z")

</div>

I downloaded that same file and it runs just fine on my device (3100X software 7.1.0 build 4067-02) – apart from the following Warning:

```auto
=================================================================
Warning occurred while setting a field of an RoSGNode
-- Tried to set nonexistent field "streamurl" of a "DetailsScreen" node
   at line 83 of file pkg:/components/screens/DetailsScreen/DetailsScreen.brs
=================================================================

```

Why don’t you start by pasting the actual debugger output, rather than just one line.

And it would make it easier to read if you enclosed your code and debugger output in code tags:

```auto
[code][/code]

```

---

<div class="post-metadata">

**Author:** ![EnTerr](https://avatars.discourse-cdn.com/v4/letter/e/ba9def/32.png) [@EnTerr](https://forum.developer.roku.com/u/EnTerr)\
**Post date:** [May 21, 2016, 1:51am UTC](https://forum.developer.roku.com/t/brightscrpt-says-this-is-a-error/5107/9 "2016-05-21T01:51:19Z")

</div>

```auto
    ' don't start animation on devices that don't support it
    m.model = createObject("roDeviceInfo").getModel()
    'Get the first character of the model number. Anything less than a 4 corresponds to a device not suited to animations.
    first = Left(m.model, 1).trim()
    if first <> invalid and first.Len() = 1
        firstAsInt = val(first, 10)
        if (firstAsInt) > 3
...

```

This code is so bad!  
Where do i start, even! Hey you - anonymous bad coder @ RokuCo:

1. Why are you using member variable **m.model** when only local var is ever needed?

2. Why are you doing **.trim()** when **left(,1)** is already returns string of length 1? How could **trim()** possibly improve on that?

3. Why are you checking “ **first \<\> invalid** ” when right above that you have readily trusted the result will never be **invalid**? (cue: **.trim()** call would never fly with **invalid** )

4. There are string functions **len(s), left(s, ..)**. And there are string methods **s.len(), s.left(..)** that do (about) the same. You can use either - but why can’t you make up your mind using the same group in the same code segment?

5. Why are you using **val(, 10)** instead of **val()**? (What, in case BrightScript suddenly stops using decimal system? … yet **.getModel()** keeps using it?)

6. Why are you using parenthesis around variable name in “**if (firstAsInt) \> 3**”?

7. Why all this gallimaufry when you could have just done it in 1 line: `**if createObject("roDeviceInfo").getModel()**  **> "3" then** ` ? Have you never heard that strings compare lexicographically?!

8. Why are you even doing this??? What makes you think models \>4000 are better at animation? Hint: try 5000 (roku tv) vs 3600 (new stick)

Such code penmanship is so inept, that you Sir are doing disservice to humanity by writing code that other developers will read. Find something else to do with your life.

Come to think of it… all i got curious was why would somebody check the first digit of model number re animation. But the more i read, closer i get to contemplating which is less painful - continue analyzing it or gouge my eyes?

---

<div class="post-metadata">

**Author:** ![EnTerr](https://avatars.discourse-cdn.com/v4/letter/e/ba9def/32.png) [@EnTerr](https://forum.developer.roku.com/u/EnTerr)\
**Post date:** [May 21, 2016, 3:09am UTC](https://forum.developer.roku.com/t/brightscrpt-says-this-is-a-error/5107/10 "2016-05-21T03:09:03Z")

</div>

This said, let me throw something positive - an article to read and consider:  
[https://medium.com/@alexewerlof/what-is … .cac5o8fpy](https://medium.com/@alexewerlof/what-is-shitty-code-handwriting-ae7c00708b#.cac5o8fpy)

Some great quotes there - plus amusing idea on the sexual reproduction of bugs :mrgreen:

---

<div class="post-metadata">

**Author:** ![Komag](https://avatars.discourse-cdn.com/v4/letter/k/5fc32e/32.png) [@Komag](https://forum.developer.roku.com/u/Komag)\
**Post date:** [May 21, 2016, 6:36am UTC](https://forum.developer.roku.com/t/brightscrpt-says-this-is-a-error/5107/11 "2016-05-21T06:36:02Z")

</div>

That was maybe too harsh, if valid 😐
