0 votes
asked ago by (490 points)

I'm going to say this upfront; the coding throwing this error probably shouldn't be throwing the aforementioned error, and it's concerning me that it is.

Here is the coding I use for my load game:

{(link-reveal: "Load a Saved Crawl")[
	(set: _saves to (saved-games:))
	(if: _saves's length < 1)[
		You don't have any saved games.]\
	(if: _saves's length > 0)[
		(for: each _name, ...(datanames: _saves))[
		<br>
			(print: 
				"(link: 'Load Crawl: " + (_saves's (_name)) + "')[" +
					"(load-game: '" + _name + "')" +		
				"]"
			)
		]
	]
]}

For some reason, my attempts at checking for the _save's length (to make sure that there is a save file to be accessed) always throws this error: 

I can't find a 'length' data name in a datamapâ–șI tried to access a value in a string/array/datamap, but I couldn't find it.

 

This is highly frustrating, because it results in both the "You don't have any saved games." error message and my saved game for 'Goethi', my test character.

1 Answer

+1 vote
answered ago by (137k points)
selected ago by
 
Best answer

The String and Array data types have both have a length property because they both contain a sequence of values, in the case of a String those values are Characters, and the length peoperty is used to determine how long that sequence is.

The Datamap data type is a collection of name & value pairs. To determine how many pairs are in the collection you would generally count the names, and the simplest way to do that is to first use the (datanames:) to obtain an Array of names which you can then get the length of.

(set: _saves to (saved-games:))
(set: _names to (datanames: _saves))
count: (print: _names's length)


So knowing the above information your example would look more like.

{(link-reveal: "Load a Saved Crawl")[
	(set: _saves to (datanames: (saved-games:)))
	(if: _saves's length is 0)[
		You don't have any saved games.]\
	(else:)[
		(for: each _name, ..._saves)[
			<br>
			(print: 
				"(link: 'Load Crawl: " + _name + "')[" +
					"(load-game: '" + _name + "')" +		
				"]"
			)
		]
	]
]}

 

Welcome to Twine Q&A, where you can ask questions and receive answers from other members of the community.

You can also find hints and information on Twine on the official wiki and the old forums archive.

See a spam question? Flag it instead of downvoting. A question flagged enough times will automatically be hidden while moderators review it.
...