0 votes
by (200 points)
edited by

Format: Harlowe 2.1

Code:
 

{
	(set: _racenames to (datanames: $races))
    (set: $validrace to (a:))
	(for: each _i, ..._racenames)[
		(if: $races's (_i)'s level <= 6)[
			(link: _i)[
				(set: 
					$char's baserace to (_i); 
					$charrace to (_i)
				)
				(go-to: "Race Choice")
			](print: "  ")
		]
	]
}

I am making a script to help me to allow people to test campaigns I design before they purchase them.

The script above is supposed to set the race variables, and the info is displayed in a separate footer page.

$races is a datamap, declared at story start
$char is a datamap, declared at stat selection
$char's baserace is an entry in the datama
$charrace is a variable declared at stat selection, set to a default value

The script displays the options appropriatly as links, but when I click on them, it doesn't update the variables.

The go-to as the passage call to itself, which allows players to make a different selection if they made a mistake.

Any help is appreciated. Thank you

 

1 Answer

+1 vote
by (23.6k points)
selected by
 
Best answer

Take a look at the answer given by @greyelf here.

by (200 points)

Managed to get it working.

{
	(for: each _i, ...(datanames: $races))[
		(if: $races's (_i)'s level <= 6)[
			(print:
				"(link: _i)[
					(set: 
						$char's baserace to '" + (text: _i) + "',
						$charrace to '" + (text: _i) + "'
					)
					(go-to: 'Race Choice')
				]    "
			)
		]
	]
}


For anyone else who has the same trouble, there are two main things to remember.

1: Encapsulate the entire link in a Print command using quotes around everything. This forces the program to consider it a single line. If you don't, the _i variable is actually not passed down passed the set portion. You will get an error that _i does not exist

2: After the initial (link: _i), any other references to _i need to be replaces by '" + (text: _i ) + "'
This forces the _i variable to be read at that instant and used, and the quotes and + will ensure that (test: _i) is ran properly

...