mIRC Home    About    Download    Register    News    Help

Print Thread
Page 1 of 2 1 2
Joined: Aug 2004
Posts: 7,252
R
RusselB Offline OP
Hoopy frood
OP Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
While this code works properly for me, the person I wrote it for states that it's not writing to the ini file.
I've run out of ideas as to why it might not be. I don't know if this is something that can be handled via the script or not, but in case it can, I have included the script here
Code:
alias askq { 
  if ($1) { 
    var %a = $($+(%,questioncounter,$1),2) 
    if $read("c:\mircstats\stats questions.txt",%a) { 
      msg $1 $ifmatch 
      timerask $+ $1 0 30 askq $1 
    } 
    else {
      .msg $1 Thanks for taking part
      dontask $1
    } 
  } 
} 
alias dontask { 
  if ($1) { 
    $+(.timer,ask,$1) off 
    unset  $+(%,questioncounter,$1) 
    unset $+(%,chan,$1)
  } 
  else { 
    .timerask* off 
    unset  %questioncounter* 
  } 
} 
on *:TEXT:*:*: { 
  if (!stop* iswm $1) { dontask $nick } 
  elseif ($target ischan) { 
    if (!addnick* iswm $1) { 
      .msg $nick Please answer the questions in this pm window 
      .msg $nick If you don't have an answer or don't want to answer a question, just enter a dummy response..NOTE: Hitting Enter/Return alone will not work. 
      .msg $nick I regret that this is necessary, however, I was unable to allow for a null (empty) response. 
      set $+(%,chan,$nick) $chan 
      set $+(%,questioncounter,$nick)  1 
      askq $nick 
    } 
  } 
  else {
    if $($+(%,chan,$nick),2) {
      .writeini c:\mircstats\Stats.ini $nick $($+(%,questioncounter,$nick),2) $1-
      inc $+(%,questioncounter,$nick)
      askq $nick
    } 
  }
} 
on *:EXIT: { dontask } 
on *:PART:#: { 
  if $chan == $($+(%,chan,$nick),2) && $timer(ask $+ $nick) { dontask $nick } 
} 
on *:QUIT: { 
  if ($timer(ask $+ $nick)) { dontask $nick } 
} 
on *:nick:{ 
  if ($timer(ask $+ $nick)) { dontask $nick | askq $newnick } 
} 


Joined: Dec 2002
Posts: 2,031
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Dec 2002
Posts: 2,031
Are they using Windows Vista ?

Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
It's unlikely, but if the file has reached a certain size you will need to use the -n switch to write to the file. Worth a shot.

Joined: Aug 2004
Posts: 7,252
R
RusselB Offline OP
Hoopy frood
OP Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
@Rock: Already thought of that, and the answer is no.
@hixxy: This is occurring even if the file doesn't already exist, but only for the original requester.

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Are you positive the user has this folder:

c:\mircstats\

I've run into people who *think* they have it, but it isn't spelled correctly.


Invision Support
#Invision on irc.irchighway.net
Joined: Jan 2007
Posts: 1,156
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Jan 2007
Posts: 1,156
When I write scripts for other people to use and they involve files in folders, I put the folder in my mirc folder. Also, my personal taste, I don't put mirc in its own folder. It is in a folder and in that folder would be other folders. Scripts folder holds my misc. scripts. Sounds holds my sound files. This is where I would personally put your stats folder.

Using mirc as I have described, now I just say:

\mircstats\file.ini

You can even go as far as creating the directory with /mkdir.

It doesn't matter what directory they have this in or where in the directory. I've used $mircdir but I tend to get errors if there are any spaces in the file path, no I've switched back to doing it as I've explained. I hope I've made sense.

Joined: Apr 2004
Posts: 759
M
Hoopy frood
Offline
Hoopy frood
M
Joined: Apr 2004
Posts: 759
If you distribute scripts that depend on files use $scriptdir then it doesnt matter where the users loads the zip to.

I have no clue why it wouldn't write though if its not any of the above. Maybe send him a debug alias to see if that folder is a dir the file is a file and wheter all the vars are set ?


