Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
dcrandall
Visitor

Brightscript line continuation marker/method?

I've caught myself sometimes needing to go extremely long in my lines, and I was wondering if there was a line-continuation marker I was missing.

IE:

if( (super = true) AND (cali = true) AND (fragil = true) AND (istic = true) AND (expi = true) AND (alidocious = true) )

Could be

if( (super = true) AND
(cali = true) AND
(fragil = true) AND
(istic = true) AND
(expi = true) AND
(alidocious = true) )

I think VisualBasic uses the '_' character, making this:

if( (super = true) AND _
(cali = true) AND _
(fragil = true) AND _
(istic = true) AND _
(expi = true) AND _
(alidocious = true) )
0 Kudos
17 REPLIES 17
EnTerr
Roku Guru

Re: Brightscript line continuation marker/method?

I haven't found a line continuation character in B/S.

HHOS: try being brief. E.g. perhaps no checking if booleans equal true:
if super AND cali AND fragil AND istic AND expi AND alidocious: ...
0 Kudos
destruk
Streaming Star

Re: Brightscript line continuation marker/method?

I believe it is the semicolon -- " ; " -- as that works with print statements.
Print"Button Pressed msg: ";msg.GetIndex()

It's worth a try anyway.
0 Kudos
belltown
Roku Guru

Re: Brightscript line continuation marker/method?

I don't think the ";" works for line continuation.

Some statements can be continued on the next line without requiring a line continuation character, e.g.


longArrayAssignment = [
{
supercalifragilisticexpialidocious: {
super: true,
cali: true,
fragil: true,
istic: true
},
expi: true,
alidocious: true
}
]


But this won't work:


longArrayAssignment =
[ ' <-----
{
supercalifragilisticexpialidocious: {
super: true,
cali: true,
fragil: true,
istic: true
},
expi: true,
alidocious: true
}
]


Neither will this:


longArrayAssignment = [
{
supercalifragilisticexpialidocious:
{ ' <-------
super: true,
cali: true,
fragil: true,
istic: true
},
expi: true,
alidocious: true
}
]



I'm not quite sure why the first case works, but the other two don't. It seems somewhat random to me. Maybe one of the experts could explain.
0 Kudos
EnTerr
Roku Guru

Re: Brightscript line continuation marker/method?

"belltown" wrote:
I don't think the ";" works for line continuation.

Some statements can be continued on the next line without requiring a line continuation character, e.g.
...
I'm not quite sure why the first case works, but the other two don't. It seems somewhat random to me. Maybe one of the experts could explain.

That is the case only for list (array) and dictionary (AA) literals - and only IN-BETWEEN elements, AFAICT. That's why one of your examples works and not the other two. Parser is forgiving in the areas where comma separators should be - in particular you may omit the comma - or have superfluous one after the last list element. If i go in details: 1st non-working example - there is assignment left "open" on previous line; 2nd - there is "open" key-value pairing.

Regarding semicolon, that's a red herring: the syntax of PRINT statement dictates that arguments separated by "," will be printed spaced by a tab and if ";" instead - no spacing (concatenated).
0 Kudos
destruk
Streaming Star

Re: Brightscript line continuation marker/method?

The brightscript reference guide doesn't mention a line continuation feature so there probably isn't one.
Each line may contain a single statement, or a colon (:) may be used to separate multiple statements on a single line.
myname = "fred"
if myname="fred" yourname = "barney":print yourname

Some methods have a 'block form' which allows you to play with the formatting on multiple lines. For the OP's original example he'll have to use two if statements.
If A=x and b=x
If c=x and d=x
end if
end if

The semicolon on a print statement prevents the linefeed and merges it all onto the same line (per docs) - what Enterr said... 🙂
0 Kudos
EnTerr
Roku Guru

Re: Brightscript line continuation marker/method?

"destruk" wrote:
if myname="fred" yourname = "barney":print yourname
This ought to be the worst penmanship i have seen here yet. I tried it and it works but still... no "then" nor even ":" as a separator? <shivers>

Nesting IFs does not work for ORs but if one needs to shorten a line, one can always use a bogus variable:
bogus = Something OR something OR something OR dark side
bogus = bogus OR Something OR something OR something OR complete
if bogus then ...

There is something that bothers me though: there is no way to do multiline string literals in B/S! Personally I like Python's tripple-quotes:
s = """line 1,
line 2""" + ''' and
line 3'''
but knowing BRS origins, best case scenario it may grow Perl's <<<heredoc
0 Kudos
dcrandall
Visitor

Re: Brightscript line continuation marker/method?

This came up because we like to keep it javascripty here at this particular shop, and a couple things I would like to break-up are:
1) Function declarations. I know it's bad to have 47 (I exaggerate, but you get my point) parameters to a function, but, sometimes you have to break the rules like an artist.
2) control statements. Sometimes they're just complex and they have to be.
0 Kudos
belltown
Roku Guru

Re: Brightscript line continuation marker/method?

"dcrandall" wrote:
This came up because we like to keep it javascripty here at this particular shop, and a couple things I would like to break-up are:
1) Function declarations. I know it's bad to have 47 (I exaggerate, but you get my point) parameters to a function, but, sometimes you have to break the rules like an artist.
2) control statements. Sometimes they're just complex and they have to be.

If you really feel the need to have 47 function parameters like an artist, you can simulate that with something like:

function test (args as object)
print args.param1
print args.param2
print args.param3
print args.param4
print args.param5
print args.param6
' ...
print args.param47
end function

test ({
param1: "abc",
param2: "def",
param3: "ghi"
param4: 3.141,
param5: "xyzzy",
param6: Invalid,
' ...
param47: false
})



This will give you more flexibility over standard function arguments, as it allows you to pass parameters in any order, have any number of optional parameters, and pass any types in as any parameter -- as long as you have the appropriate code in the called function. These aren't necessarily "good" things, but to an artist that may not matter.

Also, Brightscript and Javascript are very similar in some ways as far as their object orientatedness is concerned. I don't quite understand why you feel that keeping your Brightscript "javascripty" requires the use of long lines and gazillions of function arguments. In all the thousands of lines of Javascript and Brightscript I've written, I've never felt the need for more than a handful of arguments in either language.
0 Kudos
dcrandall
Visitor

Re: Brightscript line continuation marker/method?

I'm not saying this is right for even a second, but I feel the need to respond to what I'm sure is something like hearing about how I eat peas with a knife (in the 47 parameters) and that some submarines really do have screen doors.

In the first instance, I'm just sort of following-along with our javascript code into brightscript...and there they do these adapters. The idea is that you want to have one place where you're taking webservice data and translating it into how you handle things natively, if for some reason the webservice needs to change.

In that case, it would seem like you could just pass the object to a function and do the change there... but, again, following-along, and I can see where they want to have one 'factory' method that takes those 47 parameters and bakes bread out of it.

The one legit case, is that I'm a stickler for type-checking, and it's easy to go beyond the traditional 80 character line limit.

function somefunction(descriptivename1 as string, descriptivename2 as integer, descriptivename3 as object, descriptivename4 as dynamic)

4 function parameters is pretty reasonable for a function.
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.