Skip to content
General IRCd

.ini Question

A TG007 community discussion started by Silo.

Discussion 26 posts
Page 1 of 2
Open
Topic #11221 · 26 published posts · 4,914 views

Hey there, as I've stated before, I'm relatively new to scripting. I always only worked with what I knew and never went out of comfort zone which resulted in very basic scripts. Every now and then I attempt to improve my knowledge of .ini files which results in a bit of a break through every now & then.

 

So, I'm attempting to have a dialog with multiple check boxes for prots. I don't want all the same prots active for different channels I'm on, so I want to write to an ini file what channel has what check boxes ticked. I've sort of got the basics down but the info is too vague (I think) to call on when the init fires. This is my demo model...

dialog check.test {
  title "New Project"
  size -1 -1 90 84
  option dbu
  check "Hop", 1, 16 16 26 10
  check "Flood", 2, 16 28 26 10
  check "CTCP", 3, 16 40 26 10
  button "Close", 9, 44 67 37 12, ok cancel
  button "Apply", 10, 6 67 37 12
}
alias a {
  dialog -m check.test check.test
}

On *:Dialog:check.test:sclick:10:{
  writeini -n testers.ini Prots $+ $active enable $did(1).state  $did(2).state  $did(3).state

}
On *:Dialog:check.test:init:*:{
  did $iif($readini(testers.ini,n,Prots $+ $active,enable) = 1,-c,-u)  $dname 1-3

}

I need a better way of sending the ticked info to the .ini file and a way of calling the info on each channel I'm on.

ini file loks like this.

[Prots#scripters]
enable=1 1 1

[Prots#err0rtest]
enable=0 1 0

but of course, this doesn't say which 1 or 0 is which checkbox etc, and my $iif on the init wouldn't know how to handle the data properly.

 

If this question makes any sense to you, do you think you could offer some advice? I'm not asking for anyone to write the code for me, perhaps just explain some syntax that would help me find my way.

 

Many thanks in advance :)

 

What I do is name a Protection, then all channels that it is on in.

 

 

protect.ini

 

[protect]

textflood=chan1,chan2,chan3,chan4

 

 

Then I can say:

 

if ($chan !isin $readini(protect.ini,protect,textflood)) { return }

 

 

 

You could easily list all channels text flood is on for:

 

/didtok $dname <id> 44 $readini(protect.ini,protect,textflood)

 

 

 

 

Check out $addtok & $remtok ....

 

Add Channel:

 

writeini protect.ini protect textflood $addtok($readini(protect.ini,protect,textflood),$chan,44)

 

 

 

Remove Channel:

 

writeini protect.ini protect textflood $remtok($readini(protect.ini,protect,textflood),$chan,44)

Edited Sep 23, 2008 3:11 AM by Travis

Thanks Travis I appreciate your help on the topic. You've furnished my request of syntax to help get me started most admireably, however, I should of pointed out that I probably need the idiots versios of that. mIRC for dummies, maybe :P I'll hit the help file now and see what I can glean from it. I sort of get what you mean about the textflood chan1,chan2,chan3 etc, but if you use check boxes how will the dialog know where to assign the " tick" and where not to?

 

Again, thank you for your help & support :)

You are storing data saying whether a protection is on in a certain room. So the dialog can check the ini file and see if the protection is on for the room. If it is: /did -cu $dname <id>

Yes ok, I think I get that much and don't seem to have any trouble determining that. Forgive me for being slow in case I miss the gist of what you're trying to tell me :) On *:ACTIVE if I'm op it will automatically display my #channel name in an editable combo box. Beneath it will be about 15 different prots which will be enabled/disable via check boxes. So... if on #Channel1 it will automatically -c,-u any of the prots I have activated for that particular channel...This is what you're also saying, yes? I'm reading the $addtok sec tion in the /help file now & I think I see a similarity with the snippet you posted, though I might go about it differently :)

 