$maybe
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
My scripts end up in their own folders inside mIRC's, but I rarely ever use $mircdir. As mentioned, $scriptdir is more helpful. If the user wants the stats in its own folder as shown, then there isn't any reason why that cannot be done.

As far as spaces in filenames... if you use an identifier, spaces don't matter. Otherwise, they do and you'll want to use $qt() or else $+(",whatever,") to deal with it.


Invision Support
#Invision on irc.irchighway.net
Joined: Jan 2007
Posts: 1,156
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Jan 2007
Posts: 1,156
Well I didn't like $scriptdir. I'll tell you why.

It seemed to me that the $scriptdir identifier pointed to whatever folder my script editor was set to. My main code is in its own folder with its dependent files. This folder is located in the main script folder that holds mirc.exe, scripts folder, sounds folder, etc.

Ok so I open the script editor for the first time and it opens to the main directory that mirc.exe is in. Now I want to load my main files which are in their own directory. I personally use ctrl + L to load files, way faster than typing. SO I browse to them and load them. Now when I open my script editor and go to load it automatically points to this subdirectory that has my main script files in it. Now, from my experience, $scriptdir points to this directory and not my main folder that has mirc.exe in it. Make sense? This has been my experience and why I do not use $scriptdir.

Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
Quote:
Now, from my experience, $scriptdir points to this directory and not my main folder that has mirc.exe in it.

- Yes, $scriptdir isn't meant to point the mIRC installation directory, it's meant to point to the directory containing the currently executing script.

$mircdir points to the location of your mIRC settings (not necessarily the mirc.exe!). IMO $mircdir (or more specifically a subdirectory of it) is ideally the one that scripters should use for saving settings.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
To be compliant with windows it should ideally save settings in a mIRC\<script name subfolder>\ folder in the application data folder.

Personally I always save settings to the script's directory, because I find nothing more annoying than extracting a script to a folder on my desktop but having its config appear in my mIRC directory. The mIRC directory is for mIRC, not for scripts to save their settings.

Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
Quote:
To be compliant with windows it should ideally save settings in a mIRC\<script name subfolder>\ folder in the application data folder.
Exactly, and that's just where my $mircdir points to. And as of the next version of mIRC it'll be the place everyone else's will point to aswell unless they explicitly specify otherwise.

By contrast it could entirely be possible that an administrator on a system would install mIRC scripts to a subdirectory of the mIRC installation folder which may or may not be writeable by any other user, making $scriptdir a risky proposition.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
The same could be said about $mircdir though, unless the ability to use a mirc.ini from anywhere you like is removed and you're forced to have it in the appdata folder.

If an administrator installs mIRC to c:\program files\mIRC\, then a non-admin would probably not be able to use files in that directory.

I think the only way to ensure your settings are stored in a writeable location is to store them in appdata no matter where mIRC itself is, in which case an $appdata identifier would be useful.

Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
Yeah but if mirc.ini is in a non-writeable location then the user's already got problems, so it kind of stands to reason that it wouldn't be a big deal if the script fails at that point also.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
That's a good point actually.

I still think an $appdata identifier would be useful though. Or even better, a built-in way to save/load script settings. savesetting topic item data $getsetting(topic,item) (would automatically read a setting for $script - you could also optionally supply a script name you want to read settings for as your first parameter). This could all be done in memory and then saved when mIRC exits in the appdata folder.

Joined: Apr 2004
Posts: 759
M
Hoopy frood
Offline
Hoopy frood
M
Joined: Apr 2004
Posts: 759
$nofile($mircini) ? :P

I still prefer $scriptdir dont like scripts putting stuff where i don't expect them to pop up.


$maybe
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
I meant that $appdata would return the application data folder for the current user (usually C:\Documents And Settings\<username>\Application Data)

Joined: Aug 2004
Posts: 7,252
R
RusselB Offline OP
Hoopy frood
OP Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
Quote:
Are you positive the user has this folder:

c:\mircstats\


