-
-
Notifications
You must be signed in to change notification settings - Fork 21
Open
Labels
inactiveAn issue where currently no work is done. Typically because a replay is missing.An issue where currently no work is done. Typically because a replay is missing.
Description
I hope the code is self-explanatory. If not, you gladly could ask me.
(Its inkcpp implemented in a not-so-well-known Game Engine)
#include <ink/story.h>
#include <ink/runner.h>
#include <ink/choice.h>
#include <iostream>
using namespace ink::runtime;
Init() {
//// Load ink binary story, generated from the inkCPP compiler
story* myStory = story::from_file("test2.bin");
runner thread = myStory->new_runner();
while (thread->can_continue())
{
rLine = thread->getall(); // --> Attention: Here 'thread->getline()' and 'getall()' works.
Log::message("Start -> %s \n", rLine.c_str());
}
if (thread->has_choices()) {
Log::message("=== CHOICES ===\n");
int lineCount = 0;
for (const choice& c : *thread) {
Log::message("%d: %s\n", lineCount, c.text());
lineCount++;
}
rLine = thread->getline();
Log::message("68: getLine() - : %s \n", rLine.c_str());
Log::message("=== MAKING CHOICE 1 ===\n");
const choice* choice0 = thread->get_choice(1); // -> tried this for debugging. Passes/Compiles.
Log::message("choice -> %s \n", choice0->text());
thread->choose(0); // Not ANY story text after this line ("thread->choose(0) or thread->choose(1) ;")
//rLine = thread->getline(); // --> when enabled, causes runtime exception...
Log::message("68: getLine() - : %s \n", rLine.c_str());
auto choice1 = thread->begin(); // -> ... a debug test.
auto choice2 = thread->end(); // -> ...another debug test.
Log::message("79: choice1 -> %s \n", choice1->text());
Log::message("80: choice2 -> %s \n", choice2->text());
}
if (!thread->can_continue()) {
Log::message("Warning: thread cannot continue.\n"); // --> Doesn't trigger! So 'canContinue()' is true.
return 1;
}
//if (thread->can_continue() && thread.is_valid()) --> Does pass, but...
//{
// rLine = thread->getall(); // --> ...STILL GETS A RUNTIME ERROR HERE!!
// Log::message("getLine() - 3 - : %s \n", rLine.c_str());
//}
// Debug story state after choice
Log::message("After choice - can_continue: %s\n", thread->can_continue() ? "true" : "false"); // prints "true"
Log::message("After choice - has_choices: %s\n", thread->has_choices() ? "true" : "false"); // prints "false"
if (thread->can_continue() && thread.is_valid()) { // Does pass...
try {
Log::message("trying getLine...\n"); // still prints to console
rLine = thread->getline(); // --> another RUNTIME exception here... --> Attention: Here 'thread->getline()' dOESN't work!
}
catch (const std::exception& e) { // --> DOESN't catch...
Log::message("catching exception...\n"); // --> doesn't print...
if (std::string(e.what()).find("divert") != std::string::npos ||
std::string(e.what()).find("knot") != std::string::npos) {
Log::message("story ended on first - stop\n");
}
if (std::string(e.what()).find("divert value") != std::string::npos)
{
Log::message("story ended - on second stop");
break;
}
throw; // real error – propagate. --> It seems the Code doesn't get here... Not sure...
}
Log::message("End Line called: %s\n", rLine.c_str()); // Doesn't get called anymore if Runtime exception.
// If I out-commented the lines, it prints, but it's empty...
}
return 1;
}Also, I don't get any text printed after I select a choice via thread->choose(0);. Nothing happens...
Can you help me here? That would be very appreciated.
Here is the test.ink that I compiled in test.bin, if this helps:
> Once upon a time.
> In another time.
>
> * There is the first choice.
> Indeed, the first choice.
> ** and another choice.
> ->targetKnotName
>
> * There is a second choice.
> - Of course, there is a second choice.
> ** to try the same targetKnot...
> -> targetKnotName
>
> - They lived happily ever after.
> -> DONE
>
> === targetKnotName ===
> This is the content of the knot.
> Yeah, this knot.
> - and that's it...
> -> endOfStory
>
> === endOfStory ===
> There it ends.
> Really.
> -> DONE
Addendum: rLine is --> std::string rLine And before I tried const char* rLine. The same errors appear in any case.
Metadata
Metadata
Assignees
Labels
inactiveAn issue where currently no work is done. Typically because a replay is missing.An issue where currently no work is done. Typically because a replay is missing.