If the first section of the ini file shows Prots#channel1 and I've got the checkboxes state == 1 how could I determine which are active and which are not? If I'm frustraing you for being a slow learner, I understand & won't take any ffense if you bypass my threads :)

 

That being said, your hellp does mean a great deal to me :)

Hey no problem Silo. I love helping when the person is into it.

 

 

Ok you are very close. Let me try and explain it better for you.

 

 

I have a textflood protection. I store the switch settings (off/on) in an ini file. Let's name it Protect.ini.

 

Protect.ini

 

[Protect]

textflood=

 

This is how I will store it. If I want Textflood on in #ChannelA, I add the channel name to the ini file under textflood.

 

/writeini protect.ini protect textflood #ChannelA

 

Now it will look like...

 

Protect.ini

 

[Protect]

textflood=#ChannelA

 

and $readini(protect.ini,Protect,textflood) == #ChannelA

 

 

 

Ok, now I have your dialog up and #ChannelA becomes my active window. You use your "On Active" event. What you are wanting to do is check to see if a protect is on in the room, if it is you check the appropriate checkbox.

 

So, "On Active" I check if ($active isin $readini(protect.ini,Protect,textflood)). If it is I check the "textflood" checkbox.

 

 

on *:active:#:{
if (!$dialog(dialogname)) { return }

if ($active isin $readini(protect.ini,protect,textflood)) { did -c $dname <id> }
if ($active isin $readini(protect.ini,protect,joinflood)) { did 0c $dname <id> }

}

 

And that's how you check if the active channel has textflood turned on. In your ini file under [Protect] you will add all the different protections. When you turn one on you will add the Channel name to the appropriate protection. When you turn it off you will remove the channel name from the appropriate protection.

 

If you have more than one channel you will want to seperate the channel names with a token. A comma is safe since IRC standards says a comma won't be used in a Channel name.

 

Read up about tokens and token identifiers. Learning tokens really opened up scripting for me big time!

 

You can use $addtok to add a channel name seperated by the ',' (comma - $chr(44)) token. Use $remtok to remove the channel name.

 

With these, first you tell it what you are adding the new data to, next is the new data you are adding, next is the token seperating the data.

 

/writeini protect.ini protect textflood $addtok($readini(protect.ini,protect,textflood),#ChannelA,44)

 

44 is the $chr number for comma. ($chr(44)) This will add #ChannelA to the list of channel names and seperate it with a comma. $remtok will do the opposite.

 

Try this stuff out and come back with any questions!! Good Luck!

 

 

 

 

 

 

 

 

Ok then Travis. I've been playing around with these on & off for the last few days, and I think I'm grasping it better :) I think what I was trying to accomplish was a wee bit advanced for someone who had almost zero .ini experience. So, and with the help of a fellow chatter on Koach, I nailed the basics and have been experimenting using the ini file to store info that I previously used %vars for.

 

Vars, for the most part, can often be unpredictable & "go missing" from time to time, which can be a real pain... Anyway, I digress. I'm going to keep on playing with the basics until I feel confident & it's second hand to me, then I shall try my larger project.

 

Thanks again :) No doubt you'll be hearing from me soon enough :P

 

*EDIT* Funnily enough sometimes the boxes don't remain checked on init even though all info points it doing so. Is .ini bugy?

Edited Sep 26, 2008 8:09 AM by Silo

No, and neither are variables. Variables are neither unpredictable or go missing. Maybe if you use someone else's code and it unsets the variable you may not understand. But when yer writing your own script and decide to save something to a variable, the var will be there until you unset it.

Show the init event.

Edited Sep 26, 2008 12:10 PM by Travis

I should of been morwe clear when saying "gone missing". On some ocassions, I've had the unfortunate event where it seems the /unsetall function fires mysteriously and I lose all my %vars. That hasn't happened in some time now. No, what I was getting at was, I never liked having so many functions being set with %vars then using if ($var(%name)) did -c $dname 1 etc on init to determine if the function should be "on or off".

 

The problem I'm describing could be due to a short cut alias I wrote to shorten the event when calling the path to the ini name. I should stick to the basics till I sort it out lol.

 

