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.

"No such variable" in my script

Old posts that have not been replied to for several years.
User avatar
Thunderdome
Op
Posts: 187
Joined: Tue Mar 15, 2005 4:42 pm

"No such variable" in my script

Post by Thunderdome »

I made this one myself with some help.
The whole script works... but at the first time I run it, I get in the partyline:

Code: Select all

Tcl error [our:pubtrigger]: can't read "served": no such variable
followed by

Code: Select all

Soulseek server is up and running! - http://www.remmelt.com/slskboard/status.php.
After that, the script will always work fine. So it just does not work the first time it is called....
How can I fix this? What am I missing?


Code: Select all

# slsk.tcl by 5th Raider 
# Requires egghttp.tcl 

# Config 
set url "http://www.remmelt.com/slskboard/status.php" 
set pubtrigger "!soulseek" 
# End of config 

if {![info exists egghttp(version)]} { 
  putlog "egghttp.tcl was NOT successfully loaded." 
  putlog "slsk.tcl has not been loaded as a result." 
 } else { 
  proc your_callbackproc {sock} { 
    global url served 
    set headers [egghttp:headers $sock] 
    set body [egghttp:data $sock] 
    regsub -all "\n" $body "" body 
    regsub -all -nocase {<br>} $body "<br>\n" body 
    regexp {the server (.*)<br>} $body {} served 
    putlog "Soulseek server $served - $url." 
} 

bind pub - $pubtrigger our:pubtrigger 

proc our:pubtrigger {nick uhost hand chan text} { 
  global url served 
  set sock [egghttp:geturl $url your_callbackproc] 
  putserv "NOTICE $nick : Soulseek server $served - $url" 
  return 1  
  } 
 putlog "slsk.tcl by 5th Raider - Loaded." 
}  
D
Deniska
Voice
Posts: 4
Joined: Mon Apr 25, 2005 12:30 am
Location: Tomsk, Russia
Contact:

Post by Deniska »

Code: Select all

# slsk.tcl by 5th Raider 
# Requires egghttp.tcl 
# Config 
set url "http://www.remmelt.com/slskboard/status.php" 
set pubtrigger "!soulseek" 
# End of config 
if {![info exists egghttp(version)]} { 
  putlog "egghttp.tcl was NOT successfully loaded." 
  putlog "slsk.tcl has not been loaded as a result." 
 } else { 
  proc your_callbackproc {sock} { 
    global url served 
    set headers [egghttp:headers $sock] 
    set body [egghttp:data $sock] 
    regsub -all "\n" $body "" body 
    regsub -all -nocase {<br>} $body "<br>\n" body 
    set served ""
    regexp {the server (.*)<br>} $body {} served 
    putlog "Soulseek server $served - $url." 
} 
bind pub - $pubtrigger our:pubtrigger 
proc our:pubtrigger {nick uhost hand chan text} { 
  global url served 
  set sock [egghttp:geturl $url your_callbackproc] 
  putserv "NOTICE $nick : Soulseek server $served - $url" 
  return 1  
  } 
 putlog "slsk.tcl by 5th Raider - Loaded." 
}  
Variable $served does not exists in first launch. Just set her before regexp.
Dixi.
User avatar
Thunderdome
Op
Posts: 187
Joined: Tue Mar 15, 2005 4:42 pm

Post by Thunderdome »

This does not work... give exactly the same error... :(
User avatar
YooHoo
Owner
Posts: 939
Joined: Thu Feb 13, 2003 10:07 pm
Location: Redwood Coast

Post by YooHoo »

Thunderdome wrote:This does not work... give exactly the same error... :(
You have to comprehend how variables work. You get this error because you have not defined set served "whatever this does". I suggest you read this Tcl Variables Tutorial as well as Assigning values to variables to better understand what you are doing incorrectly
:wink:
User avatar
Thunderdome
Op
Posts: 187
Joined: Tue Mar 15, 2005 4:42 pm

Post by Thunderdome »

I've read it (I had read similar in other sites). But I don't understand...

Code: Select all

set served "regexp {the server (.*)<br>} $body {} served "

should this be it?
I don't get it.. if the variable was not defined, it should never work, and not only not work at the first time... :\
Served returns the "value" between "the server" and "<br>" in that webpage.
that is what this means:

Code: Select all

regexp {the server (.*)<br>} $body {} served
so with this, served should be defined...
but does not get it at first.... seems like it has to be run once to have something in "memory" to give the second time...
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

your regexp evaluates with no match the first time, therefore served is not set (check the docs); initialize it explicitly, set served something
User avatar
Thunderdome
Op
Posts: 187
Joined: Tue Mar 15, 2005 4:42 pm

Post by Thunderdome »

I basically I must put..

Code: Select all

set served "this is bull, but hey, the server went on vacations"
so something will show? or can I have a "real" msg based on the info it gets from that webpage?

Or... can I make the bot run it one time by itself, so the next time is always ok?

Thanks for the help.. :D
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

I've no idea what soulseek server is, but it seems that regexp should actually be regsub
User avatar
Thunderdome
Op
Posts: 187
Joined: Tue Mar 15, 2005 4:42 pm

Post by Thunderdome »

http://www.remmelt.com/slskboard/status.php

It just gets inf ofrom this page, taht shows the status of Soulseek server.
User avatar
Thunderdome
Op
Posts: 187
Joined: Tue Mar 15, 2005 4:42 pm

Post by Thunderdome »

any news on this one? I've tried serveral stuff, no sucess... :\
User avatar
^DooM^
Owner
Posts: 772
Joined: Tue Aug 26, 2003 5:40 pm
Location: IronForge
Contact:

Post by ^DooM^ »

Try putting this

Code: Select all

set served ""
under

Code: Select all

set pubtrigger "!soulseek"
This should create the variable ready for use.
The lifecycle of a noob is complex. Fledgling noobs gestate inside biometric pods. Once a budding noob has matured thru gestation they climb out of their pod, sit down at a PC, ask a bunch of questions that are clearly in the FAQ, The Noob is born
User avatar
Thunderdome
Op
Posts: 187
Joined: Tue Mar 15, 2005 4:42 pm

Post by Thunderdome »

In fact it does... but it shows only the text without saying the part I want from the site... that is, it does not say if the server is up or down.... :\
and I can't understand why...
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

Thunderdome wrote:In fact it does... but it shows only the text without saying the part I want from the site... that is, it does not say if the server is up or down.... :\
and I can't understand why...
read a good TCL book, or learn online using tons of useful resources; study other people's code, and try to code stuff yourself, starting with basic things

then you won't be that puzzled and unable to grasp simple notions like global variables
User avatar
Thunderdome
Op
Posts: 187
Joined: Tue Mar 15, 2005 4:42 pm

Post by Thunderdome »

I tried to make that myself... and I have read about variables in online tutorials... but I don't get what is wrong...
:|
I just need help to fix it... can you just write was is wrong?
Thanks
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

well, help has already been given to you, I wonder what of the following you didn't understand:
  • served is declared as global, but it's used (possibly) before initialization:

    Code: Select all

        regexp {the server (.*)<br>} $body {} served
        putlog "Soulseek server $served - $url." 
    
    here, if [regexp] doesn't find a match, served won't be set, hence the "No such variable" error on the next line; in TCL, unlike C, every variable must be initialized (with [set] or implicitly by some other commands) before being used
  • that [regexp], judging by its arguments, needs to be changed to [regsub]
Locked