Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
onevoisses
Level 8

Array operation attempted on variable not DIM'd

I am working on updating my channel,here is a problem ,I manage to narrow down my problem and can reproduce it here.
I get this error as I tried to move from the spring board to the video screen

Array operation attempted on variable not DIM'd. (runtime error &he7) in ...kg:/source/AppSpringboard.brs(39)

039: PlayVideo(videos[msg.GetIndex()])
Backtrace:
Function showspringboardscreen(video As <uninitialized>) As Integer
file/line: /tmp/plugin/MBBAAAxy1j0...kg:/source/AppSpringboard.brs(39)
Function showposterscreen(videos As <uninitialized>) As Integer
file/line: /tmp/plugin/MBBAAAxy1j08/pkg:/source/AppMain.brs(82)
Function loadjsonfile() As
file/line: /tmp/plugin/MBBAAAxy1j08/pkg:/source/AppMain.brs(51)
Function main() As
file/line: /tmp/plugin/MBBAAAxy1j08/pkg:/source/AppMain.brs(15)

the springboard seems ok as content data is there
here is the function for the video player

Function PlayVideo(video as object) as integer


If I move from the posterscreen to the videoplayer the each video will play based on the array like here

if type(msg) = "roPosterScreenEvent"
if (msg.isListItemSelected())
'PlayVideo(videos[msg.GetIndex()]) ''This work with this'"2"
ShowSpringboardScreen(videos[msg.GetIndex()])
else if (msg.isScreenClosed())

any suggestions,I might have been away too long,so I am losing the "mojo"
Channel: Goaheadmission
O/S : Linux
Home media: MYTHROKUPLAYER With Homerun
0 Kudos
5 REPLIES 5\
RokuJoel
Roku Employee
Roku Employee

Re: Array operation attempted on variable not DIM'd

Try adding

print type(videos)
print msg.getindex()
print videos.count()
print videos[msg.getindex()]

immediately before PlayVideo(videos[msg.GetIndex()])

as a troubleshooting step. Maybe the index is higher than the number of videos in the array?

- Joel
0 Kudos
RokuMarkn
Level 8

Re: Array operation attempted on variable not DIM'd

You didn't show where you initialized the videos variable, but apparently it is not an array.

--Mark
0 Kudos
onevoisses
Level 8

Re: Array operation attempted on variable not DIM'd

here is the array
Function ShowPosterScreen(videos as object) as integer
posterScreen = CreateObject("roPosterScreen")
port = CreateObject("roMessagePort")
posterScreen.SetMessagePort(port)

contentList = CreateObject("roArray",25, true)
for each video in videos
poster = CreateObject("roAssociativeArray")
poster.ShortDescriptionLine1 = video.Title
poster.SDPosterURL = video.Image
poster.HDPosterURL = video.Image
contentList.push( poster )
end for


posterScreen.SetContentList( contentList )


here is the json

Function LoadJSONFile() as void
jsonAsString = ReadAsciiFile("pkg:/json/sample1.json")
m.json = ParseJSON(jsonAsString)

ShowPosterScreen(m.json.Videos)
End Function


this is what I get when i used the print statement

------ Running ------
SpringBoardButton Pressed: 5 index: 1
<uninitialized>
1
BrightScript Micro Debugger.
Enter any BrightScript statement, debug commands, or HELP.

'
'
Array operation attempted on variable not DIM'd. (runtime error &he7) in ...kg:/source/AppSpringboard.brs(40)

040: print videos[msg.getindex()]
Backtrace:


I had 20 in the array but 21 videos so I move it to 25
also print videos.count() gives the following error

'Dot' Operator attempted with invalid BrightScript Component or interface reference. (runtime error &hec) in ...kg:/source/AppSpringboard.brs(40)

040: print videos.count();
do you think my problem is
 ShowPosterScreen(m.json.Videos)
Channel: Goaheadmission
O/S : Linux
Home media: MYTHROKUPLAYER With Homerun
0 Kudos
RokuMarkn
Level 8

Re: Array operation attempted on variable not DIM'd

When you printed "videos", the output was "<uninitialized>". That's your problem. Perhaps you created the videos variable in a different scope than where you're using it.

--Mark
0 Kudos
onevoisses
Level 8

Re: Array operation attempted on variable not DIM'd

Feedback
Thanks everyone
kbenson clarified the "m" for me in this post
http://forums.roku.com/viewtopic.php?f=34&t=31874
and jbrave-Joel in this post
http://forums.roku.com/viewtopic.php?f=34&t=39414 so I modify my loadfeed() to

Function LoadJSONFile() as void
jsonAsString = ReadAsciiFile("pkg:/json/sample1.json")
feedinfo = ParseJSON(jsonAsString)
ShowPosterScreen(feedinfo.Videos)
End Function


RokuMarkn pointed out that
When you printed "videos", the output was "<uninitialized>". That's your problem. Perhaps you created the videos variable in a different scope than where you're using it.


I found out I was calling videos to play on the videoscreen when I only needed one video so I modify

PlayVideo(videos[msg.GetIndex()])
to match my
Function PlayVideo(video as object) as integer


and so thanks Joel and endless for this beautiful tip on"
Need Help Understanding CreateObject()"

http://forums.roku.com/viewtopic.php?p=255658&sid=cbe3599496ebe07c5760788be91faeac

and finally Joel and whomever said "print" is your friend might I also add "STOP"

Here are the results of the print

Using Json

------ Running ------
msg: idx: 8
roArray
8
20
Image: http://xxx.xxx.xxx.xxx/someimage.png
Url: http://xxx.xxx.xxx.xxx:1935/xxx/xxx/playlist.m3u8

Title: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

SpringBoardButton Pressed: 5 index: 1
roAssociativeArray
1
showVideoScreen | msg = Stream started. | index = 0
showVideoScreen | msg = HLS segment info | index = 0
showVideoScreen | msg = HLS segment info | index = 7000
showVideoScreen | msg = HLS segment info | index = 14000
showVideoScreen | msg = Playback paused. | index = 0


Using XML Parsing
Using xml

------ Running ------
msg: idx: 7
roXMLList
7
20
<Component: roXMLElement>
SpringBoardButton Pressed: 5 index: 1
roXMLElement
1
showVideoScreen | msg = Stream started. | index = 0
showVideoScreen | msg = HLS segment info | index = 0
showVideoScreen | msg = HLS segment info | index = 10000
showVideoScreen | msg = Playback paused. | index = 0


I do value this help
Channel: Goaheadmission
O/S : Linux
Home media: MYTHROKUPLAYER With Homerun