Thanks, Travis. If I get no joy I'll post the init code :)

 

*EDIT* I could kick myself. I noticed if the script was diconnected, no check boxes were ticked. Connect, and voila, everything was fine. Pretty simple to see what was going on lol Anyway, I had some long lost code in my overly large init sectiopn for this particular dialog that had "if (!$server) halt" a few lines above my $readini code. Changed halt to return, and now (so far everything seems cruisy) :)

 

Idiot of the week award goes to yours truly

Edited Sep 26, 2008 1:49 PM by Silo

That's not a sign of an idiot, lol. There have been many codes I came up with that I looked at later and asked i it was me who made them codes. Sometimes I have to look at what I did a long time ago to remember certain things, lol. That's all part of scripting. :)

Heh, Thanks for the kind words, Warrior :P I'm pretty excited about finally getting some .ini stuff to work. This is going to revolutionize the way I write scripts now :)

Hey good job! I ALWAYS use return. The only time I use halt is in an event to stop mirc from echoing the info to the screen.

 

Halt stops all executing scripts. Return stops the currently executing script.

 

The time I had issues with variables I figured out what the problem is and it's good for you to know actually.

 

When mIRC starts and loads, it loads ini files. These files, like vars.ini, are stored in RAM. You can change the actual file and you wont see a difference in mIRC until it re-initializes. Because of this you cannot manually edit .ini files unless you use the /flushini command. BY manually edit I mean opening the file in a text editor and editing it. Using /writeini is fine.

 

 

/flushini <filename>

 

Flushes the specified INI file to the hard disk. INI files are cached in memory, so you may want to do this to make sure that your INI is updated properly.

 

And one last thing. What revolutionized the way I write scripts was learning hash tables and tokens. LEarning hash tables taught me about tokens. These two tools and concepts will do wonders. Especially tokens. And they both are actually very easy. Hash tables use less code than ini files. Supposedly faster too. In fact I learned hash tables before ever even working with ini files. I use ini now for storing basic settings.

 

 

Anyways, well done! Keep it up!

 

Wow, thanks, Travis. That is very informative, and I'm embarrassed to say - I've been manually deleting messy entries in my .ini file (the stuff that didn't work)! I guess I should flush the file and start again?

 

Another question: I've made an alias to shorten the path of the file ($_data) instead of (Engine/Text/Channel_Data.ini) and it works very well. I thought "why can't I take this a step further and make a similar alias return <file name> <section> <item> so I thought I could use

 

alias _rd {
  return $readini(testers.ini,$1,$2)
}

On *:Dialog:check.test:sclick:10:{
  writeini -n testers.ini Prots hop $did(1).state 
  writeini -n testers.ini Prots flood $did($dname,2).state
  writeini -n testers.ini Prots ctcp $did($dname,3).state
}
On *:Dialog:check.test:init:*:{
  if ($_rd == 1) did -c $dname  1
  if ($readini(testers.ini,prots,flood) == 1) did -c $dname  2
  if ($readini(testers.ini,prots,ctcp) == 1) did -c $dname  3
  if ($readini(testers.ini,prots,enable) == 1) did -c $dname  4
}

 

So this bit is failing BIG time

  if ($_rd == 1) did -c $dname  1

 

Is my idea of using $1 & $2 off or is something simpler, I'm missing?

 

Both you & Warrior have a great help me to, so I'd also like to publicly thank the both of you for your help & support :)

if ($_rd(prots,flood) == 1) did -c $dname 1

etc..

 

 

it think that's what you want :huh:

HI Zan, yeah, it works no problemo the way you suggested. I was trying to not have to write the items etc after the alias thus why I thougt $1 & $2 would return that info :)

You need to provide the alias with $1 and $2.

 

/testing 1.. 2.. 3.. 4..

alias testing {
  echo -a 1= $1 2= $2 3= $3 4= $4
  echo -a > $1-2
}

 

Result:

 

