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.

problem with arrays

Old posts that have not been replied to for several years.
Locked
n
nANDu
Voice
Posts: 15
Joined: Sun May 22, 2005 1:05 am

problem with arrays

Post by nANDu »

If i set an array ex($nick) in a proc test. How do i get $ex($nick) in a different proc?

Code: Select all

bind join -|- * text
bind pubm -|- * example

proc test {nick uhost handle channel} {
  set ex($nick) 1
  return 0
}

proc example {nick uhost handle channel text} {
  global ex
  putlog "ex($nick) is $ex($nick)"
  return 0
}

set array ex {}

Tcl error [example]: can't read "ex(nandu)": no such element in array
n
nANDu
Voice
Posts: 15
Joined: Sun May 22, 2005 1:05 am

Post by nANDu »

Should i make this array ex global in both test and example proc's ? I think it works

Code: Select all

proc test {nick uhost handle channel} {
  global ex
  set ex($nick) 1
  return 0
} 
D
Dizzle
Op
Posts: 109
Joined: Thu Apr 28, 2005 11:21 am
Contact:

Re: problem with arrays

Post by Dizzle »

nANDu wrote:If i set an array ex($nick) in a proc test. How do i get $ex($nick) in a different proc?

Code: Select all

bind join -|- * text
bind pubm -|- * example

proc test {nick uhost handle channel} {
  set ex($nick) 1
  return 0
}

proc example {nick uhost handle channel text} {
  global ex
  putlog "ex($nick) is $ex($nick)"
  return 0
}

set array ex {}

Tcl error [example]: can't read "ex(nandu)": no such element in array
the proc name doest match "bind join -|- * text" "proc test {nick uhost handle channel} {"

maybe this help
D
Dizzle
Op
Posts: 109
Joined: Thu Apr 28, 2005 11:21 am
Contact:

Post by Dizzle »

nANDu wrote:Should i make this array ex global in both test and example proc's ? I think it works

Code: Select all

proc test {nick uhost handle channel} {
  global ex
  set ex($nick) 1
  return 0
} 
No you dont have too set it global in the first proc because too use the command "set" so he doesnt reqornis it in de "global" cmd
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

nANDu wrote:Should i make this array ex global in both test and example proc's ? I think it works

Code: Select all

proc test {nick uhost handle channel} {
  global ex
  set ex($nick) 1
  return 0
} 
Yes, if you make it global in both procs then you can manipulate this array as you wish in these procs, and your code will work.
Locked