Entraides et échanges autour de la technologie Scol - Informations and exchanges on the Scol technology
Vous pouvez changer la langue de l'interface une fois inscrit - You can change the language once registered
You are not logged in.
i am trying to pass a channel object as an argument in a function call, is that permitted?
thx!
-h
Offline
thx that's what i thought...i'm dealing with a large function and i've lost track of the ()))))))...bluefish helps i'm pasting code in from another function.
Offline
The best method : one function = one action
Yes , thats my plan
Offline
Looking at the code that you guys write, it seems the best method is pass a local variable from one function to another until its needed, and once you have done what you have to do as a prerequisite for using the variable, use it when you are ready, in a simpler function. bluefish helps with understanding parenthesis problems, but only up to a certain point, for me at least.
Offline
A global variable can seem easier but it can be modified easily and independantly anywhere in the code. It is always dangerous. A local variable passed from a function to another function is usually safer.
In pratice, try to keep the same and explicit name for your local variables in each function. It helps you and heps a future developer to understand what you did.
I already wrote you something about that in the forum (local variable vs global variable).
Offline
About channels, you work with 3 channels at least :
- the channel of eyecandy,
- the channel of the player,
- the channel between the eyecandy and the player.
These 3 channels are differents. They must not be confused.
Offline
A global variable can seem easier but it can be modified easily and independantly anywhere in the code. It is always dangerous. A local variable passed from a function to another function is usually safer.
In pratice, try to keep the same and explicit name for your local variables in each function. It helps you and heps a future developer to understand what you did.
I already wrote you something about that in the forum (local variable vs global variable).
thx, i have everything working now, i can pass a channel between functions in one package and between packages in the same environment as a local variable
i did however have problems in passing a defcom variable (of the form defcomvariablename S) from one function to another and between packages. but since i am using only one channel between all the .pkgs of the vm using the defcom variable, i don't think there is any great harm done in leaving it as a global variable...although can this be done?
in english there is a phrase, 'hot potato', which means passing a hot potato from one person to another if you catch it, you throw it to someone else, since it's hot.
that's what i try to do with variables now. if i need the same variable in function 1 and 3 but not in function 2, i pass it through function 2 when function 1 calls function 2 which calls function 3, like a hot potato.
Offline
About channels, you work with 3 channels at least :
- the channel of eyecandy,
- the channel of the player,
- the channel between the eyecandy and the player.These 3 channels are differents. They must not be confused.
one thing i don't quite understand is that the channel from the player to eyecandy is created on the port that eyecandy is using for eyecandy's server, but eyecandy's channel to the player uses the eycandy's implicitly created _channel.
but i understand it enough to make it work.
Offline
That's why i had preferred to point out !
Be careful, _channel is not a variable, it is a function. It returns the current channel, one that is used when this function is called.
When you create a VM, a new channel is always automatically created.
A reminder, a channel is a couple : a network connection (in this case, a local connection) + an environment. An environment is all Scol api (if you prefer, all Scol language) + all loaded packages.
When a VM is conencting to another VM, another channel is also created : it is different (another network connection, local or distant) and the environment is often different too.
When you call _openchannel, you can give an environment (the third argument) :
usually it is either the current environment (= the same environment that the VM at this moment, and you add other packages later if you want) or you set "nil" and the new channel has the Scol apis only (minimal environment).
So, according the context, _channel returns the "linked" channel or the "VM" channel.
If you are not sure, define a variable for each one.
In the first VM :
typeof ChnVM = Chn;;
typeof ChnLinked = Chn;;
fun linkOtherVm ()=
set ChnLinked = _openchannel pif paf pof;
//...
fun main ()=
set ChnVM = _channel;
// ...
In the other VM, use the _connected function. This function is AUTOMATICALLY called by Scol when a connection is doing. If it exists, it executed (else it is ignored) :
typeof ChnFromAndToOtherVM = Chn;;
fun _connected ()=
set ChnFromAndToOtherVM = _channel;
0;;
and use the _closed function to set to nil when the connection is lost / killed / closed / ...
fun _closed ()=
set ChnFromAndToOtherVM = nil;
0;;
Thus, you should not be used _channel after that !
Offline
that's what i try to do with variables now. if i need the same variable in function 1 and 3 but not in function 2, i pass it through function 2 when function 1 calls function 2 which calls function 3, like a hot potato.
Yes.
Offline
thx for your explanation iri
Offline