-
-
Notifications
You must be signed in to change notification settings - Fork 23
Open
Description
Hey again,
I'm working on saving/restoring progress using a snapshot from a file and having a little trouble. When I restore I can get the choices, but not the line.
This is using the c_lib version of inkcpp.
Saving:
snapshot = ink_runner_create_snapshot(runner);
ink_snapshot_write_to_file(snapshot, "snapshot.bin");
Restoring:
snapshot = ink_snapshot_from_file("snapshot.bin");
runner = ink_story_new_runner_from_snapshot(story, snapshot, null, 0)
ink_runner_get_line(runner); // empty line
If I inspect the snapshot file I see both the current line and the choices.
I tried reading/writing using the binary directly as well.
My game is written in Jai but here's a C test program I cobbled together to make sure it wasn't my bindings.
#include <stdio.h>
#include <stdlib.h>
#include "inkcpp.h"
#define RW_BINARY 0
int main() {
HInkStory *story = ink_story_from_file("crime_scene.bin");
HInkRunner *runner = ink_story_new_runner(story, NULL);
const char *line = ink_runner_get_line(runner);
printf("LINE: %s", line);
HInkSnapshot *snapshot = ink_runner_create_snapshot(runner);
#if RW_BINARY
size_t length;
const unsigned char *data = malloc(sizeof(unsigned char) * 5000);
ink_snapshot_get_binary(snapshot, &data, &length);
FILE *fp = fopen("snapshot.bin", "wb");
fwrite(data, sizeof(unsigned char), length, fp);
fclose(fp);
free(data);
fp = fopen("snapshot.bin", "rb");
fseek(fp, 0, SEEK_END);
long fileSize = ftell(fp);
rewind(fp);
data = (unsigned char *)malloc(fileSize);
fread(data, 1, fileSize, fp);
fclose(fp);
// for (int i = 0; i < fileSize; ++i)
// printf("%c", data[i]);
// printf("\n");
snapshot = ink_snapshot_from_binary(data, fileSize, true);
#else
ink_snapshot_write_to_file(snapshot, "snapshot.bin");
snapshot = ink_snapshot_from_file("snapshot.bin");
#endif
runner = ink_story_new_runner_from_snapshot(story, snapshot, NULL, 0);
line = ink_runner_get_line(runner);
printf("LINE: %s\n", line);
for (int i = 0; i < ink_runner_num_choices(runner); ++i) {
HInkChoice *choice = ink_runner_get_choice(runner, i);
printf("%s\n", ink_choice_text(choice));
}
system("pause");
return 0;
}
I included the story example I compiled, just change to .bin.
crime_scene.txt
Thanks for any help on this :)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels