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

var_val bugfix #72425

Merged
merged 11 commits into from
Mar 24, 2024
Merged

var_val bugfix #72425

merged 11 commits into from
Mar 24, 2024

Conversation

PipeYume
Copy link
Contributor

@PipeYume PipeYume commented Mar 16, 2024

Summary

Bugfixes "fix some issues of var_val"

Purpose of change

Just try these 2 eocs :

[
  {
    "type": "effect_on_condition",
    "id": "EOC_test_varval_1",
    "effect": [
      { "set_string_var": "npc_variable", "target_var": { "context_val": "link_val" } },
      { "set_string_var": "SOMETHING", "target_var": { "var_val": "link_val" } },
      { "u_message": "the u_val_variable: <u_val:variable>" },
      { "u_message": "the global_val_variable: <global_val:variable>" },
      { "u_message": "the context_val_variable: <context_val:variable>" }
    ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_test_varval_2",
    "effect": [
      { "set_string_var": "v_link_val_2", "target_var": { "context_val": "link_val_1" } },
      { "set_string_var": "v_link_val_3", "target_var": { "context_val": "link_val_2" } },
      { "set_string_var": "v_link_val_1", "target_var": { "context_val": "link_val_3" } },
      { "set_string_var": "SOMETHING", "target_var": { "var_val": "link_val_1" } }
    ]
  }
]

The issue in "EOC_test_varval_1" is that the value of SOMETHING should be stored in npc_variable but is incorrectly stored in u_variable. And the expected behavior in this case is that it will show a debug message that there is no beta talker.
image

The issue in "EOC_test_varval_2" is that when running it, the game will crash without any debug messages.

Describe the solution

For issue1, I fixed it by setting the new talker after resolving the var_val.
For issue1, I fixed it by removing the unnecessary parameter talker *talk in function write_var_value, and when it processes var_type::u and var_type::npc, it will try to get the talker from the dialogue instead of using the talker *talk .

Additionally, parsing for values starting with "n_" has been added simultaneously to maintain consistency with math.

For issue2, track the call_depth when processing the var_val. If call_depth > 1000, a debugmsg "Possible infinite loop detected: var_val points to itself or forms a cycle. %s->%s" will be shown.

Describe alternatives you've considered

None

Testing

Additional context

@github-actions github-actions bot added <Documentation> Design documents, internal info, guides and help. [C++] Changes (can be) made in C++. Previously named `Code` [Markdown] Markdown issues and PRs EOC: Effects On Condition Anything concerning Effects On Condition json-styled JSON lint passed, label assigned by github actions <Bugfix> This is a fix for a bug (or closes open issue) <Enhancement / Feature> New features, or enhancements on existing Code: Infrastructure / Style / Static Analysis Code internal infrastructure and style Info / User Interface Game - player communication, menus, etc. astyled astyled PR, label is assigned by github actions labels Mar 16, 2024
@github-actions github-actions bot added the BasicBuildPassed This PR builds correctly, label assigned by github actions label Mar 16, 2024
src/dialogue_helpers.cpp Outdated Show resolved Hide resolved
src/dialogue_helpers.cpp Outdated Show resolved Hide resolved
@github-actions github-actions bot removed the astyled astyled PR, label is assigned by github actions label Mar 16, 2024
@github-actions github-actions bot added the astyled astyled PR, label is assigned by github actions label Mar 16, 2024
@andrei8l
Copy link
Contributor

For issue1, I fixed it by setting the new talker after resolving the var_val.

AFAICT from a quick look, the fix can go a little deeper and remove the talker argument from write_var_value() since you're also passing the dialogue instance.

You should add a test unit too, since the existing one failed to catch this issue.

Additionally, parsing for values starting with "n_" has been added simultaneously to maintain consistency with math.

I don't like this mixing. Either change it all to math syntax or not at all. IIRC we still can't change everything to math syntax because updating u_add_var would introduce a lot of churn.

For issue2, track the call_depth when processing the var_val. If call_depth > 1000, a debugmsg "Possible infinite loop detected: var_val points to itself or forms a cycle. %s->%s" will be shown.

Better just not resolve var_val recursively. I don't see any situation where that is useful or has a meaningful result. You'll note that recursive evaluation isn't mentioned in the documentation and isn't used anywhere.

@PipeYume
Copy link
Contributor Author

PipeYume commented Mar 16, 2024

I don't like this mixing. Either change it all to math syntax or not at all. IIRC we still can't change everything to math syntax because updating u_add_var would introduce a lot of churn.

Changing it to a math-like format might be better, as it currently parses in the form of u_name rather than {"u_val": "name"} or <u_val:name> format.

Better just not resolve var_val recursively. I don't see any situation where that is useful or has a meaningful result. You'll note that recursive evaluation isn't mentioned in the documentation and isn't used anywhere.

The previous code could recursively resolve var_val, and I'm not entirely sure what the intention was at the time. So, should I maintain the status quo, or should I simply remove resolving "v_" through var_val?

@github-actions github-actions bot added the NPC / Factions NPCs, AI, Speech, Factions, Ownership label Mar 17, 2024
@github-actions github-actions bot requested a review from dseguin March 17, 2024 06:17
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Auto-requesting reviews from non-collaborators: @wapcaplet @andrei8l

@github-actions github-actions bot added [JSON] Changes (can be) made in JSON Code: Tests Measurement, self-control, statistics, balancing. labels Mar 17, 2024
@github-actions github-actions bot removed the BasicBuildPassed This PR builds correctly, label assigned by github actions label Mar 17, 2024
@github-actions github-actions bot added the BasicBuildPassed This PR builds correctly, label assigned by github actions label Mar 19, 2024
@Maleclypse Maleclypse merged commit e9df0a1 into CleverRaven:master Mar 24, 2024
26 of 27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
astyled astyled PR, label is assigned by github actions BasicBuildPassed This PR builds correctly, label assigned by github actions <Bugfix> This is a fix for a bug (or closes open issue) [C++] Changes (can be) made in C++. Previously named `Code` Code: Infrastructure / Style / Static Analysis Code internal infrastructure and style Code: Tests Measurement, self-control, statistics, balancing. <Documentation> Design documents, internal info, guides and help. <Enhancement / Feature> New features, or enhancements on existing EOC: Effects On Condition Anything concerning Effects On Condition Info / User Interface Game - player communication, menus, etc. [JSON] Changes (can be) made in JSON json-styled JSON lint passed, label assigned by github actions [Markdown] Markdown issues and PRs NPC / Factions NPCs, AI, Speech, Factions, Ownership
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants