Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

[Resolved] Problem inserting "Steal" (Caused by ALibrary method re-write)

Good day everybody!

This headache topic is resolved, anybody interested to know what was wrong, Aleworks overwrote the Array method, 'insert', which caused it not to work correctly. I'm contacting vgvgf and letting him know of the errors existance, thanks to everyone who contributed their time and help.

I'll leave the topic intact for anybody who needs to read up on it for any reason.

I need a little bit of help, what I'm trying to do is create a Steal/Mug system, but I've ran into some headbutts with it. Well, first off, I started with the easier part, implementing "Mug" in Game_Battler#attack_effect and into the Battle @actor_command_window (so that it replaces "Attack" if your actor has a "Mug" skill).

What I'm working on now, isn't Mug anymore, because Mug is done and over with, now I am onto "Steal". What I want to do with "Steal" (which is typically the same for "Mug") is to be able to set up a Skill that represents it. Whenever an actor has this skill, first of all I want it to be inserted between "Skill" and "Defend", but... its not inserting at all.

Code:
  #-----------------------------------------------------------------------------
  # * Phase 3 : Setup Command Window
  #-----------------------------------------------------------------------------
  def phase3_setup_command_window
    steal_scnbtlp3_setup_command_window
    actor = $game_party.actors[@actor_index]
    if actor.has_mug?
      unless @steal_command_set
        @steal_command_set = true
        commands = @actor_command_window.commands.dup
        commands[0] = SDK::Scene_Commands::Scene_Battle::Mug
        @actor_command_window.commands = commands
      end
    elsif actor.has_steal?
      unless @steal_command_set
        @steal_command_set = true
        commands = @actor_command_window.commands.dup
        commands.insert(2, SDK::Scene_Commands::Scene_Battle::Steal)
        #commands << SDK::Scene_Commands::Scene_Battle::Steal
        @actor_command_window.commands = commands
      end
    end
  end

Yes, I did a print test and it did return true for "p actor.has_steal?" and false for "p actor.has_mug?", so I know that part is working fine... but, the commands still remain the default "Attack, Skill, Defend, Item". Further print test reveals that its even executing process of changing the commands, yet... the print test (and the command window) still show the default 4 commands and not Command "Steal". Is it possible that the Array.insert() function is obsolete?

To sum it all up, I want the commands to be like so (if you don't have Mug but have Steal)...

Attack
Skill
Steal
(Other things that could go here later...)
Defend
Item

How the heck can I get ["Attack", "Skill", "Steal", ...whatever, "Defend", "Item"] like I'm trying to do? I'm trying to avoid everything being underneath Item, because people might not otherwise know its there. It works doing commands.push... doesn't work with commands.insert(2, command)...

EDIT: Y'know what, after rigorous print tests... I just realised stupid Array.insert doesn't even work on RGSS! @_@ Am I just going crazy or anybody else notice that too?
 
Kain Nobel":1eoenhei said:
EDIT: Y'know what, after rigorous print tests... I just realised stupid Array.insert doesn't even work on RGSS! @_@ Am I just going crazy or anybody else notice that too?
Are you refering to using 'Array.insert' in that context? As just by looking in the help file, you can see that this is not a self function. It won't work unless you have an array instance. Inserting worked fine for me with an instance, but not using the constant self. Why would you ever want that in the first place? Have all newly defined arrays have the same values in them at the initialization?
 
Code:
commands = @actor_command_window.commands.dup
commands.insert(2, SDK::Scene_Commands::Scene_Battle::Steal)
p commands

I'm just trying to insert "Steal" between "Skills" and "Defend" but its not working :(

So no it doesn't have the same value as initialization. I could forcefully create the command order, but I'm trying to make it so that if there were other commands, they wouldn't be deleted in the process.

I'm assuming that the way I'm using it 'should' work (provided the method isn't bunk), but just incase I did this for the array class, it didn't make a difference though unfortunately.

Code:
class Array < Object
  #-----------------------------------------------------------------------------
  # * Array.insert
  #-----------------------------------------------------------------------------
  def self.insert(index, *args)
    insert(index, *args)
  end
end
 
Hmm... this is odd. I tried using the same snippet, and it did absolutely what it should.

Code:
a = ["A", "C"]
a.insert 1, "B"
p a
Printed ["A", "B", "C"].

Does your print output the commands as they were before the insertion? Maybe confirm this by adding a print before the insertion to see if it's the same or if it's changed.
 
You've got to refresht the window, then change it's size and y position. I just tested it with this code inserted into Scen_Battle 3:

Code:
  #-----------------------------------------------------------------------------
  # * Phase 3 : Setup Command Window
  #-----------------------------------------------------------------------------
  alias steal_scnbtlp3_setup_command_window phase3_setup_command_window
  def phase3_setup_command_window
    steal_scnbtlp3_setup_command_window
    actor = $game_party.actors[@actor_index]
    @steal_command_set = false
    unless @steal_command_set
      @steal_command_set = true
      commands = @actor_command_window.commands.dup
      commands.insert(2, "Steal")
      #commands << SDK::Scene_Commands::Scene_Battle::Steal
      @actor_command_window.commands = commands
      @actor_command_window.refresh
    end
  end

Anyway, what I found is that it was inserting the command, but it needed to refresh the window to display. Also, it will need to resize and relocate the window to display the commands. Also, I like the fact that you modified the command window class so you cvan view and edit the commands. Took me a sec to figure out, but it's a good idea.
 
Alright, I've figured this out, had nothing to do with any of that. Thanks for the help guy's I did a Search All for "def insert" after I got home from work and found this in vgvgf's Aleworks Library, for the Array class.

Code:
  #---------------------------------------------------------------------------
  # * Insert
  #---------------------------------------------------------------------------
  def insert(*args)
    array = self.clone
    to_insert = args[1, args.size - 1]
    args[0] = [args[0], array.size - 1].min
    return array.reverse.concat(to_insert).reverse if args[0] < 0
    array[0..args[0]].concat(to_insert).concat(array[args[0] + 1...array.size])
  end

I'm sorry if I gave any of you guys a headache trying to figure this out, next time I come along something weird like that I'll do a search all and see if I can find something redefining one of Ruby's classes methods. I've got it commented out, and I'm gonna contact vgvgf and let him know of the error caused by his ALibrary.

This topic is RESOLVED!!! Thanks for your help and patience everybody. :thumb:
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top