-
Notifications
You must be signed in to change notification settings - Fork 488
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
Observe Variables (beginner question) #244
Comments
Hi ! First, the 'ObserveVariable' method needs to be called only once in the 'Start' method of your script. Second, you don't need the "int full = (int) story.variablesState["fullness"];" line at all. More than that, redeclaring this variable in the Update with "int full" implies that it is not the public variable you declared but a new variable in the local scope of the method. (so it was impossible that it stored a value durably) |
Try something like this - the
|
I did that and get this:
changed 'int' to 'object', but then the "==" operator gives me an error message: So I tried the NewValue thing as a middle man like this, which at least gets rid of the compiler error, but the Text object just says "New Text", so it's not picking up anything.
Any idea where to go next? ~Gabriela |
I did notice that |
Hmm, you mean like: I've now added that into the start method, right before the Observe Variable. No change. :( |
Sorry for a probably very novice question, but I'm very new to both unity and ink.
I'm trying to learn by modifying the ink demos (The Intercept & the demos from the Unite Europe talk) and I'm getting along pretty well, especially because ink has been a real blessing for interactive fiction.
(Apologies in advance if my description of the issue is horrible, but I'm still learning all the correct terms)
Something I can't figure out for the life of me right now is how the Observe Variables function works.
I've added a test variable ("fullness") into the ink script that starts on 0 and then depending on your first branching choice it gets set to 1, later in the text 2, then 3.
I've added a Text object to the UI of The Intercept that is supposed to show the progress of that variable.
In it I've set up a variable, names "full" and an if statement that tells the text object that if the variable is 0, it puts out "- - -" in the UI. If it's 1, it puts out "I - -". If it's 3, it puts out "I I I" into the UI.
This works if I manually set variable (independently form the ink file so far). So that part works.
Then I've tried the variablesState, so that the variable is being set by the according variable in the ink file. I did this in the same script and I'm not sure if that's the right way to do it, since I had to load the full ink story file into the script to make it work. BUT once I added that link to the story in the beginning I was able to use variablesState and when I started the game it loaded up the correct output ("- - -", "I - -", "I I I"). But it didn't track the progress of the variable throughout the choices.
And I know that I need the ObserveVariable delegate function to make that work, but I just can't seem to get it to work no matter what I try.
I've tried to adapt this example:
I don't know what I'm doing wrong. Do I need to have the variable observed in another script and then just feed it into the text game object? Maybe the GameState script? Maybe just not in the "void Update()" part of that script?
Or does it not matter and I'm just messing this up in another way?
I've tried deleting the "int full = 0;" line and replaced it by the previous variablesState version:
int full = (int) story.variablesState["fullness"];
and this way it would at least read my first "VAR fullness = 0" in the ink story. But it still wouldn't update when the variable changed throughout the game.
Thanks for any help or pointers in advance. Even seeing a working example of the ObserveVariable for a UI command would be a huge help.
~Gabriela
PS:
This is the code, for reference:
The text was updated successfully, but these errors were encountered: