EDCD / EDDI

Companion application for Elite Dangerous
Other
437 stars 81 forks source link

Escape sequence \\ not working in v4.0.4-b1 #2614

Closed Darkcyde13 closed 1 month ago

Darkcyde13 commented 1 month ago

What's Wrong (please be as specific as possible)

Expected

Escape sequence double slash ( \\ ) to work as normal.

Observed

EDDI reports error of unexpected \ There is a problem with this script at line 10. expected expression, found \

Steps to reproduce

  1. Use the \\ to escape quote marks in your code.
  2. Run the code and observe error message.

Configuration

My Investigation

Investigation Notes

I was looking over the new 'Destination arrived' event script, and wanted to see about making some changes to the Anarchy pirate report at the end. I copied the default code out to a temporary script and made my changes, then tested it to see how they sounded, but I was greeted with the above error message.

I've traced it down to it being the double slash to escape the single quotes in the criminal/pirate OneOf() code. If I make them single slashes, the script runs, but doesn't speak the criminal/pirate line.

This is the code I copied out of the new default script:

{Occasionally(2, "
              Caution:
              {set local to OneOf('local', 'nearby')}
              {set chatter to OneOf('chatter', 'gossip', 'rumor')}
              {set indicate to OneOf('claims', 'suggests', 'implies', 'reports')}
              {OneOf('{local} transmissions {indicate}', 
                 '{chatter} in {local} transmissions {indicate}')}
              {Occasionally(3, 'that there is')}
              {OneOf('increased', 'elevated', 'heightened')}
              {OneOf('criminal {Occasionally(2, \\'syndicate\\')}', 
                 'pirate {Occasionally(2, OneOf(\\'gang\\', \\'clan\\'))}' )}
              {OneOf('activity', 'presence')}
              in {OneOf('the area', 'the vicinity', 'this sector', 'this system')}.
              {OneOf('Remain', 'Stay', 'Keep')} {OneOf('vigilant', 'alert', 'frosty', 'sharp')} 
              {Occasionally(3,' {F(\\'Honorific\\')}' )}.
           ")}

I changed the Occassionally to 1 so that it would always activate, and clicking the test button produces the error. The syndicate, clan, gang, and Honorific function do not work.

I have that escape sequence in a couple of my other scripts, and they also fail now. In one, I use the sequence only once, and I now get this error when testing it: There is a problem with this script at line 2. expected end of string, found incomplete expression. However, the \ is actually on line 32. If I remove one slash, the script works, unless it tries to execute that particular line of code (it's in a OneOf() ).

This is that script if you wish to test it:

{_ Missions Route Report _}
{_ Report the current route information _}

{if system.systemname != state.routedetails_destination && len(state.routedetails_route) > 0
  && state.routedetails_route != "Not set":

    {set route to split(state.routedetails_route, "_")}

    Route Report: Destination {if len(route) = 1: system |else: systems}:

    {set cur to 0}
    {set length to len(route) - 1}
    {while cur < len(route):
        {P(route[cur], "starsystem")}
        {set cur to cur + 1}
        {if cur = length: and
        |elif cur < length:,
        }
    }.

    {if len(route) > 1:
        Total Distance: {round(state.routedetails_routedistance, 2)} light years.
        Initial Destination: {P(state.routedetails_destination, "starsystem")}.
    |else:
        Distance: {round(state.routedetails_routedistance, 2)} light years.
    }

|elif system.systemname = state.routedetails_destination:
    Route Report: You are in your destination system, {P(state.routedetails_destination, "starsystem")}.

|else:
    {OneOf("You {OneOf('have no', 'don\\'t have any')} mission route
             at {OneOf('this time', 'the moment')} to report",
           "{OneOf('There is', 'You have')} no route to report at {OneOf('this time', 'the moment')}")}.
}

EDDI Logs

None, but can be provided if needed.

Player journals

N/A

Darkcyde13 commented 1 month ago

Quick update: I just went back to 4.0.3 and it all works as expected, no errors at all. So definitely a bug in 4.0.4-b1.

Tkael commented 1 month ago

I actually don't think this should have been escaped with \\ in the first place. The escape character is supposed to be a single \, every single escape should not require \\.

Regardless, thank you for letting me know about this issue. I pulled the Destination arrived code from the deprecated Entered signal source script and should have given it a closer once-over.

Proposed change to Destination arrived:

    {Occasionally(2, "
              Caution:
              {set local to OneOf('local', 'nearby')}
              {set chatter to OneOf('chatter', 'gossip', 'rumor')}
              {set indicate to OneOf('claims', 'suggests', 'implies', 'reports')}
              {OneOf('{local} transmissions {indicate}', 
                 '{chatter} in {local} transmissions {indicate}')}
              {Occasionally(3, 'that there is')}
              {OneOf('increased', 'elevated', 'heightened')}
              {OneOf('criminal {Occasionally(2, \"syndicate\")}', 
                 'pirate {Occasionally(2, OneOf(\"gang\", \"clan\"))}' )}
              {OneOf('activity', 'presence')}
              in {OneOf('the area', 'the vicinity', 'this sector', 'this system')}.
              {OneOf('Remain', 'Stay', 'Keep')} {OneOf('vigilant', 'alert', 'frosty', 'sharp')} 
              {Occasionally(3,' {F(\"Honorific\")}' )}.
           ")}

Proposed change to Missions Route Report:

    {OneOf('You {OneOf("have no", "don\'t have any")} mission route 
            at {OneOf("this time", "the moment")} to report', 
           '{OneOf("There is", "You have")} no route to report at {OneOf("this time", "the moment")}'
    )}.
Darkcyde13 commented 1 month ago

Ah, for a moment I couldn't see a difference in your proposed code to that which I tried last night, then I noticed you've swapped over the single and double quotes. 😉

So now we can't escape a quote mark if it is the same type used to encapsulate that part of the speech. As I mentioned, it used to work in v4.0.3 and before, but not now in v4.0.4-b1. I'm sure others will fall foul of this change as I have, so would it be possible to add it in the change log, so that others can also be made aware, and update their scripts accordingly?

Tkael commented 1 month ago

So now we can't escape a quote mark if it is the same type used to encapsulate that part of the speech. As I mentioned, it used to work in v4.0.3 and before, but not now in v4.0.4-b1. I'm sure others will fall foul of this change as I have, so would it be possible to add it in the change log, so that others can also be made aware, and update their scripts accordingly?

I'm still not entirely satisfied with that part. Either alternating between single and double quotes should work or escaping (with a single backslash for the first level of escaping) should work. Mulling this over.

Tkael commented 1 month ago

Escaping a single level works just fine, e.g. {OneOf('lava flows {Occasionally(1, \'at the surface\')}')}. It's when we go multiple levels deep that we start to have problems, e.g. {OneOf("lava flows {Occasionally(1, \"at the \{OneOf(\\"surface\\")}\")}")}.

Tkael commented 1 month ago

It may share some similarities with #2607 in that we are trying to iteratively parse functions in ways that native Cottle functions do not support, e.g. {when(rand(1) = 0, "foo {when(rand(1) = 0, \"bar\")}")} also fails.

Darkcyde13 commented 1 month ago

@Tkael, Sorry to drag this one back, but I'm having trouble with the following code, I just can't get it to work no matter what I try with the quote marks or escape sequences. Any Ideas?

{Occasionally(1, "Commander {CMDR} would be proud! {if CMDR = 'Mechan': {Occasionally(2, ', and Glory to Mankind!')} ")}

While this is line 34 in my code, EDDI keeps saying there is na error on line 2. If I remove this line entirely, then it all works as expected.

Tkael commented 1 month ago

@Tkael, Sorry to drag this one back, but I'm having trouble with the following code, I just can't get it to work no matter what I try with the quote marks or escape sequences. Any Ideas?

{Occasionally(1, "Commander {CMDR} would be proud! {if CMDR = 'Mechan': {Occasionally(2, ', and Glory to Mankind!')} ")}

While this is line 34 in my code, EDDI keeps saying there is na error on line 2. If I remove this line entirely, then it all works as expected.

Perhaps something like this?

{set CMDR to "Mechan"}
{set mechan to:
    {if CMDR = "Mechan": {Occasionally(2, ', and Glory to Mankind!')}}
}
{Occasionally(1, cat("Commander {CMDR} would be proud!", mechan))}
Darkcyde13 commented 1 month ago

Ahh, thank you for your solution. :-) It was only when I looked at this again after your answer, that I realised my mistake. I was missing a closing } after ...Mankind!')}.

My code works perfectly when I add it. :-) (I set CMDR to either Mechan or Darkcyde, earlier in my code). {Occasionally(1, "Commander {CMDR} would be proud! {if CMDR = 'Mechan': {Occasionally(2, ', and Glory to Mankind!')}} ")}

Thanks for your answer anyway! :-)