1. Download our Official Android App: Forums for Android!

Variables %SCREEN and %WIFI always SET?

Discussion in 'Android Apps & Games' started by Plecto123, May 11, 2016.

  1. Plecto123

    Plecto123 Newbie
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    20
    Joined:
    Mar 15, 2016

    Mar 15, 2016
    20
    0
    15
    Male
    How come the variables %SCREEN and %WIFI are always SET regardless of whether the screen is on/off or the wifi on/off? I've got a Huawei Honor 5x and Android 5.1.1
     

    Advertisement

  2. Thom

    Thom  
    VIP Member
    Rank:
     #22
    Points:
    1,318
    Posts:
    11,943
    Joined:
    Feb 16, 2011

    Feb 16, 2011
    11,943
    4,920
    1,318
    Male
    Software Developer
    Keene, NH USA
    Because they are variables with values. Try this ...

    what
    A1: Flash [ Text:Screen=%SCREEN
    WiFi=%WIFI Long:Off ]

    ... Thom
     
    electricpete likes this.
  3. Plecto123

    Plecto123 Newbie
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    20
    Joined:
    Mar 15, 2016

    Mar 15, 2016
    20
    0
    15
    Male
    Seems like the variables store "on" and "off", having %SCREEN eq off, and %SCREEN eq on, instead of SET/!SET worked :)
     
  4. Thom

    Thom  
    VIP Member
    Rank:
     #22
    Points:
    1,318
    Posts:
    11,943
    Joined:
    Feb 16, 2011

    Feb 16, 2011
    11,943
    4,920
    1,318
    Male
    Software Developer
    Keene, NH USA
    That is almost correct. Always set. You need to test the value.

    ... Thom
     
    #4 Thom, May 11, 2016
    Last edited: May 12, 2016
    electricpete likes this.
  5. Thom

    Thom  
    VIP Member
    Rank:
     #22
    Points:
    1,318
    Posts:
    11,943
    Joined:
    Feb 16, 2011

    Feb 16, 2011
    11,943
    4,920
    1,318
    Male
    Software Developer
    Keene, NH USA
    You need to use ...

    Test
    A1: If [ %SCREEN ~ on ]
    A2: End If

    ... and not ...

    Test
    A1: If [ %SCREEN eq on ]
    A2: End If

    ... Thom
     
  6. Plecto123

    Plecto123 Newbie
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    20
    Joined:
    Mar 15, 2016

    Mar 15, 2016
    20
    0
    15
    Male
    eq works fine for me, but whats the difference between equals and matches? Also, when is a variable !SET? When its completely empty?
     
  7. Thom

    Thom  
    VIP Member
    Rank:
     #22
    Points:
    1,318
    Posts:
    11,943
    Joined:
    Feb 16, 2011

    Feb 16, 2011
    11,943
    4,920
    1,318
    Male
    Software Developer
    Keene, NH USA
    Matches - look up pattern matching ... in this case they both work and are case sensitive.

    %SCREEN is always set to on or off. Try ...

    Task
    A1: Flash [ Text:Set Long:Off ] If [ %SCREEN Set ]
    A2: Flash [ Text:!Set Long:Off ] If [ %SCREEN !Set ]
    A3: Flash [ Text:~ on Long:Off ] If [ %SCREEN ~ on ]
    A4: Flash [ Text:eq on Long:Off ] If [ %SCREEN eq on ]
    A5: Flash [ Text:~ ON Long:Off ] If [ %SCREEN ~ ON ]
    A6: Flash [ Text:eq ON Long:Off ] If [ %SCREEN eq ON ]

    ... Thom
     
    electricpete likes this.
  8. electricpete

    electricpete Android Expert
    Rank:
     #67
    Points:
    393
    Posts:
    2,072
    Joined:
    Jan 7, 2012

    Jan 7, 2012
    2,072
    1,028
    393
    Male
    Electrical Engineer
    I use equals when comparing numbers or numerical expressions and matches when comparing strings (including pattern matching as Thom mentioned)

    Built in variables are always set.
    User variables are set at the time you assign thenm a value. (I'm not sure if there's a way to create an uninitialzed variable except perhaps to reference a variable name that hasn't been assigned a value... never comes up in anything I do. I'm sure it has some purpose for advanced users, but not for me and I'd venture to say not for most beginner/intermediate tasker users.

    So in summary the variables I work with are always set and I don't ever find a need to test if a variable is set... test the value with eq or matches instead.
     
    #8 electricpete, May 12, 2016
    Last edited: May 12, 2016
    Thom likes this.

Share This Page

Loading...