Profile image

[solved!] How to check if a variable has a value? (Funky Trees)

135 VeirwenBlitzzSP  8 months ago

I'm trying to make a code that checks if a value like SelectedWeapon has a loaded input, and then return a result. Ive tried SelectedWeapon ? SelectedWeapon : none (and SelectedWeapon == true ? SelectedWeapon : none too, just in case) but none of them seem to work, any help perhaps?

good day

edit//PS.: none is typed between quotation marks ( "none" ), forum just doesn't like when i type " in a code format

  • Log in to leave a comment
  • Profile image
    13.1k Grob0s0VBRa

    Ah, so it is for a label part.
    Well.
    Try this:

    {SelectedWeapon= "name" ? "name" : "none" }

    If you need the selected weapon's name to show up upon selection just add it after the question symbol.
    If it is not selected the output would be none.
    In case of multiple weapons duplicate the code like this

    {SelectedWeapon= "name1" ? "name1" : (SelectedWeapon= "name2" ? "name2" : (SelectedWeapon= "name3" ? "name3" : "none") ) }

    Pinned 8 months ago
  • Profile image

    @Grob0s0VBRa not too tidy in code but this solves the issue, thanks a bunch!

    +1 8 months ago
  • Profile image

    @Grob0s0VBRa i've tried adding clamp01(SelectedWeapon!=0) this way:
    !code screenshot
    it DOES return the if_true statement, but the if_false doesn't
    !screenshot of true value
    !screenshot of false value

    8 months ago
  • Profile image

    @Grob0s0VBRa I'll try this one, will reply later if it works or not

    8 months ago
  • Profile image

    @PlaneFlightX i just realized the forum didnt like me using quotation marks (") in code format

    i'm trying to make a conditional that checks if the value SelectedWeapon has anything selected, such as Rocket Pods or Missiles, then return the name of the weapon IF it has one, or return the text none IF it hasn't, apologies for the formatting issue

    8 months ago
  • Profile image
    13.1k Grob0s0VBRa

    Em
    clamp01(SelectedWeapon!=0)
    Just add this bit as a multiplier.
    Thing under the clamp can be: equal to, not equal to, more than, less than 0 or any other specific value,

    8 months ago
  • Profile image
    46.6k PlaneFlightX

    I'm not sure what you're trying to do, but SelectedWeapon is not a Boolean. You need a Boolean value to use a tertiary selector. Additionally, the second code has invalid syntax.

    What is the original goal you are trying to accomplish?

    8 months ago