Need help with a template

Login or register to post comments
Mon, 2012-05-28 16:08
DavidChaos

This'll probably sound stupid once I get the answer, but I can't seem to find it anywhere in documentation or examples.

Basically, what I'm trying to do is make one word list available with one input, one with another, etc. (the input in question is a choice field) I know that the Magic plugin can filter the word lists in a similar fashion, but so far, I've had little luck. I know the reason that it's not working is because the script basically only runs when the card is loaded, whereas in Magic's case, it does change if you change the input. I've looked through the code, but cannot for the life of me figure out why it refreshes in Magic but not in my code; I literally tried copying code that allowed the lists in the first place and replacing the names appropriate to my game, but no luck. Any help would be greatly appreciated.

Mon, 2012-05-28 18:59
green_meep
Administrator
green_meep's picture

It might help us help you better if you post the code here so we can see what you're trying to do.

Off the top of my head, you'd probably want something like:

word_list_switcher := {
	copy := remove_tag(input, tag: "<word-list-")
	"<word-list-" + type + ">" + copy + "</word-list-" + type + ">"
}

Where "type" is passed as a parameter.

Mon, 2012-05-28 20:15
DavidChaos

I was able to get the lists to change! Now, though, I have another snag: unlike in the example I used to try to get here (Magic), the list doesn't change the very next time you drop the list down; instead, the next time you try to input on that list, it happens. Could this possibly be just because Magic is using a text field as a reference while I'm using a choice? And here is the code for what I've got for this:

code
type_filter := [
	is_perma       : match@(match: "permanent")
	is_drop        : match@(match: "drop")
	is_terrain     : match@(match: "terrain")
]

type := card.type
total_filter := { type_filter }

tf := total_filter()

cardtype_filter := {
	input := remove_tag(tag: "<word-list-")
	ct := if   tf.is_perma(type) then "permanent"
		else if tf.is_drop(type) then "drop"
		else if tf.is_terrain(type) then "terrain"
	"<word-list-{ct}>{input}</word-list-{ct}>"
}

Edit: I've noticed that on my game file, the two fields are seperate, whereas the ones in the Magic file are actually displayed in a combined editor? Does this matter? Because in my case, one is a choice rendered as an image while the other is text.

Mon, 2012-05-28 20:19
green_meep
Administrator
green_meep's picture

You seem to have added a bunch of extra code.

game
type:
#blahblahblah
	script: cardtype_filter(value, ct: card.choicefield)

script
cardtype_filter := {
	copy := remove_tag(tag: "<word-list-")
	"<word-list-{ct}>{input}</word-list-{ct}>"
}

If that doesn't work, MSE is known to be finicky about auto-updating fields. You'd have to just make do without it, I guess.

Mon, 2012-05-28 22:28
DavidChaos

Edit: Not as done as I thought! I figured getting that first part right would make the second filter I needed easy, but turns out I'm having just as much trouble, if not more! I'm gonna post up some code now.

script
subclass_sort := if	card.class=="ANGEL" then "angel"
			else if	card.class=="BEAST" then "beast"
			else if card.class=="BIRD" then "bird"
			else if card.class=="DEMON" then "demon"
			else if card.class=="FISH" then "fish"
			else "sub"

subclass_filter := {
		thing := remove_tag(input, tag: "<word-list-")
		"<word-list-{subclass_sort}>{thing}</word-list-{subclass_sort}>"
}

This is the only version I've done that even goes without giving me an error. I've tried using something else to refer to the result of subclass_sort so that it will update (at the very least after making a new selection and dropping down the list again), but I get an error saying it cannot convert the function "{"sub"}" to a string

Tue, 2012-05-29 05:28
green_meep
Administrator
green_meep's picture

It's probably because you forgot the {} function brackets. The only time you leave them out is if you're declaring a variable or using exclusively functions that have the @ symbol (think replace@()). I would try the following:

subclass_filter := {
	thing := remove_tag(input, tag: "<word-list-")
	"<word-list-{to_lower(subclass)}>{thing}</word-list-{to_lower(subclass)}>"
}

The variable "subclass" is passed as a parameter in the function call as I showed you earlier.

Tue, 2012-05-29 17:43
DavidChaos

That doesn't quite work either. In this case, the former value is a text value (which has its own word list, and the options listed are not the only words on the list, but are the only ones that return a particular list). Anything that would work, though, tells me that it cannot convert the function to a string. This is the only version that doesn't return that error:

subclass_sort := { if input=="ANGEL" then "angel"
			else if input=="BEAST" then "beast"
			else if input=="BIRD" then "bird"
			else if input=="DEMON" then "demon"
			else if input=="FISH" then "fish"
			else "sub"
}

subclass_filter := {
		thing := remove_tag(input, tag: "<word-list-")
		sort := subclass_sort(class)
		"<word-list-{sort}>{thing}</word-list-{sort}>"
}

class is defined in the game file as card.class I tried just putting subclass_sort's code as sort itself, but that gave me the "cannot convert function to string" error. Maybe that's the problem?

Tue, 2012-05-29 20:37
hooliganj
hooliganj's picture

Sorry I don't have more time to help with this right now (it looks interesting), but here's a cleaner version of that which may work better:

	subclass_sort := {
		if input=="ANGEL" then "angel"
		else if input=="BEAST" then "beast"
		else if input=="BIRD" then "bird"
		else if input=="DEMON" then "demon"
		else if input=="FISH" then "fish"
		else "sub"
	}

	thing := remove_tag@(tag: "<word-list-")

	subclass_filter := "<word-list-{sort}>{ thing(input) }</word-list-{ subclass_sort(card.class) }>"

De Chelonian Mobile.
My Shadowfist sets.
The Usagi Yojimbo CCG.

Tue, 2012-05-29 20:41
green_meep
Administrator
green_meep's picture

I'm not sure what you're asking here. You said that "this is the version that doesn't return any errors." What additional errors is it producing?

Wed, 2012-05-30 15:02
DavidChaos

Using what hooliganj did above, it keeps telling me that the variable "input" isn't set. The error I was speaking of before is worded, quite literally, "cannot convert function to string".

Edit: I solved it. Turns out that thing I did for the first one initially (which is derived from Magic's coding) is exactly what was needed for the last one. Thanks again, though!