This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Multiuser global variables

Old posts that have not been replied to for several years.
Locked
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Multiuser global variables

Post by Ofloo »

My question:

i use a proc all the time over and over and over this proc uses global variables witch are unpossible to set within the proc like path and if i use cd the path is appended .. like set path c:\\
...........
cd test >> set path c:\\test\\

now my question if i where to make a multi user session like 2 users using the same proc at the same time .. for example in dcc sesions how would i be able to make the new user enter the home path and if the second user would brouse the files how would that work for the first user so my question


u set a variable

set test 1


within the proc u set the variable again .. by appending data or adding a value like expression
proc ...
global test

set test [expr $test + 1]


.. second users uses the path as well ..
now he is gone use global as well but the value of the number is not 1 any more cause the previous user has reset it .. to 2 so my question

how do i use global variables with in a multiuser envirement ..?

Not sur if i am making my self clear so .. plz do ask if there is something that isn't clear to u
XplaiN but think of me as stupid
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

Use an array with element names that is unique for each session (eg. the idx of a partyline user or some counter you increment each time you start a new session):

Code: Select all

set blah($id) something
Have you ever read "The Manual"?
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

could u give me small example ?? cause ... if u use id


like for example nick

set var($idx) c:\\

an example only can be used


example script like control:listen

Code: Select all

set var c:\\ 

proc test {idx arg} {
  global var
  if {....}{
    # also i can't set the new variable cause that would reset it each time i used it
    putdcc $idx "$var($idx)
  }
  if {....}{
    set var($idx) $var($idx)$arg
  }
}
simple example how would i solve this ..? cause control goes true the proc each time data comes up on the socket same as connect .. suppose u open second socket and second user where to use the global var ..

and i can't see any variable that checks if a variable is set execpt vwait but if it wouldn't set it would have to wait for ever ... and it has to happen in the proc cause once i do it outside the proc its a global variable again ..

so my problem is how do i set a varable when its not set yet and only when its not set .. or is there a command that checks if a variable is valid .. like valididx ..?

cause then i would be able to set the variable in an if string if its not set and when its is set it doesn't requere setting so ...

maybe i can use error or something cause if u trigger an unset variable an error occures but the thing is i do not understand error that well .. so if u could give me some pointers .. on that ?? like example string ??? and some info about that ..
XplaiN but think of me as stupid
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

Check out info exists. And I think you mean catch when you say "error" :) (catch can be used to avoid stopping execution if an error occurs)
Have you ever read "The Manual"?
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

right lol sorry its been a while and i use loads of samples from scripts to get the syntax ;) and they used error a lot so i assumed it was error instead of catch ..
XplaiN but think of me as stupid
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

Sorry for late answer wasn't able to dcc chat so wasn't able to work with the bot either but this is the result for

info exists $varname

Code: Select all

proc procname {..} {
  if {[info exists $varname]} {
    ......
  }
  ......
}
returns: No sutch variable "$varname" so its not realy what i was looking for .. :( but tnx for trying .. :) or am i doing something wrong also could be the case
XplaiN but think of me as stupid
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

Ofloo wrote:info exists $varname
returns: No sutch variable "$varname"
It does not :) This is the error: can't read "varname": no such variable - notice: no '$'
That error is from the variable substitution taking place BEFORE the arguments are passed to "info". '$' is only used when you want the value of a variable in tcl (you should know this by now), so the correct syntax would be 'info exists varname'. (unless the name of the variable you want to check for is stored in 'varname' of course :P)
Have you ever read "The Manual"?
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

never would of tought on using it like that but it works tnx man u been real help.
XplaiN but think of me as stupid
Locked