Skip to content
mIRC tutorials

Hard Coding.

A TG007 community discussion started by Warrior124.

Discussion 5 posts
Page 1 of 1
Open
Topic #6630 · 5 published posts · 4,296 views

Well, the main reason why people should never hard code their work is because not everyone has the same dlls, and such in the same places that are required in hard coding. This can lead to people not wanting anything else that you work so hard on, and all that work will be for nothing. So, here are some simple things you can do to achieve the same results without having to hard code.

 

Here is one of the simplest codes you can use to achieve the same results, but works better than hard coding...

 

alias findfile2 {
 if (!%findfile2. [ $+ [ $1- ] ]) || (!$exists(%findfile2. [ $+ [ $1- ] ])) set %findfile2. [ $+ [ $1- ] ] $shortfn($findfile($mircdir,$1-,1))
 return %findfile2. [ $+ [ $1- ] ]
}

 

Now you have a code that works just as well as hard coding, but can find the needed file for your work without having to manually look for it. Once the variable is stored it will work just like hard coding.

 

Here is an example on how to use it...

 

alias mdx return $findfile2(mdx.dll)
alias dialogmdx return $findfile2(dialog.mdx)
on *:dialog:mp3:init:
 .dll $mdx SetMircVersion $version
 .dll $mdx MarkDialog $dname
 .dll $mdx SetControlMDX 10 Positioner size maxbox minbox > $dialogmdx
}

 

This is just a sample code, but it gives you an idea on how to use it. Remember that hard coding works, but only if the right files are in the right place. This code works better. So, I'd better never see another hard coded script again. Just kidding, lol, but please, PLEASE use this code instead. Beleive me when I say you'd do the world a huge favor, lol. :pizza:

Edited May 14, 2006 3:06 AM by Warrior124

Hey there,

 

I know this topic was posted years ago, but only recently discovered the idea of the findfile2 function thanks to warrior!

 

However just thought I'd help out and fix a little bug with the above code...

 

This was the previous Code:

 

alias findfile2 {
if (!%findfile2. [ $+ [ $1- ] ]) || (!$exists(%findfile2. [ $+ [ $1- ] ])) set %findfile2. [ $+ [ $1- ] ] $shortfn($findfile($mircdir,$1-,1))
return %findfile2. [ $+ [ $1- ] ]
}

 

This works fine, but if mIRC cannot find the file, it will still create a blank global variable... For example:

If you use $findfile2(mdx.dll) and it cannot find the file, it will still create a global variable called %findfile2.mdx.dll

However this variable will be blank!

 

A possible fix is provided below:

alias findfile2 {
  if (%findfile2. [ $+ [ $1- ] ]) && ($exists(%findfile2. [ $+ [ $1- ] ])) return %findfile2. [ $+ [ $1- ] ]
  else {
    var %file = $findfile($mircdir,$1-,1)
    if (%file) {
      set %findfile2.[ $+ [ $1- ] ] $shortfn(%file)
      return %findfile2. [ $+ [ $1- ] ]
    }
  }
}

 

Hope this helps :)

 

Kind Regards,

Daniel

Yes, that was intentional as if someone wanted to write to a file, and the file didn't exist, it would create the file when writing to it. That's an old code, however. I'm currently working on a better method. :)

Edited Jan 18, 2010 2:05 PM by Warrior124

Ah fair enough,

My Bad there haha! I was just using this example and saw the issue which i thought was an issue! haha Sorry bout that,

 

I'm interested though in a better method?? Would it involve Hash Tables?

 

Kind Regards,

Daniel

Here is one that works much better. This will attempt to locate the specified file in the directory where you are running mirc, and its subdirectories. If it doesn't find the file there it will attempt to locate the file where your mirc.ini file is located, and its subdirectories. If it still doesn't find the file it will create a variable for the file which will be good if creating a new file. Another thing about this new code is you can find/make a file with spaces in the directory, and/or filename. :)

 

alias ff {
  var %getff $1-
  if (!%ff. [ $+ [ " $+ %getff $+ " ] ]) || (!$exists(%ff. [ $+ [ " $+ %getff $+ " ] ])) {
    if ($shortfn($findfile($nofile($mircexe),%getff,1))) set %ff. [ $+ [ " $+ %getff $+ " ] ] $ifmatch
    elseif ($shortfn($findfile($mircdir,%getff,1))) set %ff. [ $+ [ " $+ %getff $+ " ] ] $ifmatch
    else set %ff. [ $+ [ " $+ %getff $+ " ] ] " $+ $nofile($mircexe) $+ %getff $+ "
  }
  return %ff. [ $+ [ " $+ %getff $+ " ] ]
}