Howdy, Stranger!

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

Dynamic Creation of a Variable Name in Harlowe?

edited December 2016 in Help! with 2.0
I'm creating Roman names at random as needed to create characters in my experimental interactive historical text Path of Honors (philome.la/gamingthepast
For reasons that I've sort of forgotten, I have five arrays each of 10 strings that are plebeian family names called $plebNomen1, $plebNomen2, $plebNomen3, $plebNomen4, and $plebNomen5.

Is there a way in Harlow to randomly choose one of these lists to draw from using dynamic naming instead of using a cumbersome set of conditionals? So is something like this possible:

1. Create a random number from 1 to 5 and store it in an variable, call it $index for sake of argument
2. Concatenate the "$" + "plebNomen" + $index and use the whole thing as the variable name "$plebNomen1" , $plebNomen2" and so on?

I should add that what I need at the moment is to generate syntax like this (if it can be done):
$plebNomenList1's $index
So I can pick a random element within one of the $pleNomen list arrays

Thanks!!!

Comments

  • You could dynamically create a String value containing the variable name, the post-fix number and the 's ($index) element reference, and then use a (print:) macro to dynamically convert that String value into actual code but I believe there is a better way.

    Convert your five $plebNomenX variables into a hierarchical array which is a parent outer array that contains inner child arrays.

    In your case you could have a five element $plebNomen outer array, and each of those elements would be the contents of your five $plebNomenX arrays.
    (set: $plebNomen to (a:
    	(a: "First name in plebNomen1", "Second", "Third", "Etc.."),
    	(a: "First name in plebNomen2", "Second", "Third", "Etc.."),
    	(a: "First name in plebNomen3", "Second", "Third", "Etc.."),
    	(a: "First name in plebNomen4", "Second", "Third", "Etc.."),
    	(a: "First name in plebNomen5", "Second", "Third", "Etc..")
    ))
    
    (set: $outerIndex to 2)
    (set: $innerIndex to 1)
    
    Item 2,1: (print: $plebNomen's ($outerIndex)'s ($innerIndex))
    
Sign In or Register to comment.