I'm using Twine 2.0.11 and Sugarcube 2.12.0
I'm using a rpg system and some of my variables (player HP, etc.) isn't updating - I use the display macro to show the stats in multiple passages. When I switch to a new passage it goes back to the old variable and ignores the most recent passage I used.
Is there a macro available just to update the specific variables? Thank you!
Comments
Beyond that. The <<set>> macro is what you should, generally, be using to modify the values of variables.
Question. Are you using <<back>> in any of these passages by any chance?
I tested my rpg by intentionally losing a battle, bringing my health down to 1 hp. I then go to the town and sleep to replenish my HP, and then go out to the map to battle again. When I explore the map, my health accurately displays the latest stat, but when I enter into battle, my health reverts back to the 1 hp I had before I entered the town. So as you can see, it's encompassing quite a few passages so I'm not exactly sure which codes are the problem.
Playerturn passage (battle):
MapThessila passage (map):
The town passage code (TownThessila passage) is pretty long, but here's the code for the action button where the HP should have been replenished. It works, but this disappears when I go out of town and get into a battle scene.
PlayerStatistics passage:
Basically, I go through the passages in this order: Battle -> 1 HP -> move around Map -> go to Town -> replenish HP -> go back to map -> go to battle
Everything works right up until I enter battle and I'm back to the 1 hp.
If you need more info, I do have an online version of the game up (http://www.philome.la/PaperWaifu/godhood), but it is 1.) text-based but still absolutely NSFW, and 2.) might take playing a bit further along to get to the bug. I also have a saved game I can send, but I have no idea how to transfer saved games to someone else.
1. Your town passage code has a variable name error:
2. Your Playerturn passage (battle) passage uses a number of variables like $poisoned to determine what happens in the battle but you did not include any information about where those types of variables get reset to default values before the battle starts the second time around. If they are not getting reset then that could effect the second battle.
2. When the player clicks on the Attack button in the PlayerTurn passage, it goes to a "Playerattack" passage, which then goes to a "DeathCheck" passage which checks the status of the battle and reset variables if the monster is at 0 hp and slain (set poisoned to 0, etc.).
Here's the PlayerAttack passage:
And here's the DeathCheck passage:
(Like I said, there were a lot of passages, and didn't know which ones were affecting it. Was hoping if there was some kind of update macro to sort of force the variable to update, or will something like that not work with my current setup?)
I'm not using any back macros for this.
When the story traverses (forward) from one passage to the next (the next passage can also be the same as the last one) the current state of all known variables is persisted in the History system. So if you are using <<set>> on a non-temporary variable then you are already using a macro that "force the variable to update"
I don't have time ATM to debug the version you linked, I will try to do that later today but maybe TME may do it before then.
Beyond that, is the following code supposed to modify $player.HP? It looks like that was the intent, but it never obviously modifies the player's hit points.
There's none that I could see, because the HP already reverts to 1 HP before I do anything in the battle. Entering the battle itself triggers the 1 HP, and not by doing any actions within the passage.
Here's the part of one other passage that's displayed in the one of passages linking to the Map passage that leads to the battle scene upon encountering a monster, to decide if you'll fight or run away:
The only thing I can think of is my putting <<display "PlayerStatistics">> in the map and in the battle passages. I haven't modified $player anywhere else and in any other way that I know of beyond the examples I put here. But $player is also an array, though. From my StoryInit:
Ah, this one will be triggered by one of the action commands in PlayerTurn, if you choose Spells to attack. That leads to a PlayerSpells passage where selecting "Heal" will set $castaccessoryheal to yes and then goes back to the PlayerTurn passage.
Hehe, I split the battle passage into several smaller ones hoping to make it easier to code, but it looks like it's a lot harder to debug this way!
Try adding some <<print "Point xxx: " +$player.HP >> statements throughout your playerTurn passage to see if you can isolate where the HPs are being changed (change the value of xxx on each one). Put the first one on the very first line so you don't waste a lot of time if the value has already been changed by the time you get there.
Got anything in your PassageEntry passage?
I checked back on some of the passages when I'm battling bosses, and saw that I made a <<set $player.HP to 1>> if I lose to a boss. When I added in an if condition:
and then tested it out, it looks like finally worked! Values are being updated properly this time around. So it really was another code I added in that I hadn't even put in here that was causing the error. Ugghhh. I don't completely understand why adding the if condition would make the difference, but right now I'm just really glad it's working cause this was something I've been trying to figure out for 4 days now.
Thank you, thank you, thank you so much!