Possible bug with turn-based delay?

Make games! Discuss those games here.

Moderators: Bob the Hamster, marionline, SDHawk

Post Reply
User avatar
Chronoas
Slime
Posts: 8
Joined: Sun May 06, 2018 11:45 pm
Location: Minnesota, USA

Possible bug with turn-based delay?

Post by Chronoas »

Hey all, finally decided to make an account here instead of using Castle Paradox for my occasional questions/bugs/feature request.

Anyway, in my RPG, in an attempt to include a "Defend" command for characters on the main combat menu, I wanted to make a move that would boost the character's current defense by 200% until their next move. My initial implementation of this was to make an attack that does so, then have a lengthy conditionals chain, based on the user's speed, linking to varying-delayed-length Defend-Off moves that would revert the the current DEF back by 50%. While the delay lengths weren't PERFECTLY lined up with the turns of the varying speed, it was close enough that it suited the purpose.

Today, while working on my game and a different attack, I happened to re-read over the help page for attacks, and saw how "Turn-based delay" worked for active time battles, and realized that would be a perfectly elegant solution to my hack-job attack chain and cut the amount of necessary attacks from 20-something to just 2.

Thus, on to the bug. I was testing out this method, and at first glance, it seemed to work wonderfully. Unfortunately, an issue arose:

If I use Defend, it doubles my current defense as intended.
If I then use Attack, Magic, or an Item, it will correctly halve my current defense and perform the attack, as intended.

However, if I use Defend, and then Defend again, it will double my current defense again. This isn't wholly unexpected or an issue, as the previous Defend command should also halve the defense, leaving at it's doubled amount for another turn. However, this is not what is happening. Viewing the Queued attacks with the debug key, every usage of Defend appears to be queuing up another [Defend off] command on the stack, but not resolving them. If I use Attack, an Item or a Magic command, however, it then clears the entire stack at once, returning the character's defense to normal. As amusing as it is to stack defense up to dizzying heights as long as you keep guarding, it's not really what I wanted gameplay-wise.

