Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

[Harlowe] Quotations inside quotations inside macros inside more quotations

edited October 2015 in Help! with 2.0
As far as I know, there are two characters that can be used as delimiters when you define a variable: double quotations and single quotations. So I can write a set: macro, enclose the value within "", and inside that text, write another set: macro, and enclose the value within ''.

What if I need to embed a third set: macro within the second one. There is already an unclosed " and ' so if I use one of those characters Harlowe will think it's a closing one, and I need an opening.

This is the structure I'm trying to get right:
(datamap: 1, "   (set: $two to '  (set: $three to &  value  &)  '   )"   )

I need something to put where the & are.

Is there something I can do? Thanks!

Comments

  • What problem are you trying to solve where you believe the solution is to embed one (set:) macro inside another?
  • edited October 2015
    Heh. You're probably going to regret that question. :-)

    The problem is that I am building a quite complicated nightmare thing with Harlowe, where most content (at the moment, in the end I think it will be all content) is stored in datamaps and then text for each "scene" is built from a bunch of different places, using different loops that cycle those datamaps. Location description, weather description, narration and available choices, all come from different datamaps.

    Just to give you a clue, the most similar thing I can think of is Fallen London.

    So my problem is already buried under a hell of a pile of other code that would be quite difficult to explain.

    This is the convoluted explanation:

    -I have Passage A, with some text description.
    -Choice Alpha in another passage sends me to Passage A with (goto:).
    -But I also want Choice Alpha to add some extra text to the text of Passage A.

    I already have a mechanism in place for that:

    -At the beginning of Passage A I display another passage
    -It checks for extra text in a global extra text datamap
    -If there is a value for the current passage, it prints at the beginning

    So, when Choice Alpha is clicked, I use a (set:) to add the extra text to the extra text datamap.

    But then, what if I want that extra text to show up only once? I need to remove the extra text from the datamap right after it is printed. So I thought: include the (set:) macro that removes the extra text from the datamap in the extra text itself.

    By now you must be dizzy, but this structure is what I wrote in the first post: a (set:) inside a (set:) inside a (set:). Each with its own pair of quotations.

    Any alternatives I have thought would require limiting features or complicating the code even more (datamaps nested inside datamaps, I already have enough of those). Being able to use a third set of quotations would be the easiest.
  • I will need to think about the overall problem but while you wait for either me or someone else to suggest a solution to it you may want to think about a couple of things.

    note: The following is based on my limited understanding on how Harlowe works internally, Leon would be the best person to explain these topics.

    If you are plaining on using $variables to store these datamaps (using (datamap:)) you may need to be aware on how the story format handles History (timeline). From what I understand each passage navigated to by the Reader is added as an entry to the timeline and each entry tracks the name and the variables changed within the passage, and this may include the initial startup passage. (it may track the current value of all variables for each passage, but I am unsure of that as I have not examined the source code to that degree)

    The end result is that by using large and/or many (datamaps:) the History of the story could become quite large in storage size.

    If you also plan to give the Reader the ability to save their progress through the story (using (savegame:)) then you also need to be aware that save works by persisting the History (at that point) to the web-browser's Local Storage, and that by default Local Storage can only store between 5-10MB of data (per story). The actual size depends on the brand of browser and the nature of the data being stored.
  • edited October 2015
    A million thanks for that greyelf. Those are some of my biggest concerns. My prototype works OK now, but it has maybe 1/50th of the intended content. I'm worried about its future performance.

    However, I think that, by virtue of pure serendipity, the problem you warn about may not happen. The way I wrote the mechanism, all of the choices are written into datamaps. Each direction from one location to another is one value in a datamap, and also all the story choices as you advance in the game. I have plans for 50 locations and many storylines. So the heap will be high.

    BUT. I think it won't be all stored in the history as you suggest. I'll try to explain (but this is all very abstract and I'm not a developer). The whole content of the game is never simultaneously declared into datamaps. The datamap that is declared at all times is a list of available content, which contains passage names. What happens when you enter a new passage with a (goto:) is this:

    -The plain text in that passage is printed.
    -An "engine" passage is run with (display:).
    -This engine runs a loop through the list of available content, and (display:) each available passage sequentially.
    -Each of those passages (set:) the variable $a to a datamap.
    -If a relevant value is found in $a, it is added to a temporary array. (Relevant values are those options available in your current passage and your current state of the story. Each value of the datamap $a is actually a nested datamap.)
    -The next available passage is displayed and it overwrites the $a datamap. That's the reason I say that the content of the game is never simultaneously stored.
    -The loop goes on. The big content datamap is overwritten again and again: only the relevant options are added to the temporary array.
    -The loop stops.
    -The options in the temporary array are printed and the player can play.

    So, unless each (display:) macro generates history entries, only a couple of not too gigantic datamaps are actually stored each time. Regarding savegames, it is automatic and limited to one slot.

    As I said before, I'm worried with how fast will this loop work when it has to go through 200 passages.

    PS: I have solved the problem in the original post with a sub-optimal solution. Suggestions welcome.
Sign In or Register to comment.