Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

return boolean value

Status
Not open for further replies.

Thodd

Technical User
Oct 21, 2006
27
BE
Hi,

I'm trying to get a boolean value from a procedure, so I can use it for an if-loop:

proc program {
$ns at $now getbool //ns runs the proc @ a certain time
if {$bool == 1} {
do something...
} else {
do something else...
}

}

proc getbool {
set bool 0
set req [expr $x - $y]

if {$req == 0} {
set bool 1
return $bool
} else {
do something....
}

}

Anyone who knows how to do this?
thx
 
You example is perfect but
Code:
  $ns at $now getbool
is an extension that I never seen.

Boolean values are 0 and 1 (0: false, 1: true)

To set a boolean value in a procedure:
Code:
  proc setBoolean {myArg} \
  {
    ...
    set boolean 1
    return $boolean
  }

To wait for a random delay:
Code:
  set delay [expr {int(10000 * rand())}]
  after $delay

To test a boolean returned value:
Code:
  if {[setBoolean $myArg]} { ... }

One last thing: if you want boolean to be a global variable (known in both the main program and the procedure) just write it ::boolean. This ensure that the boolean variable is a global variable.

HTH

ulis



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top