Howdy, Stranger!

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

'string is not a function'

Getting this error likely because I've formatted the conditional check incorrectly. I'm checking to see if the last page visited was 'leave'. If so, show Text, otherwise, show Other text. What's the correct syntax?

This is currently incorrect:
<% if (story.checkpointName() == 'leave'){ %>
Text
<% } else { %>
Other text
<% } %>

So would it be:
<% if (story.checkpointName('leave')){ %>
Text
<% } else { %>
Other text
<% } %>

Or:
<% if (Story.checkpointName('leave')){ %>
Text
<% } else { %>
Other text
<% } %>

Or something entirely different? I'm stumped even after browsing the commented source.

Comments

  • Next time, include the header you're using. Took me a while to find the documentation.

    To answer the question, neither. checkpointName is not a function but a property of the type string - as your error message suggests - so you don't call curly brackets. What you wanna do is:
    (story.checkpointName == 'leave')
    
  • edited October 2016
    Must be a problem with my adblocker or something, as I did in fact tag this as snowman when I submitted...I'll be sure to include in the title then next time.

    Anyway, thanks for the clarification, looking at the comments I do in fact see that it's a string. Makes a lot more sense to me now, however the expressions themselves aren't executing. You mentioned not needing curlies? How then would I format a conditional statement if not using the above structure? I'm very new at this, and I've been using the above conditional format based on this question.

    Thanks for looking at this.

    EDIT: Looks like I still have work to do. I read up on setting the checkpoint as it needs to be done manually, works out now. Still, could you clarify what you meant by not needing curlies?
  • EnMod wrote: »
    Still, could you clarify what you meant by not needing curlies?
    MoLoLu will undoubtedly correct me if I'm wrong. I believe they meant that you do not need the function/method call parentheticals. Essentially, their use of "curly brackets" here was simply a wording snafu.
  • edited October 2016
    I meant parenthesis like Exile says (and no, no more corrections - I've screwed up enough of those today)

    Stupidly complex explanation: { and ( and [ look way too similar when you're tired and have been staring at code too long. So my internal monologue is associating everything bracket-y with the phrase 'curly brackets' and relying on the editor to tell me which ones are which. I forgot they have a real name.
  • MoLoLu wrote: »
    I meant parenthesis like Exile says (and no, no more corrections - I've screwed up enough of those today)

    Stupidly complex explanation: { and ( and [ look way too similar when you're tired and have been staring at code too long. So my internal monologue is associating everything bracket-y with the phrase 'curly brackets' and relying on the editor to tell me which ones are which. I forgot they have a real name.

    Happens to the best of us lol. Thanks so much for your help, both of you.

Sign In or Register to comment.