Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Search instead for 
Did you mean: 
btpoole
Level 7

Return of Function

Having difficulty getting something to work. I have a function that produces an integer. That integer is passed into another function. The second function produces a return that needs to be called by a third function. How do I call the return of the second function when it is depending on a value to be passed. See below

Create myfunc() as object
procedures performed
value
myfuncb(value)
end function

Create myfuncb(x as integer) as integer
valuex=x
procedures performed using valuex
value reached
return value
End function

Create myfuncd() as object
newvalue=myfuncb()
end function

How do you call myfuncb() to get the return? When I try this I get error for wrong parameters since I assume the function is looking for the value of x to be passed. Sorry if this is confusing.
0 Kudos
6 Replies
dcrandall
Level 7

Re: Return of Function

One thing you can do is

function whatever(x=0 as integer)

to specify a default parameter, if that's what you're asking.

EDIT: Unless you want that 'value' passed to myfuncd somehow, in which case I would 'recommend' attaching that to the global object from getglobalAA.
0 Kudos
btpoole
Level 7

Re: Return of Function

Thanks I'll try that, I don't need to pass the x value to the final function just the return of the function.
0 Kudos
RokuMarkn
Level 7

Re: Return of Function

Using a global for something like this is very poor form, even if you get it to work. I am not quite following your description of what you want to do, but perhaps this will help:


I have a function that produces an integer. That integer is passed into another function.


Ok, that code would look like this:

x1 = first_function()
x2 = second_function(x1)
....

function first_function() as Integer
...
return something
end function

function second_function(x as Integer) as Integer
...
return something
end function



The second function produces a return that needs to be called by a third function. How do I call the return of the second function when it is depending on a value to be passed.

I can't figure out what you mean by "a return that needs to be called by a third function". If you're saying that you want to pass the integer returned from the second function to a third function, you do that the same way:

third_function(x2)
...

function third_function(x as Integer) as Void
...
end function


--Mark
0 Kudos
btpoole
Level 7

Re: Return of Function

Edit.
Let me try to clarify.
First function creates roListscreen, takes msg.Index and passes that to a second function. The second function uses the index number to ParaseJson file to get a url. The url is then passed into another function which uses it to create another url. The final url needs to be a return, not passed into a function. The problem I get is when I attempt to get the return of the final function, I get wrong number of parameters.



There are three functions. The first produces a value that is passed into the second. The third needs to take the return of the second function and continue. I can pass the value of the first into the second but don't know how to call the return of the second by the third.
First function pass value x thru
second(x)

Second function accepts value of x thru
Create second(x as integer) as integer
value=x
return value
end function

Now I need to call the return value by the third.
Third function
y=second(x)
end function

When I attempt to y=second(), I get error wrong number of parameters. I have also tried y=second(x) but I have nothing to pass as x and don't want to pass anything as x. Maybe I am creating too many functions with dependencies on each other.
0 Kudos
RokuMarkn
Level 7

Re: Return of Function

I still don't understand some of your terminology but based on your description I would say the code looks like this


function first() as Void
...
url = GetUrl(msg.GetIndex())
other_url = GetOtherUrl(url)

end function

function GetUrl(index as Integer) as String)
ParseJson ....
return url
end function

function GetOtherUrl(url as String) as String
' transform url
return other_url
end function


--Mark
0 Kudos
btpoole
Level 7

Re: Return of Function

Thank you all for any consideration given to this matter. Please disregard now, I was really over thinking this. I have found a solution.
Thanks again
0 Kudos