It looks like you're new here. If you want to get involved, click one of these buttons!
<<beginmacro>> Macro this text <<endmacro>>
How do you do that? In case it's relevant, let me explain exactly what I've got going.<<dialogbox "0,0" "bluewindow" "Hello player.">>
This presents obvious problems, most of which being I can't easily use Tweecode inside the argument or it will break. I even wrote my own tiny parser to get around this.
<<dialogbox "0,0" "bluewindow" "Hello #print $player.Name#.">>
I can't create two separate macros, because as I'm sure the people who can answer this question know, you get errors (div tag wasn't closed (even though it was)). Obviously it CAN be done, as <<if>> and <<replace>> show, but am I in over my head? Is it even worth it just so I can get some cleaner code? I'd like to do something like this:
<<dialogbox "0,0" "bluewindow">> Hello <<print $player.Name>>.<<enddialogbox>>
Comments
A few caveats first:
- I was unsure why you're were assigning to properties on the macro, rather than simply using local variables, but I kept that behavior anyway.
- Also, I didn't see a place in your sample code for the coordinate argument from your examples, so the following probably needs extended to include it.
- Finally, your sample code printed $playerName, while your examples used $player.Name. The macro currently uses $playerName from your original sample code.
Prototype:<<dialogbox SPEAKER OPTIONAL_ID>>DIALOG_WIKI_TEXT<<enddialogbox>>
Usage: Code:
It matches the opening macro tag, the closing macro tag, and the contents in between. The start and end indices are only for the contents though, so it can be easily sliced out later.
More or less. Normally, the wikifier doesn't even see the closing tag, it's completely handled by the parent macro. The <<enddialogbox>> macro is only there to keep the macro formatter from complaining, which will only happen if you have mismatched number of <<enddialogbox>> to <<dialogbox>> (specifically, too many of the closing tag; the macro itself will complain if it can't find a closing tag, because there were too few). So, it only comes into play if you've mismatched your opening vs. closing tags.
Yes. The <String>.indexOf() method returns where the match started, so since we're matching the closing angle-brackets of the opening tag (">>"), we need to add two to move the start index past them.
Not at all. The conditional of the while loop scans for macro tags. Each time it matches one, it parses the macro's name from the tag and checks to see if it's found the correct closing tag. It keeps looping until it's exhausted all macro tags in its source or it finds its closing tag.
If the incrementing and decrementing in the switch statement is what you were thinking of, that's there to handle tag nesting, so that only the correct closing tag will stop the parse.
It finds the first space after the macro name in a tag, if any, which allows the code to separate the tag name from any possible arguments.
Consider the following Dialog in tweecode. That could easally be parsed by a special dialog module. It would parse standard twee syntax. Individual Speaker styles and formatting could be defined in a separate passage. This wouldn't be difficult to whip together. Just some thoughts on the matter.