Eliteofdelete Questions 2

I figured I would just make another big thread to fill with my random questions. My current struggle has to deal with matchers. After reading about them and looking at some implementations of them, I tried to make a very simple case.

Code:
string text, result;
matcher finder; 
text = "2_text";
finder = create_matcher("^[0-9]$", text);
result = group(finder, 1);
print(result);

I was hoping this would give me "2" but instead I keep getting "No match attempted or previous match failed". I've played with it for awhile, changing the matcher and adding more text but nothing seems to help :(.
 

Bale

Minion
You forgot to do find(finder). If you don't use the find() command, then no match will be found. Until you do that, it hasn't actually attempted to find the matcher which you defined.

However, your matcher won't work. It will only match if there is a single integer which is at the beginning of the line and end of the line. (The ^ matches the beginning of the string and $ matches the end of the string in the same way that [0-9] matches a digit.) In other words it will only match a string which is composed of a single integer. Only add the ^ or $ if you want to ensure you are matching a digit at the beginning or end of the string.

Perhaps the regexp you wanted was actually "[0-9]" Or to be even more succinct "\\d" since \d is any digit and [0-9] is the set of all digits. If you want to be able to match numbers of more than one digit, you should add a + after the \d so that it matches one or more characters instead of only a single digit.

Finally, there is no group 1 because you neglected to use parenthesis to define a capturing group. That's not really necessary though since group 0 is the entire matching string.

Here's my riff on your scriplet:
Code:
string text, result;
matcher finder; 
text = "2_text";
finder = create_matcher("\\d+", text);  // "[0-9]+" would work just as well, but I like to call a digit a digit.
if(find(finder)) {
   result = group(finder, 0);
   print(result);
}
else print("match failed", "red");

Note the "if" statement. Unless you do that, any failed match will produce a run-time error when it gets to the group() command, just like your example failed.
 
Last edited:
Is there a way to submit the form in a relay through a command of some sort?

I have a button when pressed, it will buy a bunch of items during which I would display "Buying....". After it finishes, I want to change the "Buying...." to change to some info text.
 
Last edited:
After playing around with it some today, it seems this might be harder than I expected. I tried putting the KoLMafia buying logic after the end of the form, but it gets executed before the form is displayed (because html takes two passes to get displayed?).

So, I tried setting a true/false global variable. If it is false, have it post the "Buying" text and switch to true. Then at the end of the form I had
Code:
if (buying)
     page.append("<script language='javascript'>document.relayform.submit();</script>");

Unfortunately, this wouldn't actually submit the form. But even if it did, I fear it would still run into the same problem I was having at the start where it would see that buying is true and re-submit the form before actually displaying the form.
 

Theraze

Active member
Maybe look at the OCD relay? Since that one lets you set items and then update the map file with what you told it to do after you hit the submit button...
 
Maybe look at the OCD relay? Since that one lets you set items and then update the map file with what you told it to do after you hit the submit button...

I have been, and my script already does that. My problem is after I update the map, I want to pass it off to an ASH buy logic. The buy logic will occur before the HTML is displayed, no matter the location it is in main.

Basically, I want the form to be submitted and the HTML to load before the ASH buy logic is commenced. Because at the moment, if I click the "Buy" button, it seems like the page gets stuck/frozen when in reality KoLMafia is just buying items. If I could print a big "Buying...." while the ASH buy logic is commencing and then have the forum re-submit with the "Items were bought for X meat" info, it would eliminate any possible user confusion.
 
I think some JavaScript might help you here. How to write it, though, I do not know. (Basically what you're trying to do is a perfect fit for an AJAX request.)
 

Bale

Minion
After playing around with it some today, it seems this might be harder than I expected. I tried putting the KoLMafia buying logic after the end of the form, but it gets executed before the form is displayed (because html takes two passes to get displayed?).

I would recommend doing that before generating the form and executing it based on a starting condition (like a form field) that only exists if the "buy" button was clicked.

html does not take two passes to be displayed. That's an illusion in your mind caused by thinking of things in the wrong order.
 
I would recommend doing that before generating the form and executing it based on a starting condition (like a form field) that only exists if the "buy" button was clicked.

html does not take two passes to be displayed. That's an illusion in your mind caused by thinking of things in the wrong order.

How would putting it before the generation of the form help? When the button is clicked, I want the form to be reloaded with a "Buying...." message displayed and then have then have the KolMafia buy items. If I put it before form generation, but after fields=form_fields(), then I would just guarantee that the items are bought before any form display. As of now, you click buy and it will give a "page is loading" cursor as KoLMafia buys items, then the form is displayed.

As for the HTML thing, I read it online as I was trying to learn how to use HTML (it was in a debate as to why CSS layout is better than HTML layout). Supposedly, HTML formatting takes two passes by a computer before it will display the web page. It probably does not apply to what I am trying to do tho.

I think you are right tho wrldwzrd, I need some sort of JS to do some semi fancy form loads to get it to display in the order I want it too. Unfortunately, I don't know how to write it either and even if I did, I'd have to figure out how to input it into the relay script. So far, my previous attempts to use any JS have been failures :(.

Thanks for trying to help guys, but I've kinda given up implementing it.
 

Bale

Minion
The form is always reloaded after clicking a button on the form. When reloading the form, first take relevant actions before doing anything to constructing the web page and then add the "Buying..." message if the buy button had been clicked.
 
Top