mIRC Home    About    Download    Register    News    Help

Print Thread
Page 1 of 2 1 2
Anyone solve this? #248497 10/10/14 10:46 AM
Joined: Oct 2014
Posts: 48
JB_uk Offline OP
Ameglian cow
OP Offline
Ameglian cow
Joined: Oct 2014
Posts: 48
Just a problem I've encountered.

I'm trying to do it so that a points system which gives points every 5 minutes would allow me to make a different command called !watchtime. It would be good if it could take the number from the points system file and take them in a specific format using a bunch of if statements. ie if the user has watched for less than an hour it would show in minutes, if the user had watched for over an hour it would show in hours and minutes then if they're addicted and have days worth of points it would show days hours minutes. I've given it a go however I can't seem to get it working.
The problem seems to be in the initial IF statement as I've tried it with a simple message following it. Here's what I tried...
Code:
on *:text:!watchtime*:#:{ 
  if (($readini(Points.ini,$+(#,.,$nick),Points)) < 12) { msg # $nick has watched the stream for $calc($readini(Points.ini,$+(#,.,$nick),Points) * 5 ) minutes. }
  if (($readini(Points.ini,$+(#,.,$nick),Points)) > 12) && (($readini(Points.ini,$+(#,.,$nick),Points)) < 287 ) { msg # $nick has watched the stream for $floor($calc($readini(Points.ini,$+(#,.,$nick),Points)) / 12 )) hours. }
  else { msg # I'm not working. }
}


The else statement is just there so I know

Last edited by JB_uk; 10/10/14 12:24 PM.
Re: Help with readini and rounding. [Re: JB_uk] #248499 10/10/14 10:58 AM
Joined: Dec 2008
Posts: 1,511
westor Offline
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2008
Posts: 1,511
Try using the $duration identifier.

Help details: /help $duration

e.g: //echo -a $duration(300)

Re: Help with readini and rounding. [Re: westor] #248502 10/10/14 11:13 AM
Joined: Oct 2014
Posts: 48
JB_uk Offline OP
Ameglian cow
OP Offline
Ameglian cow
Joined: Oct 2014
Posts: 48
But is there a way to use the
Code:
 if (($readini(Points.ini,$+(#,.,$nick),Points) > 12) && (($readini(Points.ini,$+(#,.,$nick),Points) < 287 ) 

section as that is the problem area?

Re: Help with readini and rounding. [Re: JB_uk] #248505 10/10/14 12:28 PM
Joined: Dec 2013
Posts: 779
N
Nillen Offline
Hoopy frood
Offline
Hoopy frood
N
Joined: Dec 2013
Posts: 779
Untested, and not sure if this is what you want either.
Code:
on *:text:!watchtime:#: { 
var %points ($readini(Points.ini,$+(#,.,$nick),Points)
var %time $calc(%points * 5 * 60)
var %duration $duration(%time)
msg # $nick has watched the stream for %duration $+ .
} 


Nillens @ irc.twitch.tv
Nillen @ irc.rizon.net
Re: Help with readini and rounding. [Re: Nillen] #248506 10/10/14 12:55 PM
Joined: Oct 2014
Posts: 48
JB_uk Offline OP
Ameglian cow
OP Offline
Ameglian cow
Joined: Oct 2014
Posts: 48
At a quick look that method doesn't seem to work.
So nobody knows if the initial if statement will work? frown

Re: Help with readini and rounding. [Re: JB_uk] #248507 10/10/14 01:21 PM
Joined: Oct 2014
Posts: 48
JB_uk Offline OP
Ameglian cow
OP Offline
Ameglian cow
Joined: Oct 2014
Posts: 48
If $1 is the first word a user inputs, is there a way of doing this for a bot automatically in a similar way, so for example
Code:
on *:text:!watchtime:#: { 
  msg # FIRSTWORD has watched the stream for %duration hours .
} 

Is there any way of taking this FIRSTWORD and putting it elsewhere in the same script?

Re: Help with readini and rounding. [Re: JB_uk] #248509 10/10/14 02:15 PM
Joined: Jun 2014
Posts: 248
B
Belhifet Offline
Fjord artisan
Offline
Fjord artisan
B
Joined: Jun 2014
Posts: 248
Set FIRSTWORD as a variable?

Re: Help with readini and rounding. [Re: Belhifet] #248510 10/10/14 03:01 PM
Joined: Oct 2014
Posts: 48
JB_uk Offline OP
Ameglian cow
OP Offline
Ameglian cow
Joined: Oct 2014
Posts: 48
Been brainstorming this for the past few days and the problem area is the readini. Does anyone have an idea as to why this would be, why can't it recall the number from the ini. Is it because of the format in which it is written, which is
[#jb_uk.jb_uk]
Points=23
Could it be for that reason?

EDIT: Tested with removing the Points= section and still no result...

Last edited by JB_uk; 10/10/14 03:18 PM.
Re: Help with readini and rounding. [Re: JB_uk] #248512 10/10/14 04:36 PM
Joined: Dec 2008
Posts: 1,511
westor Offline
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2008
Posts: 1,511
Well try using this code i have also adding and some other commands maybe is that you want for.


Code: http://hawkee.com/snippet/16078/


- Report here for any problems or anything else.

Last edited by westor; 10/10/14 04:44 PM.
Re: Anyone solve this? [Re: JB_uk] #248519 10/10/14 09:07 PM
Joined: Sep 2005
Posts: 2,876
H
hixxy Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,876
Code:
on *:text:!watchtime*:#:{ 
  echo -s DEBUG: $!isfile: $isfile(points.ini) ~ $!ini: $ini(points.ini,$+(#,.,$nick)) ~ $!readini: $readini(points.ini,$+(#,.,$nick),Points) 
  if (($readini(Points.ini,$+(#,.,$nick),Points)) < 12) { msg # $nick has watched the stream for $calc($readini(Points.ini,$+(#,.,$nick),Points) * 5 ) minutes. }
  if (($readini(Points.ini,$+(#,.,$nick),Points)) > 12) && (($readini(Points.ini,$+(#,.,$nick),Points)) < 287 ) { msg # $nick has watched the stream for $floor($calc($readini(Points.ini,$+(#,.,$nick),Points)) / 12 )) hours. }
  else { msg # I'm not working. }
}


Can you have someone try to run the script and then post the message that is echoed to your status window here?

Also, are you aware that your script will trigger for values less than 12, and values more than 12, but not values that are actually 12?

Your first if statement uses "< 12" (less than 12) and your second uses "> 12" (more than 12) but nothing handles 12 itself. If 12 is your points value then the else statement will be triggered and your script will say "I'm not working."

<= 12 or >= 12 would catch 12 as well, as these mean 'less than or equal to' and 'more than or equal to' respectively.

Re: Help with readini and rounding. [Re: Nillen] #248521 10/10/14 09:21 PM
Joined: Sep 2005
Posts: 2,876
H
hixxy Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,876
Hi Nillen,

Please don't take this as a criticism because I think you're a valuable contributor to this forum, but I just wanted to make you aware of something.

The help file says that the syntax for setting a variable using the /var command is:

/var [-switches] %variable = <value>

Usually you can get away with not using the = sign, but not using the = has historically caused problems. See these threads:

http://forums.mirc.com/ubbthreads.php?ub...true#Post177377
http://forums.mirc.com/ubbthreads.php?ubb=showflat&Number=177387&page=1#Post177387

If you ever do run into such a problem then it will cause you major headaches in trying to figure out what is wrong with the script because it does work the vast majority of the time, but occasionally quirks in the parser have caused it not to work.

Interestingly, the issues highlighted in those threads are no longer a problem, but it seems like it is safer to use the correct format.

Cheers

Re: Help with readini and rounding. [Re: hixxy] #248524 10/10/14 09:38 PM
Joined: Dec 2013
Posts: 779
N
Nillen Offline
Hoopy frood
Offline
Hoopy frood
N
Joined: Dec 2013
Posts: 779
Edit2: I gotta have to agree with wims. It feel unnatural for me to use the '=', even though it might have been a problem earlier I haven't seen it at all. So it feels better to do it the way I've always done it. Sorry mate. Interesting read though.

Edit1: Looking back at the code I posted here, I see that I accidentally kept a ( bracket in the first %variable when I copy pasted from your code. If you try fixing that, can you try the script again JB? I get the feeling that it is what you want. smile
Quote:
[23:46] <@nillens> !coins
[23:46] <@nillensbot> *Nillen has 58388 total coins.
[23:46] <@nillens> !watchtime
[23:46] <@nillensbot> *Nillen has watched the stream for 28wks 6days 17hrs 40mins.
using the same script, modified to use my own points system.
Code:
on *:text:!watchtime:#: { 
  var %points $coins(read,$nick)
  var %time $calc(%points * 5 * 60)
  var %duration $duration(%time)
  msg # $nickpref($nick) has watched the stream for %duration $+ .
} 

Last edited by Nillen; 10/10/14 09:49 PM.

Nillens @ irc.twitch.tv
Nillen @ irc.rizon.net
Re: Help with readini and rounding. [Re: hixxy] #248525 10/10/14 09:39 PM
Joined: Jul 2006
Posts: 3,530
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,530
Well, originally the equal sign was added to help with parsing /var (which is stupid, there is no need for it to help parsing, it even leads to quirk).
It was made optional after I more or less strongly suggested for that, and this since 6.21, not using the equal sign will not produce an error since 6.21, so nobody will ever run into problem because of it.
And there is no reason to argu that it should be used because the help file states it should, the help file is outdated/wrong/incomplete in a lot of point.
More importantly, using the equal sign today can only lead to quirk, not the other way around.
The correct format is the one that was available first, and that is WITHOUT the equal sign.

Last edited by Wims; 10/10/14 09:45 PM.

Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: Help with readini and rounding. [Re: Wims] #248526 10/10/14 09:50 PM
Joined: Sep 2005
Posts: 2,876
H
hixxy Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,876
Do you have any links to examples where using = causes issues and not using it doesn't? I have never heard of that before.

The help file being incomplete does not mean you should ignore it. I would suggest it is still better to use the documented syntax rather than undocumented.

Re: Help with readini and rounding. [Re: hixxy] #248528 10/10/14 09:59 PM
Joined: Jul 2006
Posts: 3,530
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,530
No link, but an example:
Code:
//var -s % $+ a = 1

This is actually a clue showing the '=' was added after and that it wasn't added properly, that's why I recommend not using it, it can only lead to issues, while not using it cannot.
Quote:

The help file being incomplete does not mean you should ignore it. I would suggest it is still better to use the documented syntax rather than undocumented.
That's really what I was talking about, people recommend using it because the help file recommends it, and yes, one should typically follow the help file, the problems start when the help file is actually misleading, that you should not be following it or it won't work properly, and the mIRC help file unfortunately has a lot of this.

Last edited by Wims; 10/10/14 10:24 PM.

Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: Help with readini and rounding. [Re: Wims] #248529 10/10/14 10:09 PM
Joined: Sep 2005
Posts: 2,876
H
hixxy Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,876
I can see the argument for both sides now. It's a strange situation.

I was a victim of a nasty bug in one of my scripts arising out of not using = and that's why I started to use it.

That said, either the help file should be updated or this bug fixed.

Re: Help with readini and rounding. [Re: hixxy] #248530 10/10/14 10:23 PM
Joined: Jul 2006
Posts: 3,530
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,530
So was I, but instead of accepting the fail, I had to blame something else laugh
It seemed unecessary and it was made to work correctly in the next version so I was rather happy with it, the only problem one had not using it before was because ",%var" would be seen as a new declaration:
var %a 1,%b $mid(text,%a,1) would fail without '=' with $mid invalid format.
That's the kind of stuff that won't be fixed, the help file is only misleading because it doesn't work properly, but it is supposed to, and it's not like Khaled wants to document all the quirks in mIRC, would take an entire lifetime, though we started working on http://wikichip.org/wiki/mirc for this reason, so the real behaviors and all the known and important quirks are documented, with better examples and documentations.

Last edited by Wims; 10/10/14 10:24 PM.

Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: Help with readini and rounding. [Re: Wims] #248531 10/10/14 10:30 PM
Joined: Sep 2005
Posts: 2,876
H
hixxy Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,876
I admire your enthusiasm. I'd rather just have the easy life and use the documented format than argue that the undocumented format should work laugh

I will continue to use = until the help file says we shouldn't, which will be until the end of time given Khaled's tenacity for not wanting to break existing scripts with mIRC updates. That might be why he hasn't fixed this issue, in case it breaks existing scripts that rely on the quirky behaviour.

I have to say though that although you have highlighted a bug, I don't think it is one that most people will encounter. I can't think of any situation where you would want to dynamically name a local variable.

Re: Help with readini and rounding. [Re: hixxy] #248532 10/10/14 11:58 PM
Joined: Jul 2006
Posts: 3,530
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,530
It's not about easy or hard life, it's about knowing, being aware. Most scripters nowadays use evaluation brackets to:
-Set dynamic variable, but why, it's not needed/faster, it's just useless and makes the code ugly.
-Retrieve dynamic variable, well that's faster than $eval, but that's because $eval is a huge quirk in itself and it's not like people use it arguing 'what? i'm winning pico seconds here'

The answer is monkey see, monkey do, we don't need/want no monkey. Quirks are fine as long as they are known and documented, each language has its good and bad practices, its quirks etc, the mIRC community is the only one I see not trying to get better regarding this. Codes uploaded on hawkee are usually terrible, among all the code with possible injection via timers/scon, 95% of them are vulnerable with no $safe, there is nothing telling them about those injections anyway.
This 'bug' is actually not a bug but a quirk, difference being that it's incorrect behavior but it won't be fixed because of its nature (requires change to the parser, which khaled avoids, *understandable*). I want more awareness for people, more communication/documentation from khaled regarding the quirks, cause for now, it's who is the most aware and who you trust the most and you need to find the thread from the 200X years where khaled said something about a quirk to justify it.


Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: Help with readini and rounding. [Re: Wims] #248544 11/10/14 07:46 AM
Joined: Sep 2005
Posts: 2,876
H
hixxy Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,876
The timer/scon thing is most definitely not a bug, but the issue being discussed here is.

The fact is that the assignment symbol (=) is being used as part of the variable value when it shouldn't be. That's a bug, not a quirk.

I think the more unusual things you are trying to do with your code, the more quirks and bugs you will come across, and setting dynamic local variables is unusual (although this also occurs with /var -g).

Likewise if you start messing around with things like:

Code:
//set %x $!time | timer 1 5 echo -a % $+ x $(| unset %x,0)


Rather than using the neater and more preferable alias method:

Code:
alias echotime {
  echo -a %x
  unset %x
}


Code:
//set %x $!time | timer 1 5 echotime


Then you're more likely to run into issues.

There must be thousands of quirks in every scripting and programming language, it would be impossible to document them all and a pretty pointless exercise when most users will never come across them.

Page 1 of 2 1 2