Form of...HTML!

Banana Lord

Member
No, you're right Jason. It was a missing angle bracket causing the problem. Safari was managing to figure out what I meant, and for some reason specifying a label fixed the problem in the other browsers.

I have no knowledge of Javascript, but if it turns out to be what I need I'll look into it when I get a chance. If, on the other hand, these ash functions you speak of eventuated, I would be very happy to use them instead :).
 

heeheehee

Developer
Staff member
KoLmafia has a JSON parser built in. With some effort, we could make a set of ASH functions to interface with it.

That would be pretty nifty, even for non-relay usage, since it'd make serializing maps more straightforward. Granted, the only reasons I can see for this in ASH are storing something in a property for some reason, printing to the screen, and accepting user input, but it'd still be nice to have the option.
 

Banana Lord

Member
Is it possible to have write_field() accept 'none' or blank input for non-string types? Currently I have a bunch of write_field() entries, some of which need to be blank on occasion, and I'd like to specify an input type for them to catch typos in item names and suchlike.
 

jasonharper

Developer
You would need to write a field validator function that accepts a blank entry. "itemnonevalidator" would be a good place to start.
 

Banana Lord

Member
Would it be possible to grab the html code that the script outputs? I'd like to have mafia save the html that a relay script I wrote produces to a data file so that I can make the data processed by the script accessible to applications other than mafia.
 

slyz

Developer
The relay script can certainly grab the html code it produced. What does your request have to do with this thread?
 

Banana Lord

Member
Oh, I assumed that there'd be a function handling that in htmlform.ash. Since I've posted here now, would you mind telling me how I'd save that html to a file?

Please excuse my mistake, you can probably tell that I know very little of what's happening 'under the hood' here. I have no experience coding outside of Python (and even that I only started learning this year), so what I know about ASH/Java (which is what I assume ASH is based on, in part at least) I've learnt through trial and error, picking apart other people's scripts and asking here on the forums.
 

slyz

Developer
After refreshing my memory by actually looking at a few relay scripts, I understand why you posted here. Any time one of htmlform's function is used, it uses write() directly: even if the relay script saves in a variable the html code it produces, you won't have access to the bits added by htmlform functions.

You would need to change all of the functions in htmlform.ash to return a string instead of using write(). For example
PHP:
void finish_page()
{
	writeln("</form></body></html>");
}
would become
PHP:
string finish_page()
{
	string str;
	str += "</form></body></html>";
	return str;
}
and change your relay script to build the html (including htmlform html) in a single string that you can save via map_to_file(), and then send to the browser using write().

Maybe you could also try to some other way to save the html produced: is there some way to get the page to save itself somewhere?
 

Bale

Minion
When I want to see (or save) the code, I right click in the relay browser's main frame and choose frame -> Source. Then I can just look at it or save it easily. I assume that Firefox and IE probably have such an option also.
 

Winterbay

Active member
What happens if you put a visit_url() at the bottom of your relay-override? Will that page contain the overridden code or will it only use the native one since we are not coming from the browser but from Mafia itself?
 

Banana Lord

Member
Adding a visit_url() after finish_page() puts the script into an infinite loop printing "Unexpected error, debug log printed." Putting it before finish_page() does the same, but without the error message.
 

Banana Lord

Member
I have no idea what a stack trace is, but I'm sure I'll be set straight about that in a few minutes :) It's quite a large debug log, hence the zip format.
 

Attachments

  • DEBUG_20110707.txt.zip
    395.6 KB · Views: 47

matt.chugg

Moderator
feature request for the next version:

Overloads, or expansions (if ash accepts optional parameters) of the write_check functions to include cssclass. this would allow check box to have css allowing for things like javascript checkall functions.

Code:
SNIP

writeln( "$('#checkallusable').click(function() {$('.useable').each(function() {this.checked = true;})});" );

SNIP

i've added the overloads to my htmlform.ash, but will most likely forget and update when theres a newer version.
 

StDoodle

Minion
Yup; if you find yourself using the same or same format of attributes multiple times, you can always write a wrapper function that does attr() and write_whatever() all in one (I've done that myself).
 

matt.chugg

Moderator
well, you learn something new every day! playing kol for 5 years exactly today, and i'm still just "picking it up"

Thanks guys
 

Banana Lord

Member
Is there a way to differentiate between the relay script being loaded by selection from the dropdown menu in the relay browser and by clicking a button? I'm in the process of rewriting the relay script for Harvest and I want an event to be triggered the first time the page is loaded (selecting it from the dropdown) but not when the save button is clicked. I've been trying to do something like this:
PHP:
if(write_button("save", "Save"))
		{
		writeln("<save_text>Settings saved at "+ now_to_string("h:mm a, ss") +"s</save_text>");
		if(vars["har_gen_completed_setup"] == "false")
			vars["har_gen_completed_setup"] = "true";
		
		set_property("har_relay_clicked", "true");

		updatevars();
		}
The block of html responsible for displaying the event is only written (via writeln();) if "har_relay_clicked" is false (i.e.: the page was not loaded as a result of the button being clicked). The trouble is that, after the button is clicked, the property doesn't seem to get set until after the page is reloaded, causing the event to trigger immediately after clicking the button, but then not the next time the button is clicked.
 
Top