Profile image

What's Wrong With My Text?

1,338 CookieFlightSystems  2.6 years ago

I have this chunk of code in a label

{TargetDistance>0 ? "<size=80%>Target Dist: {TargetDistance;000000}m": ""}

{TargetDistance>0 ? "<size=80%>Target Speed Rel: {rate(TargetDistance);000000}m/s": ""}

In order to tell me the distance and relative speed to a target, and I only want it to turn on when a target is detected (not locked in terms of a missile, just targeted). But instead of only showing the string, the label shows the entire code. It does this in flight too, not just in the editor.

Example below:
https://i.postimg.cc/mk3HfrLc/image.png

  • Log in to leave a comment
  • Profile image

    @ZeroWithSlashedO @DeveloperKorzalerke
    Finally found a solution

    <size=80%>{ TargetDistance>0 ? "<alpha=#FF>" : "<alpha=#00>" }Target Dist: <pos=60%>{TargetDistance;000000}<pos=86%> m
    { TargetDistance>0 ? "<alpha=#FF>" : "<alpha=#00>" }Target Speed Rel: <pos=60%>{rate(TargetDistance);00000.0}<pos=86%> m/s

    This sets the transparency of text after the if statement to zero if there is no target, if there is a target, the transparency is set to on

    2.4 years ago
  • Profile image

    @CookieFlightSystems
    Try giving a space after the quotation marks behind "Dist" and "Rel"
    Like, "Target Speed Rel:" rate(TargetDistance);000000"m/s", if that doesn't work, try putting "()" in the codes
    like (rate(TargetDistance);000000)"m/s"

    2.6 years ago
  • Profile image

    @ZeroWithSlashedO
    <size=80%>
    {TargetDistance>0 ? "Target Dist:" TargetDistance;000000"m" : "a"}

    {TargetDistance>0 ? "Target Speed Rel:"rate(TargetDistance);000000"m/s" : "a"}

    Still displays nothing, Debug Expression TargetDistance>0 is true, yet no text is displayed

    2.6 years ago
  • Profile image

    @ZeroWithSlashedO Yes, I have tried selecting targets, and also locking on with a missile. Neither works. I suppose in flight I could do "DebugExpression TargetDistance>0" or something like that to see what the code is reading.

    2.6 years ago
  • Profile image

    @CookieFlightSystems
    Wait...
    Have you selected a target during testing to see if it works?
    If the input is "false", then it's not going to show anything. I suggest adding "a" in the "false" statement to see if the code really works or no.

    2.6 years ago
  • Profile image

    @CookieFlightSystems
    Dunno. Have to try that out.

    2.6 years ago
  • Profile image

    @ZeroWithSlashedO Not sure, I literally copy/pasted what you suggested. So I have no idea what could be wrong.

    If you do the same (enter the code into a plane of yours), I wonder if it might work?

    2.6 years ago
  • Profile image

    @CookieFlightSystems
    Then something is wrong with your code. Idk what's wrong, but something is definitely wrong.

    2.6 years ago
  • Profile image

    @ZeroWithSlashedO Got a chance to test this. Now instead of displaying the full code on the label, it now shows nothing. No matter what the TargetDistance>0 is set to to make it true always (such as Fuel>0 )

    2.6 years ago
  • Profile image

    @DeveloperKorzalerke Before, the label did not have the “if” statement involved. I added that into my label. I believe the comment from ZeroWithSlashedO should work as intended - as soon as I get to my computer and able to test it.

    2.6 years ago
  • Profile image

    I already saw what's wrong as soon as I saw the code.
    Correction (?):

    <size=80%>
    {TargetDistance>0 ? "Target Dist:" TargetDistance;000000"m" : ""}

    {TargetDistance>0 ? "Target Speed Rel:"rate(TargetDistance);000000"m/s" : ""}

    Note:
    Don't put another "{" after one is already there, the quotation marks works to mark whether if it's a text or no, if no, it'll work as a normal input, therefore if you end the quote before putting the code, it should work.
    Tell me the results.
    Oh and also, since there's already a <size=--%>, you don't need to put another one because it'll stay that size until you change it again.

    2.6 years ago
  • Profile image
    11.6k JesusChrist

    @CookieFlightSystems So the code worked fine before you changed it? Weird, did you change anything else other than the variable before the zeroes?

    2.6 years ago
  • Profile image

    @DeveloperKorzalerke
    <size=80%>Target Dist: {TargetDistance;000000}m
    Should display the text "Target Dist:" followed by the target distance to 6 digits, then finally "m" as meters. All formatted to 80% size
    I basically just copy pasted if from one of the other labels in a stock plane, then changed the variable to TargetDistance

    2.6 years ago
  • Profile image
    11.6k JesusChrist

    Might be the code inside the double quotes, labels don't like mixed ft and text much.

    2.6 years ago
  • Profile image

    @HuskyDynamics01 I tried adding (TargetDistace>0) and that didn't seem to change anything. I don't think the two quotation marks at the end need a space between them because other label formats in the cockpit don't have it, but next time I'm on, I will try that.

    2.6 years ago
  • Profile image

    Usually if it shows the entire code, you're missing a parenthesis or </> or bracket or something somewhere. The only thing I can see is either put parentheses around TargetDistance>0 (I've had a few issues where the line before the ? only worked if in parentheses), or add a space between the two quotation marks at the end.

    2.6 years ago