(set: $word to "")
(set: $tempWord to "")
(set: $testVal to 10)
(set: $tempString to "")
(set: $tempCode to 0)
<script>
// Script to convert an Inform file saved as text to a Twine variable
// Get the data and format it for reading
$tempWord = localStorage.getItem("content:data::TextOnlyFile"); //Replace "TextOnlyFile" with the Inform name you're using
$tempWord = $tempWord.substring(1, $tempWord.length-1); // Eliminate the brackets around the data
$testVal = $tempWord.indexOf(",10,"); // Find the newline character
$tempWord = $tempWord.substring($testVal + 4); // Trim to the data after the newline
$tempWord += ","; //Add a comma at the end to include the last ASCII code
// Find the initial comma
$testVal = $tempWord.indexOf(",");
// Parse each ASCII code separated by a comma
while ($testVal > 0)
{
$tempString = $tempWord.substring(0,$testVal);
$tempCode = Number($tempString);
$word += String.fromCharCode($tempCode);
$tempWord = $tempWord.substring($testVal+1);
$testVal = $tempWord.indexOf(",");
}
</script>
(goto: "First passage")(if: $word is "")[There is no saved text.]
(else:)[The word is $word.]