Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditional diverts are not properly handled with whitespace #71

Closed
Chaosed0 opened this issue Dec 21, 2023 · 4 comments
Closed

Conditional diverts are not properly handled with whitespace #71

Chaosed0 opened this issue Dec 21, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@Chaosed0
Copy link

Chaosed0 commented Dec 21, 2023

When running the following ink, "This displays first" is not displayed:

 Here is some test text
 
 - (opts)
 
 + [Continue]
 
 {opts == 1: This displays first}
 
 {opts < 2:  -> opts}
 
 - This is the continuation.
 
 * [OK]
 
 -> DONE

However, if you remove the space in the line {opts < 2: -> opts} between the colon and the divert arrow, then it displays correctly.

EDIT: I've been debugging this and I think it has to do with the order of the enum values in ink::runtime::internal::value_type. value_type::value_pointer and value_type::marker have the same value. Unfortunately, I'm not well versed enough in C++ to tell what the real solution should be. If I can get a little guidance I could probably submit a PR.

@Chaosed0
Copy link
Author

I'm almost certain there is something buggy with this code, but it fixes it for me:

diff --git a/inkcpp/output.cpp b/inkcpp/output.cpp
index 09075bf..1985b88 100644
--- a/inkcpp/output.cpp
+++ b/inkcpp/output.cpp
@@ -119,6 +119,11 @@ void basic_stream::copy_string(const char* str, size_t& dataIter, T& output)
 #ifdef INK_ENABLE_STL
 std::string basic_stream::get()
 {
+	if (saved())
+	{
+		forget();
+	}
+
 	size_t start = find_start();
 
 	// Move up from marker
diff --git a/inkcpp/value.cpp b/inkcpp/value.cpp
index ec2fc0c..1caad50 100644
--- a/inkcpp/value.cpp
+++ b/inkcpp/value.cpp
@@ -104,7 +104,7 @@ namespace ink::runtime::internal
 #ifdef INK_ENABLE_STL
 	template<value_type ty = value_type::PRINT_BEGIN>
 	void append(std::ostream& os, const value& val, const list_table* lists) {
-		if constexpr (ty != value_type::PRINT_END) {
+		if constexpr (ty != value_type::value_pointer) {
 			if (ty == val.type()) {
 				os << val.get<ty>();
 			} else {
diff --git a/inkcpp/value.h b/inkcpp/value.h
index e2bc97f..1565c4f 100644
--- a/inkcpp/value.h
+++ b/inkcpp/value.h
@@ -35,8 +35,8 @@ namespace ink::runtime::internal {
 		list_flag,					// a single list flag
 		string,                     // Pointer to string
 		OP_END,                     // END of types where we can operate on
-		value_pointer,				// a pointer to an value
 		newline = OP_END,           // newline symbol
+		value_pointer,				// a pointer to an value
 		PRINT_END,                  // END of printable values
 		marker = PRINT_END,         // special marker (used in output stream)
 		glue,                       // glue symbol

@JBenda
Copy link
Owner

JBenda commented Dec 21, 2023

At first: thank you for figuring that out

The problem you identified sounds reasonable.
I will take a look at your change :+1

@JBenda JBenda added the bug Something isn't working label Dec 21, 2023
@JBenda
Copy link
Owner

JBenda commented Dec 21, 2023

Yeah the double ID was not god ^^ but the problem was primarily that the output stream was not forget correctly
Thanks for pointing it out, and for doing some digging, saved me a lot of time.

JBenda added a commit that referenced this issue Dec 30, 2023
As mentioned in #71 the output can sometimes in a saved state when
finishing the line. Since the save state is necessary for to re-role the
state in a case of a glue. It should not prevent the output from
printing in its current state.
@JBenda
Copy link
Owner

JBenda commented Dec 30, 2023

Solved in #72

@JBenda JBenda closed this as completed Dec 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants