mIRC Homepage
Posted By: TKS writing variables in .txt - 14/03/06 03:39 PM
Hello all,

I'm trying to write in an .txt file. So far everything goes well. The problems start when trying to write different variables in one line. Simple said, when I look at the .txt is shows the TEXT %var1, instead of the value of %var1 (can be both text and non-text) Simple said my script looks like this:

Code:
on text
set %var1 -
set %var2 -
set %var3 -
write test.txt %var1 $+ _ $+ %var2 $+ _ $+ %var3

When I open the .txt it shows %var1_%var2_%var3 and NOT
-_-_-

So actually what i want to know is how to write the value of a variable in a .txt and not the name smirk

Thanks for an reply's grin
Posted By: Pap Re: writing variables in .txt - 14/03/06 05:09 PM
try

write test.txt $eval(%var1 $+ _ $+ %var2 $+ _ $+ %var3)
Posted By: hixxy Re: writing variables in .txt - 14/03/06 05:22 PM
The only time that should happen is if you typed /write from the commandline.
Posted By: TKS Re: writing variables in .txt - 14/03/06 06:09 PM
Quote:
The only time that should happen is if you typed /write from the commandline.


well I don't cool
Posted By: TKS Re: writing variables in .txt - 14/03/06 06:15 PM
Quote:
try

write test.txt $eval(%var1 $+ _ $+ %var2 $+ _ $+ %var3)


Tried but doesn't work. The variables ARE valid, IE they show up in the remote.ini file
Posted By: Pap Re: writing variables in .txt - 14/03/06 08:31 PM
Could you paste your entire script please?
Posted By: Pap Re: writing variables in .txt - 14/03/06 08:33 PM
Oh, I have an idea/suggestion: don't use "%var1" "%var2", etc. try using meaningful variable names. Maybe mIRC is having issues with those names?
Posted By: mIRCManiac Re: writing variables in .txt - 14/03/06 08:34 PM
Worked here 6.17
Posted By: TKS Re: writing variables in .txt - 14/03/06 08:58 PM
Quote:
Could you paste your entire script please?


Code:
on 1:TEXT:!add*:#: {
  if (($chan == %chan) && ($2 != $null)) {
    set % $+ $2 $+ .name -
    set % $+ $2 $+ .surname -
    set % $+ $2 $+ .address -
    set % $+ $2 $+ .phone -
    set % $+ $2 $+ .spend -
    set % $+ $2 $+ .advance -
    set % $+ $2 $+ .coffee -
    set % $+ $2 $+ .final -
    write template.txt % $+ $2 $+ .name _ % $+ $2 $+ .surname _ % $+ $2 $+ .address _ % $+ $2 $+ .phone _ % $+ $2 $+ .spend _ % $+ $2 $+ .advance _ % $+ $2 $+ .coffee _ % $+ $2 $+ .final
  }
}


So what I want is a line written in my .txt which shows -_-_-_(etc). May look strange, but the - are editable when the script continues, the _ are seperators for my php site.

Anyway, the var
Code:
 % $+ $2 $+ .phone 
is beiing set, so this var will be named %Eric.phone and has a value of -
Posted By: MikeChat Re: writing variables in .txt - 14/03/06 09:00 PM
the only thing i can think of is they have an alias that is /write -n
or some other /write alias that is replacing the %variable with $+(%,variable)
Posted By: hixxy Re: writing variables in .txt - 14/03/06 09:03 PM
Code:
on 1:TEXT:!add*:#: {
  if (($chan == %chan) && ($2 != $null)) {
    set % $+ $2 $+ .name -
    set % $+ $2 $+ .surname -
    set % $+ $2 $+ .address -
    set % $+ $2 $+ .phone -
    set % $+ $2 $+ .spend -
    set % $+ $2 $+ .advance -
    set % $+ $2 $+ .coffee -
    set % $+ $2 $+ .final -
    write template.txt [color:red]$eval([/color]% $+ $2 $+ .name _ % $+ $2 $+ .surname _ % $+ $2 $+ .address _ % $+ $2 $+ .phone _ % $+ $2 $+ .spend _ % $+ $2 $+ .advance _ % $+ $2 $+ .coffee _ % $+ $2 $+ .final[color:red],2)[/color]
  }
}
Posted By: TKS Re: writing variables in .txt - 14/03/06 09:04 PM
Quote:
the only thing i can think of is they have an alias that is /write -n
or some other /write alias that is replacing the %variable with $+(%,variable)


Running plain mIRC 6.17 confused
Posted By: MikeChat Re: writing variables in .txt - 14/03/06 09:09 PM
Quote:
Quote:
Could you paste your entire script please?


Code:
on 1:TEXT:!add*:#: {
  if (($chan == %chan) && ($2 != $null)) {
    set % $+ $2 $+ .name -
    set % $+ $2 $+ .surname -
    set % $+ $2 $+ .address -
    set % $+ $2 $+ .phone -
    set % $+ $2 $+ .spend -
    set % $+ $2 $+ .advance -
    set % $+ $2 $+ .coffee -
    set % $+ $2 $+ .final -
    write template.txt % $+ $2 $+ .name _ % $+ $2 $+ .surname _ % $+ $2 $+ .address _ % $+ $2 $+ .phone _ % $+ $2 $+ .spend _ % $+ $2 $+ .advance _ % $+ $2 $+ .coffee _ % $+ $2 $+ .final
  }
}


you went through the trouble of making the vars, and then didnt use them.

try
Code:
    write template.txt $(% $+ $2 $+ .name $+  _ ,2)

Or $eval($+(%,$2,.name,_),2)


