Page 1 of 1

create global variable

Posted: 03 Nov 2020 22:09
by Ffb_Boy_30
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

Re: create global variable

Posted: 17 Nov 2020 19:47
by ProtoSahara
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