Trouble with using choicescript_stats.txt to edit variables

I’m currently working on a mystery game where there is an “Evidence Menu” in the Stats Screen where it automatically displays the most recent piece of evidence the player reviewed/received.

My problem with my code so far is that there appears to be no sync of the “most recent evidence” between regular game files (startup.txt, other chapter files) and choicescript_stats.txt

I know that my problem may sound a bit confusing, so here’s a recording of my issue in Google Drive. (It’s 33 seconds, so it’s a relatively quick view)

When I select “Apples” in the Stats Screen the “most recent fruit” defaults back to “Oranges” when I go back to the regular game (in startup.txt).

The desired effect is for the “most recent” fruit to become “Apples” when I select it in the stats screen and stay that way until I select “Oranges.”

Basically, how can I make it so that when I select “Apples” in choicescript_stats, it will say “Apples were your most recently selected fruit” in startup.txt?

Below is the code used for the program in the video.

CODE IN STARTUP.TXT

*create implicit_control_flow true

*create recent_fruit "NULL" 

*label search 

This is in startup.txt

*if (recent_fruit = "NULL")
  Select a fruit.
*else 
  ${recent_fruit} were your most recently selected fruit.

*fake_choice 
  #Apples 
    *set recent_fruit "apples"
    *comment: variable recent_fruit updated in startup.txt

  #Oranges 
    *set recent_fruit "oranges"
    *comment: variable recent_fruit updated in startup.txt

*goto search

*finish

CODE IN CHOICESCRIPT_STATS.TXT

*label fruitmenu 

This is in choicescript_stats.txt

*if (recent_fruit = "NULL")
    Select a fruit.
*else 
  ${recent_fruit} were your most recently selected fruit.

*fake_choice 
  #Apples 
    *set recent_fruit "apples"
    *comment: variable recent_fruit updated in choicescript_stats

  #Oranges 
    *set recent_fruit "oranges"
    *comment: variable recent_fruit updated in choicescript_stats

*goto fruitmenu

Now imagine this but replace “Recent Fruit” with “Recent Evidence”, and “Apples” and “Oranges” with things like “Kitchen Knife” and “Jane Doe’s Testimony.” That’s kind of how the “Evidence Menu” in my planned game will work.

Feel free to ask for clarification or anything else!

I think this is just how ChoiceScript works. It is updating the variable, but the game panel will only reflect that when you click next. It is not reactive.

There’s a trick to force it to update. But it is more trouble than it’s worth. You can do it by using *redirect_scene in the choicescript_stats.txt file. But you’ll lose all temporary variables, since it’s technically loading a new scene, and you’d have to figure out a way to redirect to the exact same place.

1 Like

Oh, alright I’ll take that into consideration. However, shouldn’t selecting an option qualify as a “Next” button as well? In the code above, the recent_fruit variable is only edited when selecting a choice in both startup and choicescript_stats.

Okay I was kind of mistaken. I decided to further test this by creating an incredibly simple code like this:

In startup.txt:

*create implicit_control_flow true

*create variable false

variable: ${variable}

*finish

In choicescript_stats

*label stats

variable: ${variable}

*fake_choice 
  #set variable to true 
    *set variable true

    set variable to true 

*page_break

*goto stats

And as expected, even if I flip variable to “true” in the stats screen, variable is still set to false when I click “Return to Game.” This does appear to be a conflict with the very way Choicescript works . Thanks! I’ll still be trying to find ways/alternatives to my system though.

This topic was automatically closed 24 hours after the last reply. If you want to reopen your WiP, contact the moderators.