1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Variable followed by function constantly failing...

Discussion in 'Support' started by Mordachai, Oct 31, 2016.

  1. Mordachai

    Joined:
    May 9, 2013
    Messages:
    40
    Likes Received:
    0
    If I have code such as:

    set message=The %ReleaseTitle% is now official.%@char[13 10 13 10]The master image is located at:%@char[13 10 9]%%ReleasedMediaFolder%%@char[13 10]The source code for this release will be archived to:%@char[13 10 9]%%ArchiveFolder.​

    I seem to be getting a failure to always interpret the @char functions!

    I thought - that if I have a set variable I can use a single % to indicate it, and optionally I can end it with a surrounding %, such as:

    %variable
    %variable%​

    Either is correct, so long as the interpreter can distinguish the end of the variable. If it cannot, the second % is needed to help it out, such as:

    %FirstName %LastName
    %FirstName%%LastName%​

    Because the whitespace makes it clear that %FristName is ending, no surrounding % is needed in the first example, but it is needed in the second because otherwise it would read:

    %FirstNameLastName​

    Which would not expand properly.

    I thought that the same rules apply for %@functions. I thought that this worked for years?
    But now I'm finding that %var%%@char[13 10] only sometimes works, and other times fails...

    What is the correct rule? Is this a bug in my version of TCC? Or do I just have the rules all wrong?
     
  2. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,883
    Likes Received:
    29
    Will this syntax help?
    Code:
    %[varname]
    
     
  3. samintz

    samintz Scott Mintz

    Joined:
    May 20, 2008
    Messages:
    1,188
    Likes Received:
    11
    I have gotten away from using the %var% syntax because of potential parsing issues. If there is a potential for misinterpreting the variable name I use %[var].

    BTW you can use ^n instead of @char[13 10] and ^t for @char[9]. So your above example becomes:
    Code:
    set message=The %ReleaseTitle is now official.^n^nThe master image is located at:^n^t%ReleasedMediaFolder^nThe source code for this release will be archived to:^n^t%ArchiveFolder.
    
     
  4. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,287
    Likes Received:
    39
    Functions never take a trailing percent sign. The closing right bracket is all the parser needs.
     
  5. Mordachai

    Joined:
    May 9, 2013
    Messages:
    40
    Likes Received:
    0
    Thanks all. That is a number of good options & info. :)
     
  6. JohnQSmith

    Joined:
    Jan 19, 2011
    Messages:
    564
    Likes Received:
    8
    That's great! I didn't know that. I'm going to have to start doing that; I started changing the variables in BASH scripts to ${varname} a couple of years ago.
     

Share This Page