Sharing code: Random Media Cvs scripting

Hi All,

When I started testing the Brightsign I choiced one application areas: game machine or promotional machine. Probably you know the concept: Entering on a commercial center you could try to win something using a sort of "slot machine" and some coupon received from retailers. Recently I saw a lot of interactive system PC based doing this kind of job.. When I understood the potentials of Brightsign I choiced this market area additionally to the normal digital signage market.

Then I ordered my Brightsign and thanks to roku staff I was finally able to try the demo using a cvs file.

Then I decided to modify the standard autorun.bas (version 1.1.6) to make what I called "Random media scripting".

I liked so much the approach of csv file choiced by Roku because it's simple and clearly visible when I discovered how to import correctly the csv file (separated with comma instead of semicolon used in Eu).

A standard CSV file on excel looks like


Then I need to have a script where in a specific moment the media is not fixed but is based on some probability to happen, a situation like "head and tail" trial.. 1/2 probablity.. or less frequently 1/4 probability.. if the case is correct i need to playback one media (mpeg or bmp) and in all the other case another media (mpeg or bmp).

Then I created a syntax to describe this on csv file


See the string "rdn:4:vinto1.mpg:perso1.mpg"

Where "rnd:" is a keyword to tell we will a random media state
4 is the probability.. mean 1/4 won probability
vinto1.mpg is the media when you won (vinto Italian word like won)
perso1.mpg is the media when you loose (perso is the italian work loose)

Then I changed the autorun.bas to be able to make this working

First of all I changed the version name of the brightscript


version="1.1.6" print "autoplay script version ";version;" started" REM REM autoplayer REM May 14, 2007 REM Copyright (c) 2006-2007 Roku, LLC. to version="1.1.6BEP" print "autoplay script version ";version;" started" REM REM autoplayer REM May 14, 2007 REM Copyright (c) 2006-2007 Roku, LLC. Then I added a command called RANDOM on the initialization to make sure all the random number series will change each start of the brightsign and I also activate the debug output normally disabled. REM REM Init some constants REM RANDOM ' just to reset pseudo random number.. debug=-1 'set to -1 to turn on debug prints; 0 to turn them off root="\" and finally the code. You need at first to put the conditional execution of the subrutine that change the state based on probability. I left some part of original code to make for you easy to identify the area to change. Simply search the "new_state:" label.. Between the comments (REM) the conditional execution.. new_state: if debug then print "new_state: state=";state REM ' Conditional Random media Scripting if left(state,4)="rnd:" then gosub play_random endif REM ' End of Random Media Scripting gosub lookup_state if debug then print"after lookup_state: state=";state;", idx=";stateidx playfile$=state_table(stateidx, 1) And just at the end of the autorun.bas add the following subrutine REM Play Random offer the possibility to playback a conditional media REM based on probability of random numbers REM Syntax rnd:probablilty:firstmedia:secondmedia REM 5 bep1 bep2 REM 5 16 27 (just as example) play_random: bep1=instr(5,state,":") bep2=instr(bep1+1, state, ":") media1=mid(state,bep1+1, bep2-bep1-1) media2=mid(state,bep2+1) bep2=(rnd(val(mid(state,5,bep1-1)))=1) state=media2 : if debug then print "The Random event is:";bep2; if bep2 then state=media1 if debug then print" then playback ";state;" file" return

For your convenience I also copied this new autorun.bas on this link on my server

I hope this work could help other people around the forum to imagine other ideas to share.

Have a nice random scripting <!-- s;) --><img src="{SMILIES_PATH}/icon_wink.gif" alt=";)" title="Wink" /><!-- s;) -->



Please sign in to leave a comment.