Rule Text replacements (Reminder Text & co)

Login or register to post comments
Wed, 2012-04-25 23:22
JeReT
JeReT's picture

Hello again,

I tried to add some cool funktionality to my textbox like automatic replacements from ~ to the cards name. And - more important - reminder text.

unfortunately both won't work.
The card name replacement always returns CARDNAME - even if I named the "name"-field of the card.
And the reminder simply doesn't work. It doesn't appear, when i write the keyword and i have no option in the right-click menu.
There is no error in the console though.

my Keywords-file:

has keywords: true

keyword match script: text_filter(value)

keyword mode:
	is default: true
	name: standard
	description: Standard keywords

keyword parameter type:
	name: string
	match: [a-Z]+

keyword:
	keyword: Test
	match: Test
	mode: standard
	reminder: Blablabla

the replacement function (I copied it basically from the Magic template... However I tried to make it slim although I didn't understand much of the code):

text_filter :=
{
	# step 1 : remove all automatic tags
	tag_remove_rule(tag: "<sym-auto>") +
	tag_remove_rule(tag: "<i-auto>")   +
	tag_remove_rule(tag: "<b-auto>")   +
	# step 2 : reminder text for keywords
	expand_keywords@(
		default_expand: { chosen(choice:"standard") },
		combine: {
			keyword  := "<nospellcheck>{keyword}</nospellcheck>"
			reminder := process_english_hints(reminder)
			keyword + "<atom-reminder-{mode}> ({reminder})</atom-reminder-{mode}>"
		}) +
	# step 2b : move action keywords' reminder text to the end of the line
	replace@(
		match: "(<atom-reminder-action>(?:░(?!<kw-).)*</atom-reminder-action></kw[^>]*>)(((?!<atom-reminder| ?<kw-)[^\n(])+)", # i added ░ to avoid a link to a smiley
		replace: "\\2\\1"
		) +
	# step 2c : remove duplicate reminder text
	replace_rule(
		match: "(<atom-reminder-[^>]*>[^)]+[)]</atom-reminder-[^>]*>)([^\n]+)\\1"
		replace: "\\2\\1"
		) +
	# step 3 : expand shortcut words ~ and CARDNAME
	replace_rule(
		match: "~|~THIS~|CARDNAME",
		in_context: "(^|[[:space:]]|\\()<match>",
		replace: "<atom-cardname></atom-cardname>"
		) +
	# step 4 : fill in the cardname atom field
	tag_contents_rule(
		tag: "<atom-cardname>",
		contents: { if card_name=="" then "CARDNAME" else card_name }
		)

	input
}

and where I call the function:

card field:
	type: text
	name: rule text
	multi line: true
	show statistics: false
	script: text_filter(input: value, card_name: card.name)

I hope anybody can tell me what I did wrong... probably I forgot some silly little things... A happy smile

My Colors

Wed, 2012-04-25 23:26
Jéské Couriano
Jéské Couriano's picture

You should not be using CARDNAME in the reminder text; it should always be the neuter (i.e. "this card" or similar).

Wed, 2012-04-25 23:45
JeReT
JeReT's picture

I do not want to use CARDNAME in the reminder text. I want the name of the card when i type ~.

To make things claerer: I have two different problems.
Problem 1: The reminder text doesn't work
Problem 2: When I type ~ it always appears CARDNAME but never the actual name of the card.

If I use CARDNAME in the reminder texts of my game is not the case. If I want to, I can, but I agree, that it is not a good idea Winking smiley
So please answer my question only from a technical point of view.

Edit:
I tried to replace default_expand: { chosen(choice:"standard") }
with default_expand: { true }
because I have no checkbox, where I can choose the mode... The reminder text should simply always appear...
But nothing changed... still no reminder text A sad &#039;frowny&#039;

My Colors

Thu, 2012-04-26 03:40
green_meep
Administrator
green_meep's picture

Do you have the "standard" keywords enabled in your game file? If not, that's probably why they're not displaying, haha.

Have you tried updating your text box? For some reason, MSE only seems to update the CARDNAME when it's edited.

Thu, 2012-04-26 09:39
JeReT
JeReT's picture

hi green_meep,

thanks for your suggestions.

I think i have "standard" not enabled in my gamefile... please tell me what i have to write to do this.

The card name problem: nothing changes when I change the name of the card.

My Colors

Thu, 2012-04-26 17:13
green_meep
Administrator
green_meep's picture

Okay, I finally got my scripts in front of me. The problem is that you're asking MSE to check whether "standard" is selected in some arbitrary field. I would try commenting out the default_expand line.

As for the card name, I meant that you should try editing the textbox that CARDNAME would be contained in, not the textbox that card.name is in. For some reason (there's another thread on this), MSE doesn't auto-update non-MtG templates' CARDNAMEs.

EDIT: I didn't see that you'd tried setting default_expand to true. Could you post a link to a .mse-installer file?

EDIT2: Try commenting out your "keyword match" line. I've never seen it used - I think it's just a simple function to convert your match parameters to all uppercase or something like that. Whatever it does, you probably don't want it there.

Thu, 2012-04-26 18:47
JeReT
JeReT's picture

Thanks for your support, green_meep.
unfortunately nothing helped so far A sad &#039;frowny&#039;

here is what my code looks like now:

text_filter :=
{
	# step 1 : remove all automatic tags
	tag_remove_rule(tag: "<sym-auto>") +
	tag_remove_rule(tag: "<i-auto>")   +
	tag_remove_rule(tag: "<b-auto>")   +
	# step 2 : reminder text for keywords
	expand_keywords@(
		combine: {
			keyword  := "{keyword}<atom-reminder-{mode}> ({reminder})</atom-reminder-{mode}>"
		}) +

	# step 3 : expand shortcut words ~ and CARDNAME
	replace_rule(
		match: "~|~THIS~|CARDNAME",
		in_context: "(^|[[:space:]]|\\()<match>",
		replace: "<atom-cardname></atom-cardname>"
		) +
	# step 4 : fill in the cardname atom field
	tag_contents_rule(
		tag: "<atom-cardname>",
		contents: { if card_name=="" then "CARDNAME" else card_name }
		)

	input
}

The card name issue also doesn't work under any circumstances. I tried many different things (writing something before the card name or after, changing the card name, adding a card an switch back, etc). Nothing worked A sad &#039;frowny&#039;

Unfortunately I also don't know how to create an mse-installer...

My Colors

Thu, 2012-04-26 18:55
green_meep
Administrator
green_meep's picture

If you're on Windows, simply type magicseteditor packageinstaller.mse-installer package1.mse-game package2.mse-style into your command prompt. It'll create a .mse-installer file somewhere in your home folder with the name specified.

EDIT: if you're having problems converting it to .mse-installer format, just zip it up and host it somewhere.

Thu, 2012-04-26 19:21
Pichoro
Pichoro's picture

If you're using code tags correctly and not altering your code before posting, try moving the { symbol up a line, so the top line of your script reads "text_filter := {"

Also, ditch the extra line between steps 2 and 3.

Are there no error messages in the Console tab?


Also, I don't have time to fix it just this minute, but that keyword function is a mess now.

Thu, 2012-04-26 19:50
green_meep
Administrator
green_meep's picture

That's a good point, Pichoro. I just realized that you're trying set parameters like variables. There's probably a million errors in the console right now, which is why I wanted to have the original so that I could try and run it for myself.

You could try taking a look at the second link in my sig to see if the information (namely in Functions and Variables) helps you any.

Thu, 2012-04-26 20:59
JeReT
JeReT's picture

Thanks for your replies.
There are no errors in the console. Deleting lines didn't help either.

Thanks for the link. I will work through it tomorrow. If i don't see my mistake after it, I will upload it for you.

My Colors

Sat, 2012-04-28 15:37
JeReT
JeReT's picture

Sorry for the double post...
just want to be noticed Winking smiley

I've read your stuff... some things are a bit clearer to me now, but i couldn't solve the problem.
I zipped a version of my template with very small graphics (don't want to share the design before the game is ready to publish).

I would be happy, if you could take a look A happy smile

here is the download link

Thanks in advance A happy smile

My Colors

Sat, 2012-04-28 22:13
green_meep
Administrator
green_meep's picture

depends on: spheres-japanese-cost.mse-symbol-font 0.0.0

No .mse-symbol-font to be found. MSE is complaining - I'm not sure how no errors appear on your side.

The script file should not be indented like you have it now. The text_filter() is the proper way to do it.

I'm not sure, as I fiddled with a lot of things, but I believe the problem is due to that while the "default_expand" parameter should evaluate to true, it doesn't. I also revised the function a little bit. Rules are no longer used - we use the @ symbol now.

Updated code:

Spoiler:
text_filter := 
	# step 1 : remove all automatic tags
	remove_tag@(tag: "<sym-auto>") +
	remove_tag@(tag: "<i-auto>")   +
	remove_tag@(tag: "<b-auto>")   +
	# step 2 : reminder text for keywords
	expand_keywords@(
		default_expand: {true}
		combine: {
			if expand then "{keyword}<atom-reminder-{mode}> ({reminder})</atom-reminder-{mode}>" else "{keyword}" }
	) +
	# step 3 : expand shortcut words ~ and CARDNAME
	replace@(
		match: "~|~THIS~|CARDNAME",
		in_context: "(^|[[:space:]]|\\()<match>",
		replace: "<atom-cardname></atom-cardname>"
	) +
	# step 4 : fill in the cardname atom field
	tag_contents@(
		tag: "<atom-cardname>",
		contents: { if card_name=="" then "CARDNAME" else card_name }
	)

Also, functions like this aren't really "functions" in that they don't take the script's curly braces.

Your "CARDNAME" stayed as such because you forgot the "+" sign before your replace@ function. As a result, MSE didn't know that there was anything coming after step 2 and failed to parse steps 3 and onwards.

By the way, Pichoro, your function works like the MtG's one does. It's odd but understandable that there would be such a discrepancy between passing card.name as a parameter and accessing it directly.

EDIT: Nope, you didn't forget the "+" sign; I must have eaten it while I was fiddling around. If that's the case, then the error regarding your CARDNAME was probably due to the fact that the previous function wasn't executing properly, and MSE wasn't able to get to it.

Sat, 2012-04-28 22:28
JeReT
JeReT's picture

Yeeehaaa!
Thanks a lot! it works now A happy smile

Sorry for not adding the symbol font... i forgot to do this.

My Colors