Check if var is enpty



  • Hi

    Is it possible to check if an <VAR> is empty?
    If it is empty = do nothing
    If it contains an string = CAPTURE

    best regards
    Providers


  • Admin

    What do you mean by "empty"? Is the variable created with an empty value?
    If it's created, just do
    "<VAR>" EqualTo ""
    If it's not created you can do
    "<VAR>" DoesNotExist



  • Sorry, I do not understand.

    #FUNCTION_Convert_HTML_SUB2 FUNCTION HTMLEntityDecode "<SUB2>" -> CAP "Subscription"
    if the <SUB2> does not contain anything, then I dont want it to be captured at all

    Right now it will capture following:
    Parsed variable | Name: Subscription | Value: <SUB2>


  • Admin

    Switch to loliscript view and then write this

    IF "<SUB2>" Exists
    #FUNCTION_Convert_HTML_SUB2 FUNCTION HTMLEntityDecode "<SUB2>" -> CAP "Subscription"
    ENDIF
    


  • I do not know if its an bug, but if you parse something into a variable then it always exists,
    If it doesent get any data into it it then fills itself with its onw name

    Examble:
    #PARSE_Subscription_2 PARSE "<SOURCE>" CSS "#subscription-section > div.overview-widget__column.overview-widget__content > div.widget-title" "innerHTML" -> VAR "SUB2"

    If nothing is found then
    <SUB2> = <SUB2>
    (Shouldent it have been <SUB2> = ""



  • Hi
    If my variables <1> - <2> - <3> - <4> - <5> - <6> are empty, then <LIST> = "<1> - <2> - <3> - <4> - <5> - <6>" (as a string)
    Therefor I need to test if it is "<1> - <2> - <3> - <4> - <5> - <6>"

    How to do that, it teats it as 6 varibles
    I want to achive true

    -----Code-----

    FUNCTION Constant "<1> - <2> - <3> - <4> - <5> - <6>" -> VAR "LIST"

    PRINT <LIST>

    IF "<LIST>" EqualTo ""<1> - <2> - <3> - <4> - <5> - <6>""
    PRINT "true"
    ELSE
    PRINT "fALSE"
    ENDIF

    -----debug---------

    Executed function Constant on input <1> - <2> - <3> - <4> - <5> - <6> with outcome <1> - <2> - <3> - <4> - <5> - <6>
    Parsed variable | Name: LIST | Value: <1> - <2> - <3> - <4> - <5> - <6>

    <1> - <2> - <3> - <4> - <5> - <6>
    Jumping to line 45
    "false"


  • Admin

    I already told you, to check if any variable replacement happened in a string, you need to use the Exists condition.
    If the variable was created but it's empty (so it gets replaced with an empty string) you use EqualTo "".
    Also in this case you might wanna look into parse block => Create Empty which ALWAYS creates a variable, but if it couldnt parse anything it will create an empty one instead of not creating it at all.



  • Im sorry,
    But I cant make it work, can you maybe help me change the code above?

    The variable <LIST> are always created
    There are always something in the varible, no matter if I put anything into it, That is the problem
    If I do not add anything to it, then it contains <1> - <2> - <3> - <4> - <5> - <6> as text

    I do not know hot to check for this text as it would treat it as 6 varibles

    If <1> - <2> - <3> - <4> - <5> - <6> are found then <LIST> = Fighting - Golf - Serier - Sport - Film - Kanaler
    Or Simalar



  • quick fix for the current thing:
    make sure CreateEmpty is checked on creation of <1> to <6>

    so in your expample if <2> is empty it would be
    Fighting - - Serier - Sport - Film - Kanaler

    (and then maybe translate - - with -)



  • Got it now, thanks for your all your pataince (hopefully I can one day start helping others)

    Solution.
    Under "PARSE" make sure not to tick on "Create Empty"
    This way the variable is not created if its empty

    Now its possible to check if it exists

    IF "<VAR>" Exists
    ## COMMANDS TO BE EXECUTED ON TRUE CONDITION
    ELSE
    ## COMMANDS TO BE EXECUTED ON FALSE CONDITION
    ENDIF
    

Log in to reply