It should also be noted that I made a custom Flee command on the main combat menu that also makes use of chains, and the Defend-off stack does NOT clear when I attempt (and fail) use it. While it's possible that it's an issue with attacks used from the main combat menu, I suspect it has to do with some interaction between attack-chaining and the turn-based delay (that, or I screwed something up in my attack settings somehow that's causing it). I'm currently using the May 2nd nightly build.


Tangentially-related feature request: Speaking of my custom Flee command, might it be possible, in chaining options, to get a combination 'stat-comparison'/'scaled stat chance' option? I wanted to make Flee auto-target the highest-speed enemy, and compare the user's speed to the target's speed. Something like:

if random 0 to 1 < attacker speed
divided by target's speed [+ - * /] #

(for my purpose's, {attacker's speed/(target's speed*2)}, so that equal speed would give me a 50% chance of chaining to the 'force run' attack)
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

Thank you for the exceptionally detailed report! Hopefully James replies to this, rather than assuming I managed to fix your problem, because I'm not very familiar with attack delays and haven't even used turn-based battles...

However I did have a look at the code, which I've never studied before, and I think it looks like battle_check_delays() is never getting called from turn_mode_state_machine(), probably because pending_attacks_for_this_turn() returns false because it ignores attacks that aren't blocking? I haven't a clue how to fix this without breaking something.

What do you mean by using attack delays ("Delay attacks before attack" rather than turn delays) in turn-based more to delay an attack under the next round? I thought that attacks can only be delayed until later in the *current* round. So if you simple set a delay of 100, then that chained attack would happen at the end of the round -- which is only half of what you want in your case. (I don't see what you would use conditional chains depending on the attacker's speed for. The speed stat only affects turn order)
Tangentially-related feature request: Speaking of my custom Flee command, might it be possible, in chaining options, to get a combination 'stat-comparison'/'scaled stat chance' option?
Ah, it doesn't even seem to be possible to emulate that effect using multiple attacks. So it would be useful to add that chain condition option to allow that sort of thing... are you going to request a feature for HotOHR? :)
(This doesn't fall into the 'trivial to add' category, unfortunately)
Last edited by TMC on Mon May 07, 2018 3:48 pm, edited 4 times in total.
User avatar
Bob the Hamster
Lord of the Slimes
Posts: 7658
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Post by Bob the Hamster »

Hello!

I read the report carefully.

You are using turn-based delays, but not using turn-mode, you are using active time mode, correct?

That is fine so far.

What you describe sounds like it must be a bug, but if I am going to be able to figure it out, I think I will need to be able to test it myself. Can you send me a zip to Bob@HamsterRepublic.com with your rpg file and a .rsav file close to a battle where it will be easy to reproduce this?
Last edited by Bob the Hamster on Mon May 07, 2018 4:07 pm, edited 1 time in total.
User avatar
Chronoas
Slime
Posts: 8
Joined: Sun May 06, 2018 11:45 pm
Location: Minnesota, USA

Post by Chronoas »

Sorry, I should clarify: I'm using Active Time Battle. What I wanted to do with Defend is make it so it only lasts as long as it takes for the user's timer bar to fill back up. The problem with this, as you might imagine, is that the time it takes for the bar to fill is going to be different depending on the character's speed. I originally created a Defend command with a long conditional-on-user's-speed chain that would eventually link to one of many 'defend-end' of varying delays, depending on the current speed of the user. It was long (currently using 26 attacks), messy, and the delays I could set didn't perfectly line up with the timer-lengths, but it otherwise worked.

While working on something else, I was reading through the F1 help-log in "Appearance & Sounds..." under attacks and happened upon the description of "Delay Turns Before Attack" (something I hadn't paid much attention to, since I wasn't using turn-based combat). It reads as follows:

"Delay Turns Before Attack: In turn-based battles, this is how many rounds of combat the attacker will wait before attacking. In active-time battles, the turn delay is based on the amount of time it takes for the attacker's ready-meter to fill up." (emphasis mine)

This pretty much is EXACTLY what I was trying to accomplish with my lengthy chain, in a single function. Instead I can just set the "Defend End" attack to have a "turn" delay of 1, and it will always (theoretically) trigger when the ready-meter has filled back up. It turns a complex, 26-attack chain into 2. Indeed, if I use Defend, it doubles my defense as intended and once my ready-meter fills, if I use Attack/Magic/Item, it will trigger Defend-end, halve the defense back to normal, then perform my chosen action as I want.

The problem is introduced when I select Defend a second time in a row. It uses Defend again, doubling my defense, but the Defend-end on the attack queue doesn't trigger, it stays there (and adds a second Defend-end stack to the queue). If I perform Defend again, it will again double the defense and add another Defend-end stack to the queue, but still won't trigger the one's already queued up. Only once I choose Attack, Magic, or Item, it will suddenly trigger all the queued-up Defend-ends at once and finally return the defense to it's initial value.

Likewise, I have a custom "Flee" command that also uses some chains, and when I try to use it (and it fails to make me run), the Defend-end stacks in the queue still won't trigger, which is what makes me inclined to think it has to do with some interaction between chain attacks and the turn-delay check.
Ah, it doesn't even seem to be possible to emulate that effect using multiple attacks. So it would be useful to add that chain condition option to allow that sort of thing... are you going to request a feature for HotOHR? :)
(This doesn't fall into the 'trivial to add' category, unfortunately)
Man, I've been wanting to enter my game into HotOHR since 2010. I've never made a formal entry because I (rightly) didn't feel I would be able to get my game into a state where I'd like to share it yet. Considering how much I've been forgoing video games to work on it the past few weeks (especially with all the new features in the past year, woo!), though, I've been giving serious considerations to taking a shot this year. That said, I think I'll still hold off on any formal entrance as of yet. :(

But yeah, currently the best I could do was make it compare the user's speed to the lowest-speed enemy, and always fail if lower. Otherwise, it chains to an attack that does scaled stat chance of the user's speed versus 29 (the speed cap of my game+1), and give a chance to run based on that. It's...functional, but not quite what I'd like to do.

Anyway, sent the email. I forgot to mention it there, but if you want to take a look at the attacks in custom, it's Attack 40 and 41 (not Attacks 72-97).
Last edited by Chronoas on Tue May 08, 2018 3:29 am, edited 4 times in total.
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

Whoops! Guess I didn't read as carefully as James!

You still have most of a year, so hopefully you will actually manage to release your game this time!
(Also I'm not restricting feature/bug requests to people who release games for the contest, but rather to those working on games.)
This sot of thing really falls into what battle scripting is needed for. Hopefully there's more progress on that this year too...
User avatar
Bob the Hamster
Lord of the Slimes
Posts: 7658
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Post by Bob the Hamster »

I got the file you sent, and I can reproduce the issue. I'll let you know when I have time to figure out what is happening.
User avatar
Chronoas
Slime
Posts: 8
Joined: Sun May 06, 2018 11:45 pm
Location: Minnesota, USA

Post by Chronoas »

Alright, thank you. Hopefully it's not too difficult to fix. :)

Well, I really would like to participate in the event finally, so I think I will make a concerted effort to TRY to get something released, even if it's only a demo-like chunk of the game. Considering my game is supposed to be something of a love-letter to classic SNES JRPGs like Chrono Trigger, FF6, etc. maybe I'll shoot for a full release in time for HotOHR 2020 :D
User avatar
Chronoas
Slime
Posts: 8
Joined: Sun May 06, 2018 11:45 pm
Location: Minnesota, USA

Post by Chronoas »

So, about to start working on my game again after taking a break, and I thought I'd pop in and see if anything was discovered or resolved on this bug, while I'm thinking of it. Did it ever get fixed for the nightly's?
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

Heh, nice coincidence. When you reported this bug I didn't understand how turn-based delays in the attack queue worked at all, so I could hardly even understand your report. Since then, I've fixed some other problems with the attack queue. I was actually wondering whether I managed to accidentally fix this bug while making other changes, so if you retested it with a recently nightly that would be appreciated.
If it's not fixed, I wanted to tackle this bug soon, while I still remember details of the attack queue, but realistically I've also got about 40 other bugs I wanted to fix "soon" so I don't know when that will happen.
Last edited by TMC on Thu Oct 25, 2018 8:56 am, edited 1 time in total.
User avatar
Chronoas
Slime
Posts: 8
Joined: Sun May 06, 2018 11:45 pm
Location: Minnesota, USA

Post by Chronoas »

Yeah, I also realized after your confusion that I probably should've put the description of "Delay Turns Before Attack:" from the Attack Appearance help screen, since that's what made me attempt this method in the first place.

Anyway, a succinct summary: I'm using Active-Time Battle. I want to make a 'Defend' command on the battle menu that doubles a hero's defense stat until they take another action - i.e., reverts to normal once the Ready Meter has refilled. Because the Ready Meter time varies based on a character's speed, using time delay for an attack that reverts defense to normal is a messy (currently 20+ chained attacks) affair.

The help description for "Delay Turns Before Attack" option reads:
Delay Turns Before Attack: In turn-based battles, this is how many rounds of combat the attacker will wait before attacking. In active-time battles, the turn delay is based on the amount of time it takes for the attacker's ready-meter to fill up.
This cleanly does what I want: "Defend" doubles defense -> chain "DefendEnd" to halve defense on a 1-turn delay. No matter what the character's speed is, DefendEnd will activate when their Ready Meter is full again. The character chooses a new action, their defense reverts to normal, and they perform their chosen action, battle goes on.

The problem, of course, is the bug: This works exactly how I want, save for one instance: If the character chooses "Defend" a second time in a row, their defense should double again and add a "DefendEnd" to the attack queue; the previous queued "DefendEnd" should also trigger to halve their defense, leaving it at its doubled value for another turn. What's currently happening is that any consecutive "Defend" command is doubling their defense value, adding a "DefendEnd" attack to the attack queue, but the previous "DefendEnd" command is STAYING in the queue instead of triggering. Repeated use of "Defend" continues to double the defense stat to astronomical heights until the character choose a different action. Once a different action, such as Attack, is chosen, all the queued "DefendEnd" attacks suddenly trigger at once and deflate their defense back to normal.


Alas, as of this post, I can confirm that this bug remains in the current nightly. I've attached a screenshot showing a half dozen "DefendEnd" attacks stuck in the queue. What's notable is that if I select the custom "Flee" command (and it fails to have me flee the battle), the "DefendEnd" attacks are also staying in the queue. [s]Since both the "Defend" and "Flee" commands make use of chains, the behaviour suggests that something in the chain logic is bypassing a check on the queue somewhere, but that's wild speculation on my part[/s].

Image

EDIT: Disregard what I said about chains. I added a few attacks that use chains to my ability menu, a few to the main battle menu, and one that didn't use chains to the main battlle menu. None of them triggered the bug.

EDIT2: Oh wow. So I've spent a bit of time poking and prodding to try and figure out what it is that's causing "Flee" and "Defend" to trigger the glitch, but none of my other attacks. It's the "Automatically choose target" bitset. To confirm, I've made a completely new attack, and only turned the "Automatically choose target" bitset on, and sure enough, it's not clearing the queue.

EDIT3: I turned "Automatically choose target" off on "Defend", and it works as intended. I think I've found where to look, haha.
Last edited by Chronoas on Thu Oct 25, 2018 11:12 am, edited 6 times in total.
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

Ah ha! Thanks for this very detailed testing. Indeed, looking at the code for "automatically choose target", I see that it puts the autotargetting attack directly onto the attack queue, while with manual targetting, battle_confirm_target gets called which calls update_turn_delays_in_attack_queue before putting the attack in the attack queue. So the problem appears to be a missing update_turn_delays_in_attack_queue call.

I'll fix this now, however I ALSO noticed a very similar problem with enemies which I will guess has the effect of causing the same problem for all turn-delayed enemy attacks in active time battle mode, regardless of whether "automatically choose target" is set or not. I actually found that problem recently - a broken call to update_turn_delays_in_attack_queue, which I haven't fixed yet - but I didn't know what effect it would have. Now I can see that it should be the same as this bug. Two bugfixes for the price of one!

Edit: OK, the fix will be in the next nightly build. Thanks for making this easy!
Last edited by TMC on Fri Oct 26, 2018 1:58 am, edited 3 times in total.
User avatar
Chronoas
Slime
Posts: 8
Joined: Sun May 06, 2018 11:45 pm
Location: Minnesota, USA

Post by Chronoas »

Happy to oblige, and even happier to have it fixed! :)
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

Err... you better wait for the next nightly build (in about 23 hours). A rather dramatic bug snuck past me into tonight's nightly build, which makes the Enter and Space keys malfunction...
Post Reply