Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Is there a way to determine the 1st character of a variable's output?

Kind of an awkward phrasing, I know.

Here is what I want to do:
I have $variable (which, if it helps, is set to a numerical character.) and I want to make several (if:)'s that link to different passages depending on the first character of the variable.
What I have been TRYING to do, which hasn't been working is
(if: $variable's 1st is 1)[(go-to:"PASSAGE1")](else-if:$variable's 1st is 2)[(go-to:"PASSAGE2")]
, etc, etc
I have also tried
(if: 1st of $variable is 1)[(go-to:"PASSAGE1")]

I could set up an individual (if:$variable is 10) (if:$variable is 11) etc but I have...a lot of numbers there.

Is there any way that I can do this without resorting to making an (if:) for every number?
Thanks

Comments

  • I was talking with a friend, and another possible solution to this would be to make a SEPARATE value for what I am trying to do with the first number. So it would be something like
    (if:$category is one)[(go-to:"PASSAGE1")]
    
    And then use $variable (minus the first number) to do the same thing I was using it for
  • edited August 2016
    I am going to assume that when you say "set to a numerical character" you mean that the variable contains a String value that consists of one or more numerical characters like 1,2,3,etc..

    Each character within a String value is also a String value, so you need to use a String value in your comparisons.
    Set the variable to a String containing numerical characters.
    
    (set: $var to "12345")\
    var: $var
    
    (if: $var's 1st is "1")[1 is the first character in the String]
    
    (if: not ($var's 3rd is "2"))[2 is not the third character in the String, it is (print: $var's 3rd)]
    
  • edited August 2016
    That sequence worked in and of itself; I think my main issue is that my variable isn't set to a string, it is set to a number

    ie the difference between
    (set:$var to "1") and (set:$var to 1)
    

    The latter is an actual number while the former is a string.

    So tl;dr I am an idiot thank you greyelf
  • edited August 2016
    In that case if you can still check the digits of an actual number like so: *smile*
    Set the variable to a multi digit number.
    
    (set: $var to 12345)\
    var: $var
    
    (if: (text: $var)'s 3rd is "3")[3 is the third digit in the number]
    
  • All hail greyelf thank you very much!!! This means I get to keep my heap of code without having to edit in little quotation marks. *heart eyes* I greatly appreciate it!!!
Sign In or Register to comment.