mIRC Homepage
Posted By: Cygnata $read command not finding file - 19/08/19 06:19 PM
I own the Skeleton_in_the_Closet dicebot, based off the Dem Bones/Bone Devil code. One of the commands in the file tells the bot to search a crit table and randomly display a message from the file. However, no matter where I place the file, he's not seeing it! He's been offline for a couple years, but it worked fine before.

Relevant code:

; nifty little critical strike table; reads numbered lines from text based on d100 result.
on *:text:!crit*:#: {
set %crit.roll $rand(1,100)
msg $chan ( $+ $nick $+ ) $read(crit-table.txt, %crit.roll) }
unset %crit.roll
}

Where should I be moving crit-table.txt to so he'll actually see it?
Posted By: kap Re: $read command not finding file - 19/08/19 07:07 PM
Hi

If you move the file crit-table.txt to the same directory the script file is in and change $read(crit-table.txt, %crit.roll) to $read($scriptdircrit-table.txt, %crit.roll) does it then work?

I could be wrong but as it is, it's probably looking for crit-table.txt in $mircdir.

hth
Posted By: Cygnata Re: $read command not finding file - 19/08/19 07:47 PM
Works perfectly, thanks!
Posted By: Wims Re: $read command not finding file - 19/08/19 08:53 PM
Quote
I could be wrong but as it is, it's probably looking for crit-table.txt in $mircdir.
That's entirely correct.
Posted By: maroon Re: $read command not finding file - 19/08/19 09:13 PM
Just a reminder that $read() has default behaviors that may not be intuitive, requiring it be a good idea for most users to use the nt switches

$read($scriptdircrit-table.txt, %crit.roll)
becomes
$read($scriptdircrit-table.txt,nt, %crit.roll)

Without the 'n' switch, it tries to evaluate identifiers found in the text line, and in some cases you can get some nasty surprises from this
Without the 't' switch, it looks at line#1 of the text file, and if it's a positive number, it uses that as the number of lines in the text file, even if line#1 has a much smaller number. The above syntax for $read shows a random line from the file, but if line#1 contains 10, then you get a random line from the next 10 lines, regardless how many lines there really are.
© mIRC Discussion Forums