Save-Point
Strange Game_Enemy#actions iteration bug - Printable Version

+- Save-Point (https://www.save-point.org)
+-- Forum: Games Development (https://www.save-point.org/forum-4.html)
+--- Forum: Code Support (https://www.save-point.org/forum-20.html)
+--- Thread: Strange Game_Enemy#actions iteration bug (/thread-3556.html)



Strange Game_Enemy#actions iteration bug - Kain Nobel - 06-14-2011

Script's Purpose

The script I'm writing is supposed to prevent enemies from using pointless state-only skills that don't have a damage factor, also supposed to prevent enemies from random targeting actors whom the skill would be useless on, etc.

Symptoms

Iteration bug: With the method Game_Enemy#actions, I run an iteration that is supposed to filter all actions, check which is a skill, check if skill has power 0, check if skill has valid +/- state sets, then remove skill if conditions are all met and the action is pointless against the offending party. The problem sort of defies logic, and I have no other meddling scripts to cause this glitch.

I can print the default method, which returns all RPG::Enemy::Action objects just fine.

Right after that, I iterate through the script with actions.each {|action| ...}, but for some reason there are certain actions that get skipped. From the tests I ran, it appears that it only skips state-skills which target all (ie, Mass Venom) while at the same time others are successfully iterated through (ie, Mass Fire).

Target Random bug: The script is set up to fix random targeting methods so that a pointless state-skill won't be used on somebody whom the skill would be pointless on. It does have a DBS limitation I'm not really worried about (the same actor might be targeted during the same turn even though an enemy who acted before it inflicted actor with [state].) The one thing that is bugging me though is once in awhile, on a new turn, enemies might target an actor with a pointless state-only skill, I'm not sure where I slipped up.

Demo

I've got a ton of scripts on this, so I've isolated the problem script to its own demo.

http://www.mediafire.com/?g2x031be8g8z3w4

You can go into the script itself to set testing = true/false, which will give you a printout of whats going on behind the scenes.



RE: Strange Game_Enemy#actions iteration bug - Charlie Fleed - 06-14-2011

downloaded, will start testing asap


RE: Strange Game_Enemy#actions iteration bug - Charlie Fleed - 06-14-2011

Ok, i think that the each iterator is not happy when you delete items in the array it is iterating through.
Let's say the array is A. I usually create a temp array B, where I put the objects I determine have to be deleted. At the end of the iteration on A, I run an iteration on B and delete the objects in it from A.


RE: Strange Game_Enemy#actions iteration bug - Kain Nobel - 06-15-2011

With your help I was able to fix the main bug in my script, thank you Charlie!

Bugfix #1

I haven't had time to test it yet, but this might've solved the 2nd bug. Anyways, thank you for your help.


RE: Strange Game_Enemy#actions iteration bug - Charlie Fleed - 06-15-2011

I'm glad I could help. :)