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: 
matrixebiz
Roku Guru

Re: Brightscript Sub and Function Routine

So with 'Sub' I can declare a value to Something without having to return that value back out of the routine like I would have to do with a 'Function'? or are you meaning something different?

Something = Door
Somthing = Sub()  or  Somthing = Function()


Sub()
Change Something to = "Window"
End Sub

Function()
Change Something to = "Window"
return window
End Function
0 Kudos
squirreltown
Roku Guru

Re: Brightscript Sub and Function Routine

"matrixebiz" wrote:
So with 'Sub' I can declare a value to Something without having to return that value back out of the routine like I would have to do with a 'Function'? or are you meaning something different?

You are not required to return something from a function.
Kinetics Screensavers
0 Kudos
matrixebiz
Roku Guru

Re: Brightscript Sub and Function Routine

Okay, thank you
0 Kudos
Komag
Roku Guru

Re: Brightscript Sub and Function Routine

sometimes I want to conditionally cancel a function with an empty RETURN, and if I plan to do that, I just have to add the AS VOID to the FUNCTION at the top or else I'll get a Return error. 
Ex:
FUNCTION mapScrollOne(dir) AS VOID
map = m.drAA.map
IF NOT m.mAA.flL[map.mapFl][ 1] THEN RETURN
IF map.mInvert THEN dir = oppFace(dir)
moveY = 0
moveX = 0
mSYp = map.mapScrollY
mSXp = map.mapScrollX
d = m.sy.sett.scrollSz
IF       dir = 0: moveY = - d: mSYp = mSYp - d
  ELSEIF dir = 1: moveX =   d: mSXp = mSXp + d
  ELSEIF dir = 2: moveY =   d: mSYp = mSYp + d
  ELSEIF dir = 3: moveX = - d: mSXp = mSXp - d
END IF
IF checkMapRoom(dir, mSYp, mSXp)
  map.mapScrollY = mSYp
  map.mapScrollX = mSXp
  offsetMap(moveY, moveX)
  playSound("menuForw", 0, 0, 0, FALSE, 1, 1)
END IF
END FUNCTION
0 Kudos
squirreltown
Roku Guru

Re: Brightscript Sub and Function Routine

"Komag" wrote:
sometimes I want to conditionally cancel a function with an empty RETURN, and if I plan to do that, I just have to add the AS VOID to the FUNCTION at the top or else I'll get a Return error. 

Or you could return 0
Kinetics Screensavers
0 Kudos
marcelo_cabral
Roku Guru

Re: Brightscript Sub and Function Routine

"Komag" wrote:
sometimes I want to conditionally cancel a function with an empty RETURN, and if I plan to do that, I just have to add the AS VOID to the FUNCTION at the top or else I'll get a Return error. 

You can also use Return from a Sub the same way.
0 Kudos
Komag
Roku Guru

Re: Brightscript Sub and Function Routine

"squirreltown" wrote:
"Komag" wrote:
sometimes I want to conditionally cancel a function with an empty RETURN, and if I plan to do that, I just have to add the AS VOID to the FUNCTION at the top or else I'll get a Return error. 

Or you could return 0

Functions are Integers by default? If I have to declare AS INTEGER then it's easier to type AS VOID and save myself the trouble later on of typing that 0. But if you can do 0 by default without the AS VOID that's nice to know.
0 Kudos
EnTerr
Roku Guru

Re: Brightscript Sub and Function Routine

"Komag" wrote:
Functions are Integers by default?

Functions and variables in B/S are "as Dynamic", unless otherwise explicitly declared. That means you can return ANY of The Types.
0 Kudos
Komag
Roku Guru

Re: Brightscript Sub and Function Routine

Ah yes, if I would have applied my noggin a little harder I might have realized/remembered that! At least, I knew it regarding variables.
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.