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: 
geebs
Visitor

Data Type Conversion for TargetRect values

There's something simple that I'm not understanding about data type conversions. Need a little help.
Trying to set the width and height of a text rectangle. Harcoding the numbers works, however, now I need to set the width and height from variables.
According to the docs (and testing) I have to first convert my variables to integer type. I tried appending a "%" to my variables but still get Data Type Conversion errors.

I get a value from my xml file...
rectWidth = xml.text_rectW.getText()
rectWidth is now 500

however, its still a string data type
how do I convert this to an integer so I can set my textbox rectangle width? Becuse this does not work...

rectWidth% = xml.text_rectW.getText()
rectHeight% = xml.text_rectH.getText()

mytext = []
mytext.Push({
Text: "some text to help make you boogie all night long with all the ladies"
TargetRect: { x:10, y:10, w: rectWidth%, h: rectHeight% }
})

the text displays fine but the text rectangle is the whole width and height of the screen.
0 Kudos
2 REPLIES 2
RokuChris
Roku Employee
Roku Employee

Re: Data Type Conversion for TargetRect values

You can convert a string to an int with ToInt() http://sdkdocs.roku.com/display/RokuSDK ... ToIntAsInt
or StrToI() http://sdkdocs.roku.com/display/RokuSDK ... gAsDynamic

BrightScript Debugger> ? type("5".ToInt())
Integer
BrightScript Debugger> ? type(StrToI("5"))
Integer
0 Kudos
geebs
Visitor

Re: Data Type Conversion for TargetRect values

Awsome, thanks!
strtoi() worked for me. My example:

rectW = xml.text_rectWidth.getText()
rectW = strtoi(rectW)

Now I can set my text rectangle width, height and also XY coords. Thanks again. 😄
0 Kudos