Author Topic: Passing expression as an explicit text string  (Read 4036 times)

Exergist

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 405
  • Ride the lightning
Passing expression as an explicit text string
« on: February 17, 2017, 11:35:22 AM »
Is it possible to explicitly save an unevaluated expression string within a text variable?

In other words is it possible to save "{EXP:('{TXT:answer}'='Anderson') Or ('{TXT:answer}'='Aria')}" (without double quotes) inside a variable "question 1"? In this case, I would NOT want {TXT:answer} to evaluate to the text inside of "answer" or to have the expression logic evaluated. Rather, I want all the text to be kept as-is.

Thoughts?

Thanks!

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Passing expression as an explicit text string
« Reply #1 on: February 18, 2017, 01:51:24 AM »
You need to escape the curly braces using "|", however this only works once. When the string is processed, the escape character is removed.

What are you trying to do with this string?

Exergist

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 405
  • Ride the lightning
Re: Passing expression as an explicit text string
« Reply #2 on: February 20, 2017, 09:21:13 AM »
Would you mind elaborating what you mean by:
Quote
You need to escape the curly braces using "|", however this only works once. When the string is processed, the escape character is removed.

I'm trying to create a more dynamic command for retrieving user input. Besides passing unique questions based on the root command that calls the query command, I want to be able to pass unique text comparison conditions so that the query command can handle the 1.) question posing, 2.) answer retrieval, and 3.) answer processing.

My use case here is for a Mass Effect 3 profile. Two of the questions that eventually need to be asked of the user are "what is Shepard's class," and "who is in your current squad?" Two different questions with two very different sets of conditional text comparisons to grab the user's response and filter down to the required action or variable saving. So it would be slick to pass the conditional text expression as a variable that could then be interpreted by sub-commands.

Clear as mud? Here's a snippet of my work-in-progress code:

A root command for identifying the current squadmates in the party:
Code: [Select]
        Begin Text Compare : [{EXP:('{TXT:answer}'='Ashley') Or ('{TXT:answer}'='EDI') Or ('{TXT:answer}'='Garrus') Or ('{TXT:answer}'='James') Or ('{TXT:answer}'='Javik') Or ('{TXT:answer}'='Kaidan') Or ('{TXT:answer}'='Liara') Or ('{TXT:answer}'='Tali')}] Equals '1'
            Jump to Marker: Assign

I want to do this kind of text comparison in the sub-command that actually does the user query. However since the comparison is unique to the "Set Squad" command, I cannot apply it to the more general query command that can execute for other root commands. So ideally I would need to pass the long EXP text string as a variable for later text comparison in the sub-command query. So I need to somehow store the EXP as an entirely unevaluated text string and get the "Begin a (Text) Conditional Block" to read this.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Passing expression as an explicit text string
« Reply #3 on: February 20, 2017, 11:51:12 AM »
I can see what you're trying to do, but in my opinion it's a convoluted way of doing it.

You have two squad members at most(excluding Shepard), so all you need to do is set two variables:
Code: [Select]
Set Text [SquadMember1] to 'Ashley'
Set Text [SquadMember1] to 'EDI'

And use this in your subcommands:
Code: [Select]
{EXP:('{TXT:answer}'='{TXT:SquadMember1) Or ('{TXT:answer}'='{TXT:SquadMember2')}

Exergist

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 405
  • Ride the lightning
Re: Passing expression as an explicit text string
« Reply #4 on: February 20, 2017, 01:04:36 PM »
That would certainly work for a single question, however it will inherently conflict with other question commands such as the one to get Shepard's class:

Code: [Select]
   
Begin Text Compare : [{EXP:('{TXT:answer}'='Adept') Or ('{TXT:answer}'='Engineer') Or ('{TXT:answer}'='Soldier') Or ('{TXT:answer}'='Infiltrator') Or ('{TXT:answer}'='Sentinel') Or ('{TXT:answer}'='Vanguard')}] Equals '1'

In this case the values and size of the "array" of answers changes. If the size of the array were to stay the same then perhaps this is doable. This is why I'm trying to see if it is possible to pass the "array" of conditional text comparison to sub-commands.

As of right now I've just left the conditional text comparison within the root command (so it's working fine right now). Being able to pass the conditional information would just be a robustness and flexibility improvement.

Thoughts?

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Passing expression as an explicit text string
« Reply #5 on: February 20, 2017, 01:28:42 PM »
I still don't see the advantage, but that's my problem, not yours.

Code: [Select]
Set Text [answer] to [Not Set]
Set Text [test] to '|{EXP:('|{TXT:answer|}'='Anderson') Or ('|{TXT:answer|}'='Aria')|}'
Set Text [answer] to 'Aria'
Begin Text Compare : [{TXT:test}] Equals '1'
    Write '[Purple] Yes' to log
End Condition
Will do what you want. You must use "{TXT:test}" rather than just "test" for the eval, token's probably aren't processed when the variable is used directly.

Exergist

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 405
  • Ride the lightning
Re: Passing expression as an explicit text string
« Reply #6 on: February 20, 2017, 02:45:58 PM »
Thanks again Pfeil for the feedback. Great call on using "|" to indicate a literal curly bracket (help document page 100 as I later discovered).

I suppose in the end what I was trying to do wasn't practical because the actions done during the text comparison (i.e., the steps taken after the text evaluation) are too specific and cumbersome to pass to sub-commands.

I'm sure I'll find a use for "|" in the future :D