I'm working on an HTML5/JavaScript game engine, and I have started to encounter a scenario I haven't ever been in the past, and can't figure out how I can pull this off.
Simply put, I want to split a string into an array, by a character - so long as that character is not within parenthesis.
Basically, in XML files for things like items/tiles, I store "triggers", which are statements giving rules for operations the code will perform. The different parameters of a single trigger are split up with a colon (:), and more than one trigger can be in place for an item, whereby each trigger is split by a comma. Here's an example:
<response trigger="npc:self:dialog:1:3">No, thank you.</response>
(This is basically saying: if this response is selected, make the NPC who asked the initial question cycle to the a specific message of a specific conversion)
Moving along: I have come to need the ability to encapsulate callback triggers within parenthesis of parameters with certain triggers. Here's an example:
<response trigger="shop:open:1:(npc:self:dialog:1:4)">Yes, please.</response>
(This is basically saying: open up a specific store, and when the store is closed, jump to a specific conversation/message for the speaking NPC)
The idea is that when a store is closed, I can invoke the 4th parameter of that trigger (which is a trigger itself). As I am sure you have guessed, the problem here is that if I split the initial trigger-string based on ":", then it breaks up the callback trigger as other (messy) parameters of the main trigger. I don't want that. Nor, do I want to do anything like splitting secondary triggers by another character (for generation reasons later on, and because I imagine there will be times where I will want to nest lots of triggers at deeper levels and I don't want to use different characters. I know of work-arounds, but I'd like to learn the proper way to split by a character that is not contained within other specific characters.
Since I am encapsulating the callback parameter with parenthesis, I figure there must be a clean regular expression I can use to split the main trigger string by all colons NOT INSIDE parenthesis.
Sadly, I haven't been able to come up with the right expression to get this done.
Any ideas?
I greatly appreciate any assistance any of you may have. :)