mIRC Homepage
Posted By: MauS How to read a random file line into a variable? - 05/05/03 10:15 PM
I know that /play -r Origins.txt plays a random line from file?

But how to read a line into a variable?

I need this for making random quit messages.
var %Var $read(file.txt)
Yeah, thanks
var %Var = $read(file.txt)
Nimue, /var needs no = - /var %var bleh will work as /var %var = bleh does.
Most of the time it will work without the = yes. Sometimes it will not.
It is good practice to use the correct syntax ALL the time to avoid errors when the incorrect syntax will not work.
Anyway i just needed $read(file.txt). Thanks again
Code:
$read(file.txt,$rand(0,$lines(file.txt)))


not really needed but smile
That rand statement is completly useless. When you don't provide the line to read from, the alias does the same exact thing. Can you say unneccisary typing?
Code:
//var %b $remove(abc,%a) | echo -s %a

Type that.

/var %var = value is the documented way, nowhere in the help file does it say that you can omit the =. There are other things that aren't mentioned in the help file and do work, but this one (omitting the =) is an abuse imo. Mainly because there are cases where it breaks.
//var %b $remove(abc,%a) | echo -s %a
this doesnt work because you echo %a - but %a doesnt exist.
type //var %b $remove(abc,b) | echo -s %b
this works
You're missing the point. If you see more carefully, the example I mentioned does not generate an "/echo: insufficient parameters", but a "$remove(): invalid parameters": the script halts before it reaches the /echo command. Just replace "echo -s %a" with "echo -s something %a" if you're not convinced yet. Also note that your example works because it's a different case. I used a variable as a second parameter to an identifier (%a and $remove()) , you used a letter as a second parameter to the same identifier. Test stuff some more, you'll definitely get a better picture of how things (don't) work.
nope, you are missing the point - the question was if the = is necessary in the /var command.
I denied that because its not. Your example has nothing to do with this topic because //var %b $remove(abc,%a) | echo -s %a of course will give an * Invalid format: $remove - this is because %a doesnt exist (so it doesnt return anything), but u use it as a substring in $remove, it's the same as if you would use $remove(abc,)
so the point is that the error is not that the = is missing in the //var command but in your $remove, if you use it properly, e.g. //var %b $remove(abc,b) it works perfect.
Please don't keep it up, you're making a fool of yourself.

You want a variable that exists? Type this:
Code:
//var %b b | var %a $remove(abc,%b) | echo -s %a

Now type this:
Code:
//var %b b | var %a = $remove(abc,%b) | echo -s %a

Now read the thread again more carefully and let's hope you get it.
© mIRC Discussion Forums