Yes, I'm positive, since the text file with the questions is in that directory, and it reads the questions correctly. If the name was spelled incorrectly, then the bot wouldn't be asking the questions.

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Well, I guess I'd echo this:

$($+(%,chan,$nick),2)

right before that IF line. See what it's echoing. That is most likely where it's failing.


Invision Support
#Invision on irc.irchighway.net
Joined: Jan 2007
Posts: 1,156
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Jan 2007
Posts: 1,156
Yeah, also

echo -a $file(c:\mircstats\Stats.ini) $nick $($+(%,questioncounter,$nick),2) $1-


About the $mircdir/$scriptdir debate.

I choose to not use $scriptdir because it is not stable. It can change. I do not use $mircdir because it doesn't support a file path with spaces. I receive errors like

"C:/Documents" no file (example, not exact error msg)

The script I am developing I have named SoulFly. So the main folder is named SoulFly_v1. In this folder is my mirc.exe file with it's neccesary .ini support files. Logs & Sounds folder is also in my SoulFly_v1 directory. My personal scripts neccesary files are in their own folder called SoulFly. SoulFly.mrc and SoulFly.ini are two files for example.

I was having issues with mdx and other dll's using $mircdir when people wanted to run the script from their desktop "C:Documents and Settings\USER\Desktop\" or from My Documents or Program Files. Now I point to the dll's like this:

Quote:
SoulFly\dll\mdx.dll


Now users may put my script wherever they like and it works.

This is my personal experience and solution. Sorry to go off topic, I just wanted to be clear about errors I have found using $mircdir and $scriptdir and why I do not suggest using them.

Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
Not stable? It returns the directory the executing script is in - that's all. It doesn't change unless you move the script to a new directory and then reload it.

As for $mircdir not supporting paths with spaces, you can see that it clearly does return paths with spaces by installing mIRC to a directory with spaces in it and then typing //echo -a $mircdir

The problem you're getting is when you try to pass a file/directory to certain commands without enclosing them in double quotes.

If a command has just one parameter (a file), or a command has only one file paramater and that parameter is last, then it's perfectly fine to pass a path without spaces. For example:

These are all fine:
/run c:\documents and settings
/splay c:\documents and settings\3.wav
/splay -p c:\documents and settings\x.mp3

But this is not:
/filter -ff c:\documents and settings\x.txt c:\documents and settings\y.txt

The reason for this is that mIRC has no idea where the first file ends. This is why you have to enclose it in quotes:

/filter -ff "c:\documents and settings\x.txt" "c:\documents and settings\y.txt"

You can do this by doing:

$+(",<file>,")
" $+ <file> $+ "
or $qt(<file>) (only added recently)

Identifiers don't suffer from the same problem because all parameters are separated by commas, so mIRC has no trouble working out filenames.

If this seems unclear, feel free to ask and I can try to clarify some points.

Joined: Jan 2007
Posts: 259
K
Fjord artisan
Offline
Fjord artisan
K
Joined: Jan 2007
Posts: 259
If you get errors stating that C:/... .../, then you can use $qt() to put it in quotation marks, which will resolve the error.
Edit: Hixxy beat me to it crazy

Last edited by Kardafol; 13/03/07 08:58 PM.

Those who can, cannot. Those who cannot, can.
Joined: Jan 2007
Posts: 1,156
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Jan 2007
Posts: 1,156
Yeah I used quotes and it does that, but for some mdx things it doesnt. It's weird. I chose to call the file as I mentioned and haven't seen any errors.

As for $scriptdir, I've seen it change from going to my main directory "SoulFly_v1" that mirc.exe is in, to my SoulFly folder. I just wanted it to return the same root directory everytime without hassles.

Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
Originally Posted By: DJ_Sol
As for $scriptdir, I've seen it change from going to my main directory "SoulFly_v1" that mirc.exe is in, to my SoulFly folder. I just wanted it to return the same root directory everytime without hassles.


It does do that as long as you don't move and reload your script.

