Forum Discussion

rsromeo's avatar
rsromeo
Channel Surfer
15 years ago

RUNNING A REMOTE SCRIPT

Can someone please clue me in on how I would go about calling and running a remote BRS script. I tried RUN but it only works running another script from within the package. I need to run a remote script from a URL. The remote script has special functions that I will need to update occasionally which is why I want to keep it remote rather than include it with the package. Thanks for your help.

10 Replies

  • "rsromeo" wrote:
    Can someone please clue me in on how I would go about calling and running a remote BRS script. I tried RUN but it only works running another script from within the package. I need to run a remote script from a URL. The remote script has special functions that I will need to update occasionally which is why I want to keep it remote rather than include it with the package. Thanks for your help.

    I haven't tried it, but it seems like it should work... have you tried doing roUrlTransfer.GetToFile() to a "tmp:/" path and running that?
  • Indeed, you can download files into tmp and run from there. I've tested this quite a bit.
  • rsromeo's avatar
    rsromeo
    Channel Surfer
    thanks. I tried it but it doesn't seem to run the remote script. does the remote script need to be formatted a special way? It is a .brs file that contains an roList. Here's what I tried doing...

    var = CreateObject("roUrlTransfer")
    var.SetUrl("http://website.com/test.brs")
    var.GetToFile("tmp:/test.brs")

    Then I tried both Run and Eval but neither seems to work.
    Eval("tmp:/test.brs")
    Run("tmp:/test.brs")
  • Have you checked GetLastRunCompileError() and GetLastRunRuntimeError() to see if your script is producing errors?
  • rsromeo's avatar
    rsromeo
    Channel Surfer
    yes. actually in the debugger, looks like Run is running the script but the error I get says

    /tmp/plugin/FABAAAmzGSZ1/tmp:/test.brs(64): runtime error ec: 'Dot' Operator attempted with invalid BrightScript Component or interface reference.

    In remote script, I am making reference to an object in the calling script which is why I think I'm getting the error. My remote script looks something like this...

    list = CreateObject("roList")
    list.AddTail("abc")
    list.AddTail("123")
    list.ResetIndex()
    x= list.GetIndex()
    while x <> invalid
    if show.Title = x then
    screen.AddButton(2, "test")
    end if
    x = list.GetIndex()
    end while

    The error is on the line that says (if show.Title). "show" is an object in the calling script. how can I make the calling script and remote script interact with each other so the variables are recognized in each?
  • "rsromeo" wrote:
    The error is on the line that says (if show.Title). "show" is an object in the calling script. how can I make the calling script and remote script interact with each other so the variables are recognized in each?

    According to the SDK documentation, the Run function takes optional arguments that can be passed to the scripts Main() function.

    "rsromeo" wrote:
    does the script being called need to have Main() ?

    I believe with Run() it does. Optionally, you could do a GetToString() and Eval() the result, which I'm pretty sure uses the context of the running script.
  • rsromeo's avatar
    rsromeo
    Channel Surfer
    thank you all for your help, especiallyTheEndless - you rock!!! Used GetToString() and Eval() and IT WORKS!!! thanks again!! 🙂
  • "rsromeo" wrote:
    yes. actually in the debugger, looks like Run is running the script but the error I get says

    /tmp/plugin/FABAAAmzGSZ1/tmp:/test.brs(64): runtime error ec: 'Dot' Operator attempted with invalid BrightScript Component or interface reference.

    In remote script, I am making reference to an object in the calling script which is why I think I'm getting the error. My remote script looks something like this...

    list = CreateObject("roList")
    list.AddTail("abc")
    list.AddTail("123")
    list.ResetIndex()
    x= list.GetIndex()
    while x <> invalid
    if show.Title = x then
    screen.AddButton(2, "test")
    end if
    x = list.GetIndex()
    end while

    The error is on the line that says (if show.Title). "show" is an object in the calling script. how can I make the calling script and remote script interact with each other so the variables are recognized in each?


    Unless you are testing method equivalence (not return value), shouldn't that be "show.Title()" instead of "show.Title"?

    My original testing on this was to convert an existing app of mine to be entirely loaded from the network. To do so, I changed references to files shipped with it tmp:/ paths, and in the initialization routine for it, had it download and store the files in tmp:/. After that, which still works as a standalone app, I simply had a small 10-20 line app that downloaded the script files and did a Run() on them. Think of it as identical to sideloading your app (needs a main, etc) except you have to use tmp:/ for files and either download them to tmp:/ ahead of time or within the downloaded code. If you think of it that way, it's fairly easy to debug using the normal sideloading process, and then switch to downloaded code after most the bugs have been worked out.