create global variable

Discuss your Lua playlist, album art and interface scripts.
Ffb_Boy_30
New Cone
New Cone
Posts: 4
Joined: 22 Oct 2020 16:28

create global variable

Postby Ffb_Boy_30 » 03 Nov 2020 22:09

Hi,
I'm looking for a solution to create a global variable to store the handle : "fd" when I create a socket

Code: Select all

fd = vlc.net.connect_tcp("localhost",54293)
I've made an event which fire every input_changed , I need to send the player state.

Code: Select all

PlayerState = vlc.var.get(vlc.object.input(), "state")
At first time the socket is created but when I jump in my event at the second time the socket handle is gone.
I don't know how to create a global variable .
Thanks

ProtoSahara
New Cone
New Cone
Posts: 7
Joined: 17 Oct 2020 17:05

Re: create global variable

Postby ProtoSahara » 17 Nov 2020 19:47

Where is fd defined? To have it stay the same for multiple events and not be redefined it should be set outside of the input_changed() function (activate(), the global scope, etc...).

Also, if you are making a tcp connection to send the player state, it might just be better to set up and tear down the connection on every input_changed event, rather than trying to store an open connection.
For example,

Code: Select all

function input_changed() fd = vlc.net.connect_tcp("localhost", 54293) -- send player state and do other stuff vlc.net.close(fd) end


Return to “Scripting VLC in lua”

Who is online

Users browsing this forum: No registered users and 17 guests