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

Type Mismatch Object and Integer

 

m.CurrDateObject = FindCurrDateObject(m.itemContent.date)

?"title :"m.CurrDateObject.title //Here I got Type Mismatch Error When 0 comes
?"text :"m.CurrDateobject.text

 

'FindCurrDateObject Return Object when if condition true in function

'when if condition false then it's return 0

'Here, I received two different data types on the function 

  1. If Condition true => Object
  2. If Condition false => 0 as Integer

Can anyone suggest How can I manage this two data types on Roku?

 

function FindCurrDateObject(date as Integer) as Object
    m.date = CreateObject("roDateTime")
    m.myObject = {}
    for each item in m.global.itemArray
        now = m.date.AsSeconds()
                if (now >= date) then
                            m.myObject.title = item.title
                            m.myObject.text = item.text
                            return m.myObject 
                 //This below-mentioned part works, but it's called every time. I don't want to return the invalid value
                 'else 
                 'return invalid                      
             end if
    end for
end function

 

 

0 Kudos
1 REPLY 1
renojim
Community Streaming Expert

Re: Type Mismatch Object and Integer

If you want to return an Object sometimes and an Integer others, you have to make the return type of the function "Dynamic":

function FindCurrDateObject(date as Integer) as Dynamic

This can lead to other problems because you can't just test to see if it returns 0.  For example:

if FindCurrDateObject(date) = 0 then
   ' do whatever
end if

This will throw an error if FindCurrDateObject returns an object.  Likewise if it does return 0 then you'll get the error you're seeing when you try to access the returned value as an object (i.e., ?CurrDateObject.text)

To be honest, returning "invalid" is probably the better way to go since you can always test for a return of invalid.

There's probably other ways to accomplish whatever it is that you're trying to do like returning empty strings for title and text instead of 0 or invalid.

Roku Community Streaming Expert

Help others find this answer and click "Accept as Solution."
If you appreciate my answer, maybe give me a Kudo.

I am not a Roku employee.
0 Kudos