Results 1 to 9 of 9

Thread: Set NR Lua var

  1. #1
    Join Date
    Mar 2006
    Location
    Sydney, Australia
    Posts
    787

    Default Set NR Lua var

    Hi,
    I am a little fuzzy on something and i was hoping someone could set me straight, is the best way to create a NR Lua var as an exact copy of a Girder Lua var to use NetRemote.RunLua?
    Thanks
    Dan

  2. #2
    Join Date
    Nov 2003
    Location
    Hove, E Sussex, UK
    Posts
    4,005

    Default

    Why can't you just use SetVariable?

    Code:
    NetRemote.SetVariable("VariableName", VariableName)
    Thx, Dan

    Onwards and Upwards!
    http://www.danward.co.uk

  3. #3
    Join Date
    Jun 2005
    Posts
    760

    Default

    What's confusing about this one is that if the second VariableName in Dan's example is a single Girder Lua variable, it will update a NR variable in NR. But if VariableName is a Girder Lua table, then it will update a NR Lua table of the same name. Clear as mud?

  4. #4
    Join Date
    Nov 2003
    Location
    Hove, E Sussex, UK
    Posts
    4,005

    Default

    Of course another option is, if you do not want a table to be a lua variable in NR, you can use send mapped table, so that your girder table appears as a table in NR, in the NR variable space.

    See this code as an example, I parse a table in G5, to send just what I need in to the NR variable space of NR.

    Code:
    SageTV.SendtoNR = function(self, tab)
        local n = 1    
    
        for i, child in pairs (SageTV[tab]) do
    
            map = {
            
                Channel = {label = "Channel"},
                Title = {label = "Title"},
                Episode = {label = "Episode"},
                Description = {label = "Description"},
                Duration = {label = "Duration", func = function(duration)
                                                            if duration then
                                                                return (duration / 60)
                                                            end
                                                        end},
                Favorite = {label = "Favorite", func = function(id)
                                                    if id then
                                                        return "1"
                                                    else
                                                        return "0"
                                                    end end},
                StartTime = {label = "StartTime", func = function (starttime)
                                                                if starttime then
                                                                    local i
                                                                    local t = {}
                                                                    for i in string.gfind(starttime, "%d+") do
                                                                        table.insert(t, i)
                                                                    end
                                                                    return t[3].."/"..t[2].."/"..t[1].." at ".. t[4]..":"..t[5].." hrs"
                                                                end
                                                            end},
                AiringID = {label = "AiringID"},
                MediaID = {label = "MediaID"},
                
            } 
            
            val = {
                
                Channel = SageTV.Channels[child.airing.channelId].channelName,
                Title = child.title,
                Episode = child.episode or "n/a",
                Description = child.description,
                Duration = child.airing.duration,
                Favorite = child.airing.favoriteId,
                StartTime = child.airing.startTime,
                AiringID = child.airing.sageDbId,
                MediaID = child.airing.mediafile.sageDbId
                
                }
        
            NetRemote.SendMappedTable(val, map, "SageTV."..tab.."."..n..".")--child.airing.sageDbId
            n = n +1
    
        end
    end
    If you are happy with the table being stored in the lua variable space of NR, you can always use the VariableName.Changed, to trigger an action to convert to NR variables.
    Thx, Dan

    Onwards and Upwards!
    http://www.danward.co.uk

  5. #5
    Join Date
    Mar 2006
    Location
    Sydney, Australia
    Posts
    787

    Default

    Hi,

    Thanks to both of you for your help
    Quote Originally Posted by dsmes View Post
    What's confusing about this one is that if the second VariableName in Dan's example is a single Girder Lua variable, it will update a NR variable in NR. But if VariableName is a Girder Lua table, then it will update a NR Lua table of the same name. Clear as mud?
    this is the info i was after its a Girder Lua table i want to duplicate in the NR Lua Variable space.

    Also thanks Dan for that working example of SendMappedTable, last time i tried to use that i couldnt get my map right!

    Dan

  6. #6
    Join Date
    May 2004
    Location
    Cardigan, UK
    Posts
    9,278

    Default

    SendMappedTable isn't a simple function, but it is pretty powerful.

    Note that if you pass in nil as the second parameter then all the field specified in the table will be set to the empty string.
    --Rob

  7. #7
    Join Date
    Nov 2003
    Location
    Hove, E Sussex, UK
    Posts
    4,005

    Default

    Rob, just pointed out to me I have set up my map in the loop, so it repeated gets called, the map, can be moved out of the loop
    Thx, Dan

    Onwards and Upwards!
    http://www.danward.co.uk

  8. #8
    Join Date
    Mar 2006
    Location
    Sydney, Australia
    Posts
    787

    Default

    hello again,
    so lets say i want to send my Girder Lua table one variable at a time to NR Lua vars, now should i be using RunLua?
    sandshoe
    Dan

  9. #9
    Join Date
    May 2004
    Location
    Cardigan, UK
    Posts
    9,278

    Default

    Possibly, but it's easier to just send the entire table using NetRemote.SetVariable

    The problem with RunLua is that you won't get any errors reported, which can be confusing (although they might appear in DebugView, the won't currently appear in NRD's Lua console).
    --Rob

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •