Howdy, Stranger!

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

[Harlowe] How to make a variable name itself?

Let's say I want to create some random characters. One way to do this, in my twisted imagination, is making a $namecreate variable that creates one name, then I would make it dump that name in another variable specific for that character (let's say it created a bartender, and dumped his name to a variable with the name of the character)

Is there a way for a story to generate, or at least rename, variables along the way?

Or is there another way to create this effect for the player?

Comments

  • I believe you are asking is it possible for the Reader to enter a name (like 'bartender') and then to rename an existing variable so that it new name is the same as the name the Reader entered.

    eg. rename the $namecreate variable to now be $bartender.

    If that is the case then the simple answer is: No.

    Although you could use a (datamap:) to simulate the effect:
    (set: $npcs to (datamap: "namecreate", "Bob"))
    
    Get the Reader to enter a job name via a prompt macro, the value would need to be validated for things like space characters.
    I am cheating in this example and hard-wiring the value to bartender!
    (set: $job to "bartender")
    
    (set: $npcs to it + (datamap: $job, $npcs's namecreate))
    
    namecreate: (print: $npcs's namecreate)
    bartender: (print: $npcs's bartender)
    
    Both the namecreate and bartender properties of the $npcs Object have the same value.

    But there is a problem with what you want to do, how will you (the Author) use the $bartender variable within your story if you don't know what the variable's name is when you are writing the story!

    Instead you could just use two generic variables like $playerName and $playerJob to store the Reader's chosen name and job.
  • edited August 2016
    Yeah it's best to just use something like $playername that doesn't change and have the player input a name which then gets stored as a string ala $playername is "Joe".
Sign In or Register to comment.