The function FormatLinks has been updated! I overhauled it to clean up the code and remove most of the logic as it was unneeded.

Note that this new version relies on the all modifier, so if you're on AYA or an old version of YAYA, you may need to adjust it to use a local variable. (Or, I would highly recommend converting to YAYA/updating YAYA instead!)

I don't usually think about this function too much, I just plop it into a ghost and go. But this time I took a closer look because I recently realized that the ASC function is actually an old one from AYA, and that the compatible.dic file that comes with YAYA now redirects ASC to CHR instead in most cases! So, I figured it's better to update this function so that it doesn't require compatible.dic to run it. (Also, note for AYA users, that means if you want to use this function you'll need to convert the CHR function calls to ASC instead.)

And, well... as is so often the case, once I start tinkering with something I quickly realize how many other things about it I'd like to change. I realized that the logic of the function is a bit overly complicated for what is ultimately a simple goal, and I thought it might be nice to refresh it.

This is the original code:


FormatLinks
{
	_display = ""
	for _i = 0; _i < ARRAYSIZE(_argv); _i++
	{
		_display += _argv[_i] //Add the link/title
		
		//Alternate between adding ASC(1) or ASC(2)
		if _i % 2 == 1; _display += ASC(2)
		else; _display += ASC(1)
	}
	_display
}

First, I slimmed things down by adding the all modifier and removing the local variable from the equation entirely. That reduced visual clutter a lot.

Second, I realized that I could handle each pair of title/url in one iteration of the loop rather than 2 if I made the loop jump up by 2 every time instead of 1. This removed the need to check if it is an even or odd iteration of the loop. With that change made, I realized it might read more intuitively if I put everything into a single line instead of splitting it up!

Here is the code after the changes:


FormatLinks : all
{
	//Loop jumps by 2 so that it works with pairs. Url can be grabbed by using _i + 1
	for _i = 0; _i < ARRAYSIZE(_argv); _i += 2
	{
		"%(_argv[_i])%(CHR(1))%(_argv[_i + 1])%(CHR(2))"
	}
}

So, now the loop is greatly simplified. The function still works with alternating strings of titles/urls, as I think that's still the easiest/cleanest way to write them, but now the function itself is slimmer and simpler. Hooray!