greubel
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2012
08:43 AM
Brightscript parameter reference
Is it possible to pass a parameter by reference instead of by value ? According to the documentation, arrays types are passed by reference but is there a way to pass the address of a value into a subroutine ?
7 REPLIES 7
belltown
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2012
09:04 AM
Re: Brightscript parameter reference
You can make the value an array element and pass the array to your function. To access the value you would use value [0]:
value = [12345]
callByValue (value)
print value [0]
sub callByValue (value as object)
value [0] = 54321
end sub

TheEndless
Channel Surfer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2012
09:56 AM
Re: Brightscript parameter reference
I'd probably go with an associative array wrapper (e.g., refParam = { Value: valueToPassByRef }), similar to what belltown suggested, but as an alternative for intrinsic types, if you box them first (or explicitly CreateObject them) and specify the function parameter "as Object", you can use the setter to reset the value.
Sub Main()
myInt = 1
myInt = Box(myInt)
print "Before:"; myInt
ResetInteger(myInt)
print "After:"; myInt
End Sub
Sub ResetInteger(input As Object)
input.SetInt(10)
End Sub
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)

RokuJoel
Binge Watcher
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2012
11:28 AM
Re: Brightscript parameter reference
On a related note, the performance issues that were seen with regards to Associative Array access should be fixed or at least significantly improved in the latest 4.8 release.
- Joel
- Joel
greubel
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2012
06:11 PM
Re: Brightscript parameter reference
Thanks ! This appears to work.
Sub test()
a = 1
a = box(a)
b = "Now is the time"
b = box(b)
? "a = " Type(a) " val = " a
? "b = " Type(b) " val = " b
chk( [9,a,b,0] )
? "a = " Type(a) " val = " a
? "b = " Type(b) " val = " b
end
End Sub
Sub chk( in as dynamic )
? "in = " type(in)
? in
in[1].SetInt(2)
in[2].SetString("The quick brown fox")
End sub
-----------------------------------------
a = roInt val = 1
b = roString val = Now is the time
in = roArray
9
1
Now is the time
0
a = roInt val = 2
b = roString val = The quick brown fox
Sub test()
a = 1
a = box(a)
b = "Now is the time"
b = box(b)
? "a = " Type(a) " val = " a
? "b = " Type(b) " val = " b
chk( [9,a,b,0] )
? "a = " Type(a) " val = " a
? "b = " Type(b) " val = " b
end
End Sub
Sub chk( in as dynamic )
? "in = " type(in)
? in
in[1].SetInt(2)
in[2].SetString("The quick brown fox")
End sub
-----------------------------------------
a = roInt val = 1
b = roString val = Now is the time
in = roArray
9
1
Now is the time
0
a = roInt val = 2
b = roString val = The quick brown fox
MazeWizzard
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2012
06:37 PM
Re: Brightscript parameter reference
"RokuJoel" wrote:
On a related note, the performance issues that were seen with regards to Associative Array access should be fixed or at least significantly improved in the latest 4.8 release.
- Joel
Not to hijack the thread or anything...glad you got the byvalue/byreference thing working OP. But this statement is monumental. I guess I'll have to pick up my Roku development again, since performance of AA's (and objects in AA's) was a bottleneck that caused me to stop. At least I should do some benchmarking/profiling again.
Wish it had been in the release notes. I had all but given up and put it aside. Didn't bother. Now I missed a month. My bad. Should check occasionally anyway I guess.
Thanks for the info. 🙂
kbenson
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2012
10:25 AM
Re: Brightscript parameter reference
Efficient dissemination of changes/fixes/features in new firmware releases has always been a problem. At least they have a wiki now, so maybe they can make some use of it to help this.
-- GandK Labs
Check out Reversi! in the channel store!
Check out Reversi! in the channel store!

RokuJoel
Binge Watcher
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2012
11:16 AM
Re: Brightscript parameter reference
Yeah, in the release publication we just said "performance improvements". I checked with engineering and was told that the fixes they were working on for AA's are indeed in the most recent release, (@ktbenson you might want to check with your performance testing suite to measure how much if any, significant improvement there is).
- Joel
- Joel