1= 1.. 2= 2.. 3= 3.. 4= 4..

> 1.. 2..

 

alias _rd {

return $readini(testers.ini,$1,$2)

}

 

You need to tell the _rd alias what $1 and $2 are.

 

If used as a command, the info is seperated by spaces.

So if you use: /testing One,Two Three,Four

 

$1 == One,Two and $2 == Three,Four

 

(incidentally the space that seperates them is considered a token. $chr(32) )

 

When using the alias as an identifer, i.e.: $_rd, the data is seperated by commas. The comma is considered the token $chr(44).

 

$testing(One..Two,Three..Four) $1 == One..Two and $2 == Three..Four

 

 

So you would provide $1 and $2 with your custom identifier as Zan showed you.

 

$_rd(prots,flood) == $readini(testers.ini,prots,flood)

 

 

Ahhhhh right, I totally get you. Apologies to Zan, I missed his point entirely, and since I use parenthisis to wrap customer identifiers I should of seen what he was saying.

 

Thanks guys, that's been of great help to me.

 

PS - I'm like a kid with a new toy since grasping this. Stuff I've been putting off for weeks because I couldn't accomplish it with %vars was all done in less than twenty minutes last night using .ini. :embar:

Hey Silo, well done. It really is a pleasure working with someone who actually wants to learn and not just be given some code to copy and paste. So ... what's next!? hehe

Thanks Travis, it's only with the help of great people & tutors like yourself that inspire me & help me push my boundries :)

 

Next? Well probably quite basic for most really :P I'm trying to use MDX to make only my Nickname blod in my custom nicklist. So far they all keep coming out bold :(

Excuse the double post, I wanted to add another question to the topic and (I confess) wanted to bump it :)

 

This is a follow on to Travis's indepth lesson he shared me with (If you (Travis, that is) had the interest perhaps you could write tutes, as you have a very easy way of explaining things).

 

Ok, after being pretty happy with my results of your teaching, I thought I'd tackle the original question I was posting about in the first place. I followed a different path to what you suggested, and time may prove this a foolish step as this progresses.

 

[Protection]
#err0rtest=Revenge=1,Profanity=1
#Scripters=Revenge=1,Hop_Flood=1,Profanity=1,Mode_Lock=1

 

As you can see, I added the channel first then add the prots to it via $addtok (I'm getting the feel for it, slowly). Note the = 1 This was the result of some messy coding which I used for experimentation purposes since I thought it would be easy to show which boxes were ticked on init if Iused the

= 1 method.. Observe:

     ; if ($active !ischan) return
     ; if ($me !isop $ifmatch) { $input(You need Op status or higher to make these changes,hdo,HALT) | return }
      if ($did(119).state == 1) writeini $_prots Protection $active $addtok($readini($_prots,Protection,$active),Revenge,44) $+ $chr(61) $+ $did(119).state
      if ($did(104).state == 1) writeini $_prots Protection $active $addtok($readini($_prots,Protection,$active),Hop_Flood,44) $+ $chr(61) $+ $did(104).state
      if ($did(99).state == 1) writeini $_prots Protection $active $addtok($readini($_prots,Protection,$active),Profanity,44) $+ $chr(61) $+ $did(99).state

 

This is the alias I use to call the checked boxes on init (I'm pretty embarrasses about this, but hey, I am learning & it is only experimental at this stage :P )

alias show.prots {
  if (!$dialog(cpanel)) { return }
  if ($active isin $readini($_prots,Protection,Revenge))  did -c cpanel 119 
  if ($active isin $readini($_prots,Protection,Hop_Flood) && ($readini($_prots,Protection,Hop_Flood == 1)) did -c cpanel 104
  if ( $active isin $readini($_prots,Protection,Profanity) && ( $readini($_prots,Protectio,Profanity) == 1) ) did -c cpanel 99
}

 

I've only made two checks so far. No need to write a bunch of them until they work :)

 

Any advice for me Mr. Travis or others? :)

 

Thanks you.