Howdy, Stranger!

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

Is it possible to concatenate code?

Hi! Im trying to make an inventory

The idea was to store the stuff in a datamap and display only the names of the datamap but using for each name a link-reveal that displays the values of the names

To do that I was trying to make a live macro that incremenets an index variable and then shows the link reveal for the object of the index, but the live macro overwrites it when the index is changed!

So what Is that maybe somehow i can concatenate code on each loop of the live so I can display the dataset as I want and its not overwrited

Thanks!

Comments

  • You need to state which Story Format you are using when you ask a question, as answers can be different for each one. Based on the macros you named in your question I am going to assume you are using Harlowe.

    One way to do what you want is to use a named hook to indicate where you would like the output of you dynamic code to be placed, then you can use either the (replace: ) macro or the (append: ) macro to target that named hook.

    1. The basis of the logic part of your code would look something like the following
    {(set: $inventory to (datamap: "sword", 1, "food", 3, "rocks", 2))
    
    }You are carrying: []<list|
    
    (set: $names to (datanames: $inventory))
    (set: $length to $names's length)
    (if: $length is 0)[
    	(replace: ?list)[nothing]
    ]
    (else:)[
    	(set: $index to 1)
    	(set: $key to $names's ($index))
    	(replace: ?list)[
    		*** Dynamic Code to output the link-reveal goes here ***
    	}]
    
    	(if: $index < $length)[
    		(live: 10ms)[
    			(if: $index >= $length)[
    				(stop:)
    			] (else:)[
    				(set: $index to it + 1)
    				(set: $key to $names's ($index))
    				(append: ?list)[
    					*** Dynamic Code to output the link-reveal goes here ***
    				}]
    			]
    		]
    	]
    ]
    
    note: I added indentation and extra line-breaks to the above example, most of it can be removed except for the first line-break within each (replace:) and (append:) macro's associated hook because those are needed to format the list so that each item appears on its own line.

    2. The Dynamic Code to output the link-reveal.
    You can use the (print:) macro to convert text contained within a String value into macro code. You will need to use the (text:) macro to convert the value stored in the $inventory database into a String value so that it can be concatenated to the String value being passed to the (print:) macro.
    (print: "(link-reveal: '" + $key + "')[: " + (text: $inventory's ($key)) + "]")
    
  • Many thanks!!! :)
Sign In or Register to comment.