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 vars reset :(

Old posts that have not been replied to for several years.
P
ProXy
Op
Posts: 126
Joined: Sun Aug 11, 2002 3:09 pm

No vars reset :(

Post by ProXy »

Hi,

I wrote a script that reads the current channel and removes the # in front of the channel. Then i simply responds the result. When i run the script for the first time it works right. But if i run the script more often in other channels i still get the other channel...
What could be the reason for this?
Do i have to unset the vars?

Here is the code:

Code: Select all

		set getipchannel [string replace $channel 0 0]
		regsub -all <IP> $getipoutput $getipip getipoutput
		regsub -all <PORT> $getipoutput $getipport getipoutput
		regsub -all <CHANNEL> $getipoutput $getipchannel getipoutput
		putserv "PRIVMSG $channel :$getipoutput"
ProXy
d
darko``
Op
Posts: 121
Joined: Sun Sep 08, 2002 5:33 pm
Location: Malta

Post by darko`` »

Um :| Are you sure you pasted the right code? It doesn't match your query :|
Else, try to post more specific question.
Ignorant and lazy people will save 30 minutes by chosing simple config file. Smart ones will save 3000 minutes of *everyone's* time by opting for complete config file.
P
ProXy
Op
Posts: 126
Joined: Sun Aug 11, 2002 3:09 pm

Post by ProXy »

Yes it was right: The posted source will first remove the first sign of the string, and then replace an URL like "http://<IP>:<PORT>/>CHANNEL> with the right settings.

The problem is, that the <CHANNEL> is the same value in all channels i run the script after the first time!
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

The error must be somewhere else. If this works the first time, then it'll work every time. But maybe you're mismanaging the variables and using old data. So we'd need to see the other code.
P
ProXy
Op
Posts: 126
Joined: Sun Aug 11, 2002 3:09 pm

Post by ProXy »

The script works the first time and sets a channel to the var $getipchannel.

I do NOT unset this var. When i wanted to run the script in other channels the value of $getipchannel is the same old channel like the first run!

The other code does NOt have influence to the problem so there`s no need to paste it!
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

The only explanation is for it to be another part of the script.

Maybe your method of getting the channel name in the ifrst place is at fault.

As you noted in your first post, the code does at it says it should.

But you also aknoledge that there is more code.

Just becuase an economy car can do 100 MPH, doen't mean that when it breaks down ater 4 hours solid driving, the engine should be to blame. It's the drivers fault, even more so for not acknoledginf so.

This applies here. Just because the script works the first time round, do no blame one simgle part of it, when it breaks. You need to look at the whole problem.
P
ProXy
Op
Posts: 126
Joined: Sun Aug 11, 2002 3:09 pm

Post by ProXy »

Code: Select all

#### Flag for global users ####
set getipglobalflag "*"

#### Flag for local users #####
set getiplocalflag "*"

####### Public command ########
set getipcommand "!stats"

### Port of the stats site ####
set getipport "50000"

####### Default Output ########
set getipoutput "Stats @ http://<IP>:<PORT>/<CHANNEL>"

#### END OF CONFIGURATION #####

set getipusage "Usage: $getipcommand"
bind pub $getipglobalflag|$getiplocalflag $getipcommand pub:getip
proc pub:getip { nick uhost handle channel arg } {
	global botnick getipoutput getipport getipusage
	if {[llength $arg]!=0} {
		putserv "PRIVMSG $channel :$getipusage"
	} else {
		set getipip [lindex [exec host [lindex [split [getchanhost $botnick] @] 1]] end]
		set getipchannel [string replace $channel 0 0]
		regsub -all <IP> $getipoutput $getipip getipoutput
		regsub -all <PORT> $getipoutput $getipport getipoutput
		regsub -all <CHANNEL> $getipoutput $getipchannel getipoutput
		putserv "PRIVMSG $channel :$getipoutput this is channel $channel"
	}
}
putlog "LOADED: GetIP v0.1"
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

s stated, it was somthing else int he script.

you are making the variable "getipoutput" global, which means, any changes made to it are saved.

Thus, next time the script is called, it no longer has the <IP> or so on in it, as these have been replaced with the values from the previous call.

You should use an intermediate var in the regsub.

IE

at the begining of the proc, use "set int $getipoutput"

Then use "$int" instead of "$getipoutput" in the regsub's.
P
ProXy
Op
Posts: 126
Joined: Sun Aug 11, 2002 3:09 pm

Post by ProXy »

Just to do it right: I should not set $getipoutput as global, but set $int = $getipoutput. Do i have to set $int before or behind the proc? Perhaps you could paste a little example... :)
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

Perhaps you could get a clue :P

You fail to understand what is wrong in this script.

If you read my post, and understand why it's happening, you will locate the answer.

Once again, maybe you should be trying this yourself.

You may not have access to a machine, but this is not our problem, or should I get the forms together to call myself rover or spot!
P
ProXy
Op
Posts: 126
Joined: Sun Aug 11, 2002 3:09 pm

Post by ProXy »

I don`t understand why there should be a solution if i use another var for regsub. I still need to make the other global to set $int with the right value!
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

This is rather simple

Take the following code

Code: Select all

set var "ppslim is"
proc test {} {
  global var
  set var "$var cool"
  puts stdout "$var"
}
puts stdout "$var"
test
puts stdout "$var"
[code]

Runt his scode through tclsh and you get

[code]
ppslim is
ppslim is cool
ppslim is cool
Maybe i didn't want to change the value of var outside of the proc, but I needed to change part of it, only inside the proc.

EG, I wnated it to post this following output

Code: Select all

ppslim is
ppslim is cool
ppslim is
To do this, i should have used the code

Code: Select all

set var "ppslim is"
proc test {} {
  global var
  set temp "$var cool"
  puts stdout "$temp"
}
puts stdout "$var"
test
puts stdout "$var"
[code]

Follow the same sort of procedure in your own script.
P
ProXy
Op
Posts: 126
Joined: Sun Aug 11, 2002 3:09 pm

Post by ProXy »

But I don`t want to extend the var. All your examples set a var to another one adding some stuff...
The script is only running once, and the output has to be http://IP:PORT/ROOM

Seems that i am too stupid for this..

I only want to set the var like http://<IP>:<PORT>/<CHANNEL> before the proc and then replace the 3 Parts by vars... (http://$ip:$port/$room)

Then I can simply output the URL because all vars have the right value!
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

My example is exactly the same as yours.

The only2 differances, mine doesn't do what you want it, and it doesn't use regsub.

You say mine changes the value of var, and add stuff too it.

Then look at your own. It may not add stuff to it, but instead changes somthing. In eccance, adding is a change.

If it is a real must, and you realy are too thick, here is my example again, using resubs.

Code: Select all

set sub "ppslim is <WORD>"
set word "cool"

proc test {} {
  global sub word
  regsub -all -- "<WORD>" $sub $word sub
  puts stdout "$sub"
}

puts stdout "$sub"
test
puts stdout "$sub"
This will produce

Code: Select all

ppslim is <WORD>
ppslim is cool
ppslim is cool
When in your thinking, you want it to produce

Code: Select all

ppslim is <WORD>
ppslim is cool
ppslim is <WORD>
the command "regsub" uses the following format

regsub ?switches? expression input-string subtituation-spec varname

Switches = Items that can effect how the command interets the input-string or expression. EG, rather than substituting the first match, replace them all.

expression = The item within input-string that should be replaced (seeing as this is a regular expression command, you can use these here).

input-string = the string of text, that the substitutions should be made on.

substitution-spec = what should the matches be replaced with

varname = where do we store the new item

using this small rement of code

Code: Select all

set text "hello <WORD> all"
regsub -all -- "<WORD> $text "to" text
We can see, that the variable $text, should be searched for the text "<WORD>.

If found, it should be replaced with the text "to".

The end result should be saved to the variable text.

As such, this command overwrites the variable text, with a new one.

This is exactly the same as what is happening in yours.

You are overwriting you input string "http://<IP>:<PORT>/<CHANNEL>" with the value you want to send to the channel.

If, for example, the first time you run the script,
<IP> = 192.168.254.1
<PORT> = 24
<CHANNEL> = mirchelp (#mirchelp with the # removed, as you wished)

Then all works well, and the message is displayed correctly.

Next time the script is run, the input-string becomes "http://192.168.254.1:24/mirchelp"

This is not want you want.

Now look at my prevous post, to see an example at how things should be done.
P
ProXy
Op
Posts: 126
Joined: Sun Aug 11, 2002 3:09 pm

Post by ProXy »

OMG.

You just explained what i wanted to explain to you. The source you pasted is nearly like mine, the same error. You don`t have to tell me some examples about my error, but try to say how to do it right. And please try to do it so, that i will follow it! And i do NOT want to have a random output. The output has to depend on the channel the eggdrop is atm!

I know how to use regsub and what it does. But i DO NOT KNOW how to solve the problem that the vars always have the same value!

I ran my script in #abc so the URL is http://123.123.123.123:1234/abc and it IS RIGHT!
I ran it again in another channel but the output is still the same! In all your posts you describe how to use regsub like i already did!

The Script shall always look the chan the eggdriop is on atm and replace <CHANNEL> with that channel!
Locked