Jump to content

.ini Question


Silo

Recommended Posts

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 :)

 

Link to comment
Share on other sites

  • Replies 25
  • Created
  • Last Reply

Top Posters In This Topic

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 by Travis
Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

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!

 

 

 

 

 

 

 

 

Link to comment
Share on other sites

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 by Silo
Link to comment
Share on other sites

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 by Travis
Link to comment
Share on other sites

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 by Silo
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...