see if it writes correctly -_
Posted By: MikeChat Re: writing variables in .txt - 14/03/06 09:18 PM
or maybe
Code:
on 1:TEXT:!add*:#: {
  if ($chan == %chan) {
    set %nick $$2
    set %nick $+ .name - 
    set %nick $+ .surname -
    set %nick $+ .address -
    set %nick $+ .phone -
    set %nick $+ .spend -
    set %nick $+ .advance -
    set %nick $+ .coffee -
    set %nick $+ .final -
    write template.txt %nick.name _ %nick.surname _ %nick.address _ %nick.phone _ %nick.spend _ %nick.advance _ %nick.coffee _ %nick.final
  }
}


on 1:TEXT:!add*:#: {
if ($chan == %chan) {

could be
Code:
on 1:TEXT:!add*:#yourchannel: {
  set %nick $$2
  set %nick $+ .name - 
  set %nick $+ .surname -
  set %nick $+ .address -
  set %nick $+ .phone -
  set %nick $+ .spend -
  set %nick $+ .advance -
  set %nick $+ .coffee -
  set %nick $+ .final -
  write template.txt %nick.name _ %nick.surname _ %nick.address _ %nick.phone _ %nick.spend _ %nick.advance _ %nick.coffee _ %nick.final
  unset %nick.*
}


unless the channel name needs to be dynamic
Posted By: TKS Re: writing variables in .txt - 14/03/06 09:50 PM
Quote:


you went through the trouble of making the vars, and then didnt use them.

try
Code:
    write template.txt $(% $+ $2 $+ .name $+  _ ,2)

Or $eval($+(%,$2,.name,_),2)


see if it writes correctly -_


it works smile

but what do you mean with not using the vars?
Posted By: TKS Re: writing variables in .txt - 14/03/06 09:56 PM
Quote:
or maybe
Code:
on 1:TEXT:!add*:#: {
  if ($chan == %chan) {
    set %nick $$2
    set %nick $+ .name - 
    set %nick $+ .surname -
    set %nick $+ .address -
    set %nick $+ .phone -
    set %nick $+ .spend -
    set %nick $+ .advance -
    set %nick $+ .coffee -
    set %nick $+ .final -
    write template.txt %nick.name _ %nick.surname _ %nick.address _ %nick.phone _ %nick.spend _ %nick.advance _ %nick.coffee _ %nick.final
  }
}


on 1:TEXT:!add*:#: {
if ($chan == %chan) {

could be
Code:
on 1:TEXT:!add*:#yourchannel: {
  set %nick $$2
  set %nick $+ .name - 
  set %nick $+ .surname -
  set %nick $+ .address -
  set %nick $+ .phone -
  set %nick $+ .spend -
  set %nick $+ .advance -
  set %nick $+ .coffee -
  set %nick $+ .final -
  write template.txt %nick.name _ %nick.surname _ %nick.address _ %nick.phone _ %nick.spend _ %nick.advance _ %nick.coffee _ %nick.final
  unset %nick.*
}


unless the channel name needs to be dynamic


yes chan needs to be dynamic wink

and somehow your solution is not working. It writes though, but the vars (needed for further editing) are named %nick.address etc. So not the unique one's i need like %eric.address or %myla.address
Posted By: MikeChat Re: writing variables in .txt - 14/03/06 11:20 PM
Quote:
yes chan needs to be dynamic wink

and somehow your solution is not working. It writes though, but the vars (needed for further editing) are named %nick.address etc. So not the unique one's i need like %eric.address or %myla.address


oh ok, the nick ($2) being kept as a var wasn't obvious from what i saw, even though you had shown each var having the value of - (which I took to be a substitute for what you are really setting it to)
Posted By: DaveC Re: writing variables in .txt - 15/03/06 04:11 AM
I think for a start u might have missed a point about dynamicly named vars (then again my head started to hurt trying to read this thread)

//set % $+ $2 $+ .name -
//echo $(% $+ $2 $+ .name -,2)

more preferably
//set $+(%,$2,.name) -
//echo $($+(%,$2,.name),2)

The reason for this is, in the SET your not evaluating the var name at all the word SET well cause mirc to go "oh wow i better not get the contents of this since im setting something into it.
aka
//SET %blah frog
//SET %blah dog
it would be no good if in the second line mirc went "well %Blah is frog, so we have //SET frog dog"

And in any access of the var, mirc needs to be told, it needs to evaluate this twice instead of once, becuase the first evaluation puts the var name together, the second then evalautes it for its contents.
//echo $+(%,bl,ah)
%blah
//echo $($+(%,bl,ah),2)
dog

Try this ** Im assuming this is example code, as you might as well just /write template.txt -_-_-_-_-_-_-_- **
Code:
on 1:TEXT:!add*:#: {
  if (($chan == %chan) && ($0 >= 2)) {
    set $+(%,$2,.name) - 
    set $+(%,$2,.surname) -
    set $+(%,$2,.address) -
    set $+(%,$2,.phone) -
    set $+(%,$2,.spend) -
    set $+(%,$2,.advance) -
    set $+(%,$2,.coffee) -
    set $+(%,$2,.final) -
    write template.txt $+( $($+(%,$2,.name),2) , _ , $($+(%,$2,.surname),2) , _ , $($+(%,$2,.address),2) , _ , $($+(%,$2,.phone),2) , _ , $($+(%,$2,.spend),2) , _ , $($+(%,$2,.advance),2) , _ , $($+(%,$2,.coffee),2) , _ , $($+(%,$2,.final),2) )
  }
}


just to be clear $($+(%,$2,.name),2) is accessing the dynamic var, around that is $+( var , _ , var , _ , etc etc )
Posted By: TKS Re: writing variables in .txt - 21/03/06 06:00 PM
Thank you for your detailed info, was exactly what I needed! cool
© mIRC Discussion Forums