Feature - Rejected If Begin index is out of bounds return false

icon315

Member
I was recently trying to edit my script and i came across a problem when checking for "new events". It seems that when using substring() that if the phrase that you are looking for is not present then it aborts the script. i think that instead of aborting it should just return false.

Here is what i would do then:
PHP:
string newm = visit_url("messages.php");
if ( substring ( newm, (last_index_of ( newm, "<span style=\"color:blue;\">New!")), (index_of ( newm, "</td><td class=small><b>From" ))) == true)
write ("<br><br>"+ substring ( newm, (last_index_of ( newm, "<span style=\"color:blue;\">New!")), (index_of ( newm, "</td><td class=small><b>From" )))+"</div>");
 
Any boolean function will abort if it returns false and the output is not captured. Get around it by doing, for example:

Code:
if (function(arg1, arg2)) {}
or
Code:
(!function(arg1, arg2));
 
Last edited:
I think the function we're looking for is contains_text().

Either way, I don't think this'd be possible to implement in ASH.

edit:
Namely,
Code:
if (contains_text(newm, "<span style=\"color:blue;\">New!") && contains_text(newm, "</td><td class=small><b>From"))
 
Last edited:
It seems that when using substring() that if the phrase that you are looking for is not present then it aborts the script. i think that instead of aborting it should just return false.
I have no idea what you mean by "if the phrase you are looking for is not present". substring() doesn't "look for phrases". Please show me your code which is "aborting".
 
I have no idea what you mean by "if the phrase you are looking for is not present". substring() doesn't "look for phrases". Please show me your code which is "aborting".

I did show you the code

I think the function we're looking for is contains_text().

Namely,
Code:
if (contains_text(newm, "<span style=\"color:blue;\">New!") && contains_text(newm, "</td><td class=small><b>From"))

Hey this worked thanks
 
Ah. You want to call last_index_of(), which returns -1 if the string is not present, without bothering to check the result. I encourage you to clean up your coding practices, rather than asking that KoLmafia support you in being sloppy.

Rejected.
 
This might help; it will create a record containing the sender's name, id, and message for each new kmail and load them into a map:
Code:
record my_kmail {
    string name;
    int id;
    string msg;
};

string page = visit_url("messages.php");
matcher m = create_matcher("<span.+?>New!</span>.+?<b>From</b><a href=\"?\'?showplayer.php\\?who=\"?\'?(.+?)\"?\'?</a>*+?\\(#(\\d+?).+?<blockquote>(.+?)</blockquote>",page);
my_kmail [int] inbox;
while (m.find()) {
    inbox[count(inbox)] = new my_kmail(m.group(1),m.group(2).to_int(),group(3));
}
 
Back
Top