Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Search instead for 
Did you mean: 
railfan
Level 7

Brightscrpt says this is a error

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 <NEWLINE>, 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
0 Kudos
10 Replies
joetesta
Level 10

Re: Brightscrpt says this is a error

I think your structure of using "Left" is incorrect; 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;
    deviceInfo = CreateObject("roDeviceInfo")
deviceName = deviceInfo.GetModel()
modelFirstDigit = deviceName.Left(1).ToInt()
aspiring
0 Kudos
belltown
Level 7

Re: Brightscrpt says this is a error

"joetesta" wrote:
I think your structure of using "Left" is incorrect; 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%28sasStri...
https://github.com/belltown/
0 Kudos
joetesta
Level 10

Re: Brightscrpt says this is a error

0 Kudos
belltown
Level 7

Re: Brightscrpt says this is a error

"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/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!
https://github.com/belltown/
0 Kudos
RokuMarkn
Level 7

Re: Brightscrpt says this is a error

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
0 Kudos
railfan
Level 7

Re: Brightscrpt says this is a error

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

When i saw the error after installing the brighscript stuff I was like hum how do I fix this???
0 Kudos
belltown
Level 7

Re: Brightscrpt says this is a error

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:

=================================================================
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:
[code][/code]
https://github.com/belltown/
0 Kudos
EnTerr
Level 8

Re: Brightscrpt says this is a error

    ' 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?
0 Kudos
EnTerr
Level 8

Re: Brightscrpt says this is a error

This said, let me throw something positive - an article to read and consider:
https://medium.com/@alexewerlof/what-is ... .cac5o8fpy

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