Howdy, Stranger!

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

How to limit the amount of characters a user can enter

(I'm using twine 2.0, Harlowe) Basically I want users to be able to choose their own names so this code seemed like a good idea:
(set: $name to (prompt: "What's your name?"))

name: $name
the problem there is no limit to how many characters the name is (it gets messy) and I don't have the slightest idea how to do so say I want it to be a max of 16 characters without a min

Comments

  • I can't help you there, but you could use some variables after they enter the name. Like, I don't know if this would be possible, but you could do an (if:) statement, asking if $name is bigger than sixteen, and if it is, then ask them to redo it?
  • edited September 2016
    Deadshot wrote: »
    I can't help you there, but you could use some variables after they enter the name. Like, I don't know if this would be possible, but you could do an (if:) statement, asking if $name is bigger than sixteen, and if it is, then ask them to redo it?
    thought of that, didn't know how to correctly implement it, like give me an actual example
  • Khaloodxp wrote: »
    Deadshot wrote: »
    I can't help you there, but you could use some variables after they enter the name. Like, I don't know if this would be possible, but you could do an (if:) statement, asking if $name is bigger than sixteen, and if it is, then ask them to redo it?
    thought of that, didn't know how to correctly implement it, like give me an actual example

    Sorry, I dunno.
  • greyelf wrote: »
    read it don't know how to make it limit the amount of characters, right now I'm trying to work out the problem with a javascript conditional but that's not working either I'm thinking something around the lines of prompt("What is your name?"); and then I set it to a value somehow like $name and then I make an if conditional like "$name".length <= 16 or something like that
  • Deadshot wrote: »
    Read this - I think it'll help:

    http://twine2.neocities.org/#macro_number
    sadly it doesn't it will only turn numbers in a string to values (not text)
  • Khaloodxp wrote: »
    an if conditional like "$name".length <= 16 or something like that
    The String data section of the Harlowe Manual explains how to access the length of a String value.
    $name's length
    
  • greyelf wrote: »
    Khaloodxp wrote: »
    an if conditional like "$name".length <= 16 or something like that
    The String data section of the Harlowe Manual explains how to access the length of a String value.
    $name's length
    
    greyelf wrote: »
    Khaloodxp wrote: »
    an if conditional like "$name".length <= 16 or something like that
    The String data section of the Harlowe Manual explains how to access the length of a String value.
    $name's length
    

    thanks I was able to figure it out
    (set: $name to (prompt: "What's your name?"))
    (if: $name's length > 10)[(set: $name to (prompt: "Error name can't be more than 10 letters"))]
    
    it works perfectly now
  • Khaloodxp wrote: »
    greyelf wrote: »
    Khaloodxp wrote: »
    an if conditional like "$name".length <= 16 or something like that
    The String data section of the Harlowe Manual explains how to access the length of a String value.
    $name's length
    
    greyelf wrote: »
    Khaloodxp wrote: »
    an if conditional like "$name".length <= 16 or something like that
    The String data section of the Harlowe Manual explains how to access the length of a String value.
    $name's length
    

    thanks I was able to figure it out
    (set: $name to (prompt: "What's your name?"))
    (if: $name's length > 10)[(set: $name to (prompt: "Error name can't be more than 10 letters"))]
    
    it works perfectly now

    How's the game coming along?
  • it's almost done I just making simple copy pastes. appearance modifications, lag reduction, basically I am done I am just making it look cooler
  • Khaloodxp wrote: »
    it's almost done I just making simple copy pastes. appearance modifications, lag reduction, basically I am done I am just making it look cooler

    Cool
Sign In or Register to comment.