Blade Ink Python provides bindings for the Inkle's Ink, a scripting language for writing interactive narratives.
bladeink is fully compatible with the reference version and supports all its language features.
To learn more about the Ink language, you can check the official documentation.
Here is a quick example that uses basic features to play an Ink story using the bladeink crate.
# Story is the entry point of the `bladeink` lib.
story = Story.from_file("inkfiles/TheIntercept.ink.json")
self.assertTrue(story.can_continue())
end = False
while not end:
while story.can_continue():
line = story.cont()
print(line)
# Obtain and print choices
choices = story.get_current_choices()
print(f"Num. choices: {choices.len()}\n")
if choices.len() != 0:
for i in range(choices.len()):
text = choices.get_text(i)
print(f"{i + 1}. {text}")
# read_input() is a method that you should implement
# to get the choice selected by the user.
choice_idx = read_input()
# set the option selected by the user
story.choose_choice_index(choice_idx)
else:
end = True
print("Story ended ok.")We can execute Python tests in the tests folder using the next command:
$ python -m unittest -v tests/story_tests.py