Hash Script Options from a config file

By CakerX on Dec 23, 2006

READ THE DIRRECTIONS below, write in your scripts name where I tell you to below, copy and paste this into your script, adjust as needed. I kinda ripped this out of my latest project, so if I didn't wipe all my script's specific material, sorry.

Essentially this is hash tables for dummies. This allows you have user set options for your script, that are read from a config file. Maksure you change the text between the <>s to whatever it tells you.

  1. Your script MUST be an INI, no .mrcs.
  2. create the file <yourscript's name>.conf
  3. put the text [options] at the top and
    thisismyoption=myoptions value, and use ";"'s for comments explaining
    what they are for the user to edit.
  4. make sure all the are the same thing, with NO SPACES ALLOWED
  5. Again make sure you edit this properly, look at it in notepad before pasting.
  6. options added
  7. use this in ANY script you want. This gave me a few headaches figuring it out, so hopefully I saved you said headache.

edit: I don't use global variables simply because mIRC only can handle one variable file at a time.

If this variable file is unloaded, or someone's script that loads its own variable file is loaded, my code would cease to function.

edit2: besides hash tables rock my socks off. just cut paste, and use the fucking identifiers.

edit: forgot, the custom identifiers $yourscrip_options(option)
and $yourscript_version(name|version|original file) are used to access your data.

;Open up your script in notepad when mIRC is not running, and just paste and edit
[version]
version=<your script's version>
name=<your script's name>

[extconf]
extconf=<your script's name>.conf

;---Open up mIRC, and paste everything below this in with the script editor in MIRC.-----

alias <yourscriptname>_version {
  if ( $1 == $null ) || ( $1 == version ) { return $hget(crypt_version,version) }
  elseif ( $1 == name ) { return $hget(crypt_version,name) }
  elseif ( $1 == originalfile ) { return $hget(crypt_version,originalfile) }
  else { return ERR }
}
alias <yourscriptname>_options.rehash {
  var %int
  var %word rehashing
  if ( $1 == --int ) { set %int $true | set %word initializing | goto start }
  :dump
  hfree <yourscriptname>_version
  hfree <yourscriptname>_options
  ; this is for un-hashing your options for unloading
  if ( $1 == --free ) { echo -sqe freed | halt }
  :start
  .remote on

  ;hashing conf
  :hash
  hmake <yourscriptname>_version 3
  hadd <yourscriptname>_version version $readini( $script ,n,version,version)
  hadd <yourscriptname>_version name $readini( $script ,n,version,name)
  hadd <yourscriptname>_version originalfile $readini( $script ,n,version,originalfile)

  ; Uncomment this if you want your script name echoed in local on load/rehash
  ; echo -qs *** <yourscriptname> v $+ $hget(<yourscript>_version,version) %word

  ;making options table
  hmake crypt_options 5
  var %extconf $readini( $script ,n,extconf,extconf)
  hadd <yourscriptname>_options extconf %extconf 

  ;add a new line for everything option you have, cut and paste, the replace the <option#>
  : with what options you have in your conf file.
  hadd <yourscriptname>_options <option1> $readini( %extconf ,n,options,<option1>)
  hadd <yourscriptname>_options <option2> $readini( %extconf ,n,options,<option2>)  
  hadd <yourscriptname>_options <option3> $readini( %extconf ,n,options,<option2>) 
  ; echo -qs -
  halt
}

alias <yourscriptname>_options {
  ; this is an alias for an identifier $<yourscriptname>_options(<your_option>), so you can
  ; easily use them in your script
  ; just type the options you have made in the conf file in below, seperated by a space.
  ; all items in text will return their values,  binary options return $true for 1 and $false
  ; for 0. If you don't know, put it in text options
  var %textoptions <options that return text goes here>
  var %binaryoptions <options that are either a on/off true/false 0/1 aka binary go here>
  if ( $1 isin %binaryoptions ) {
    if ( $hget(<yourscriptname>_options, $1 ) == 0 ) { return $false }
    elseif ( $hget(<yourscriptname>_options, $1 ) == 1 ) { return $true }
    else { return ERR }
  }
  elseif ( $1 isin %textoptions ) { return $hget(<yourscriptname>_options, $1 ) }
  else { return 1 }
}

;----most important part---;
;if you already have on load command, just copy and past the contents
;if you don't just copy it all.

on 1:load:{
; the --int doesn't try and free the hash tables first which causes a crash
<yourscriptname>_options.rehash --int
}

Comments

Sign in to comment.
Disturbed   -  Dec 26, 2006

;o

 Respond  
xDaeMoN   -  Dec 25, 2006

Then create a custom identifier so it would be easier for the user to edit the configurations needed ;)

Sample:

alias _Scriptname return Script_name_here
alias _Scriptver return Script_version_here

Usage: $_Scriptname & $_Scriptver

 Respond  
Marshtomp   -  Dec 24, 2006

RoninWarrior: Read the author notes.
It looks nice, but i have no experince in hash files.

 Respond  
RoninWarrior   -  Dec 23, 2006

why not set it to were you can set your scriptname with % it will take an hour to change all of that .

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.