Joined: Jan 2007
Posts: 1,156
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Jan 2007
Posts: 1,156
If I use an identifier to point to a specific place I want to make sure it ALWAYS points to where I want it. I mean, Im giving anyone this code to use. People do straaaaange things with it. Running from the desktop is just one of the mildest. It's my opinion, my preference, since it will not provide me with the exact same path EVERY SINGLE TIME I go to it I cannot use it. Make sense?

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Remember that spaces require an identifier (or quotes) to work. If you try something such as:

/write $mircdir\script\script.txt hello

And $mircdir == c:\Program Files\mIRC, then you will have problems.

However, if you use it in an identifier, such as:

//echo -a $read($mircdir\script\script.txt,1)

And $mircdir is still == c:\Program Files\mIRC, then it will work properly. For the first example, you'd need $qt() or similar methods of adding quotes. As long as you follow that rule, it will never give you problems with spaces.

I have always used $scriptdir and my scripts can be moved anywhere on anyone's computer and it has never been unstable. Remember that the rule for spaces is the same as with $mircdir.

If you still have issues with it not working properly, I'd suggest posting example code here and see if someone finds something that was done incorrectly, because it should work all of the time if you're following the rules mentioned above.


Invision Support
#Invision on irc.irchighway.net
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
$mircdir is not static either. Someone moves mIRC to a different location and it changes..

If you use completely static directories by hardcoding them into your script (ie. you use /write "c:\program files\mirc\x.txt" a) then that's just the worst way possible. If I install mIRC to c:\mirc\, then I'm going to want settings stored somewhere around there. Not in an entirely different folder.

Joined: Jan 2007
Posts: 1,156
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Jan 2007
Posts: 1,156
Thanks for all your ideas and Im sorry this got off topic. As I said, to point to a file in a subdirectory, I have been using:

/SubDir/filename.ext

Haven't had any issues so far. *crosses fingers*

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
If it's just for yourself, that's an okay way to do it. However, if you distribute it and someone installs your script to something like c:\mirc\scriptname\ and it points to something like data\data.txt, mIRC will assume it's in c:\mirc\data\ and it may actually be in c:\mirc\scriptname\data\ instead. That's why $scriptdir is safer.


Invision Support
#Invision on irc.irchighway.net
Joined: Aug 2004
Posts: 7,252
R
RusselB Offline OP
Hoopy frood
OP Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
In regards to the hard coded locations of those files, the directory was specified by the original requester, and, as of this posting, nothing seems to have helped. For some reason the ini file doesn't want to allow to be created on his system.

Joined: Jan 2007
Posts: 1,156
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Jan 2007
Posts: 1,156
did you echo those two things Russel and verify that they are correct?

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Originally Posted By: RusselB
In regards to the hard coded locations of those files, the directory was specified by the original requester,


That wasn't in response to you. laugh


Invision Support
#Invision on irc.irchighway.net
Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
Does the user have write-access to that location? Or is the file read-only? /writeini doesn't appear to produce errors when it fails to write to a file for any reason. It would seem to be a bug.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Joined: Aug 2004
Posts: 7,252
R
RusselB Offline OP
Hoopy frood
OP Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
All variables and identifiers are returning correct values per the situation. I had him try it with no ini file, and the first parameter that was echoed $file(c:\mircstats\Stats.ini) returned $false.

I then had him manually create the ini file, and at that point it reeturned $true

However, the only way to get the $true was to manually create the ini file, and then the file wasn't updated with the information supplied.

Aside from that, the other variables and identifiers have all returned expected values.

Joined: Aug 2004
Posts: 7,252
R
RusselB Offline OP
Hoopy frood
OP Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
Since the op can manually create the ini file in that location, and the text file with the questions is also in the same directory, I can't see how he could not have write-access to the directory, and the ini file shouldn't be read-only, especially when it's being created (or supposed to be created via the script.)

Edit: The op has informed me that the directory has a read-only attribute, but he's been unable to remove that attribute. This makes no sense to me, since he's able to manually create the ini file.

Page 1 of 2 1 2

Link Copied to Clipboard