Force-deactivate Window_BattleEnemy?

If Shaz reads this, you might realize this is indirectly related to that whole @ungray issue, but this is something else.

This is the next thing on my script-related TO-DO list.  Basically I have a skill running on a switch restriction from Yanfly Skill Restriction that is based off Game_Timer turning a switch ON/OFF during battles when @count hits certain values. (Timer is active and working while actor-turn-making is happening)

When this skill is usable (switch is OFF), and choosing enemy targets (Slime A, Slime B, etc.aka Window_BattleEnemy), I'm trying to make it so that when the switch turns ON while this window is active, Window_BattleEnemy deactivates back to the BattleSkill/SkillList window ONLY IF THIS SPECIFIC SKILL (or other specifics that also function in the same style) ARE BEING USED. I need to do this because if you try to use the skill after the switch turns ON, it naturally becomes non-usable and you waste a turn due to skill failure.

Example:

  1. Window_BattleSkill list is open
  2. When the timer hits 5 seconds of @count, I can select the skill Retribution
    -----------------------------The following is what I want -----------------------------------------------
  3. I am now choosing the enemy to target with Retribution. However timer reaches 3 seconds of @count and the window force-deactivates
  4. I now have to choose another skill / actor command / etc.

Sadly one thing I noticed is that Window_BattleEnemy doesn't have an update of any kind... (I think?) Anyways I guess the main place to look is Scene_Battle.

Edit 1: Okay so far I managed to set a global variable $deactivate to turn True when the timer reaches 3 seconds (in Game_Timer), then it does the following in Scene_Battle

if @enemy_window.active if $deactivate @enemy_window.hide.deactivate command_skill $deactivate = false endendNow the only thing I need to figure out is how to check what Skill ID is selected when entering @enemy_window, and then add (right after "if $deactivate"):

Code:
if @enemy_window.active  if $deactivate    if selected_skill_ID == 223      #<--- I need to figure out this part, pseudocode      @enemy_window.hide.deactivate      command_skill      $deactivate = false    end  endend
I'm not really familiar with the script, but I'm not sure this can be done. A skill is not used until all of your actions have been selected and targets identified. So when the skill is used, the enemy window will not be active anyway.


This is with the RTP battle system. I don't know if any scripts you're using replace that and have different behaviour.
skill is saved into a variable local to the battle scene (@skill), you might wanna go to this method in scene_battle,

def on_skill_ok

and save the skill id into a global variable so that you can use it on other classes

or try using 

SceneManager.scene.skill.id

for the skill id check

so your code would be like this in case it would work:

if @enemy_window.active  if $deactivate    if SceneManager.scene.skill.id == 223 #<--- I need to figure out this part, pseudocode      @enemy_window.hide.deactivate      command_skill      $deactivate = false    end  endend
BTW all windows based on Window_Base have updates... if they don't have specific updates to them, they simply use the update of their super class... so you can still extend it and modify to your needs...
Last night I was looking around at @skill, but not in that exact sense. I'll give it a try when I get back in a few hours.

Edit: Upon trying if SceneManager.scene.skill.id == 223, I get an error when the window goes to deactivate.

PcZgBFv.png
I see... quite expected it...

just add this:

class Scene_Battle  def skill    return @skill  endendor 

Code:
class Scene_Battle  attr_reader: skillend
Actually, no need. I just used "if @skill.id == 223" and it works perfectly.  I got the confirmation of this idea from a Front/Rear row script I had that also uses @skill.id

Now my skill 223 successfully exits enemy selection when the switch turns off.

Thanks a bunch guys. This thread can be closed.
oh... I didn't realized that you're running the script from Scene_battle
This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/force-deactivate-window_battleenemy.19302/