[ACE] Why can't i straightly delete actor's weapon?

Hi there,
I wonder why, since actors' equips is an array only?
Why can't i remove for example, actor 1 weapon just like this:
$game_actors[1].equips[0] = 0 or
$game_actors[1].equips[0] = nil


i see in game_player script, they discard weapon like this:
@equips[slot_id].object = nil if slot_id

Now why when i try to run this code:
$game_actors[1].equips[0].object = nil
it got error of undefined "object" method??? I just copied it from game_player script, why it's error?

I've moved this thread to RGSSx Support. Thank you.



You probably referenced the wrong id, as they are often not the same in the engine at runtime, as many start at 0 instead of one. Also make sure that $game_actors is defined, as I thought it was $game_actor
@bgillisp Game_Actors is the wrapper class for Game_Actor so in this case that is the correct usage.

@VeryXInh the reason why it is not working is because you probably misunderstood how the equips method works. The instance variable "@equips" is not what the "equips" method returns. Here is the method itself:
Code:
def equips
    @equips.collect {|item| item.object }
end
As you can see item is the instance of Game_BaseItem (the single element of the @equips array) but the method returns an array of item.object. That means the array you get when calling equips is no longer an array of Game_BaseItem and thus its elements do not have the object method which is defined in the Game_BaseItem class.

It is the same as writing this:
Code:
def equips
  array_I_want_to_return = []
  @equips.each do { |item| array_I_want_to_return << item.object }
  return array_I_want_to_return
end

As you can see the object method is already called on each element of the @equips array.
$game_actors[1].equips[0] = 0
$game_actors[1].change_equip_by_id(0, nil)
Hey, thanks guy.
So how can access @equips variable via script call? Is it possible?
@VeryXInh
What are you trying to do?
This page has a lot of script calls explained.
https://steamcommunity.com/sharedfiles/filedetails/?id=668507872
@Roninator2 i want to know how to access variables within a method via script call? can you help me?
the problem here is that equips are not numbers but objects. and you can't assign a variable (which is a number) to an object.
you need to create the equips object and then assign it to actors, that will work. but that requires an additional step, the creation of said object - you can't directly assign it in a single script line.

That is why you need either multiple lines or a predefined function to access that, and nothing can change this principle.
@VeryXInh as Andar said accessing equips is not a simple matter. Accessing variables is. Which the two are totally different.
Mind you a variable can be any value but normally it just holds numbers. Also variables are often assigned temporarily to perform functions in scripts.
The games variables are quite simply $game_variables[x]
scripting will use variables in many different ways.
e.g. For i in 0...$game_party.size
the i is a variable and in this case is a number.
I suggest you read some tutorials on scripts (if you haven't), (if you have - then study them well).
There are tutorials on ruby programming which may help you learn more.
I myself am at that point, learning more.
You can access the @equips array directly (or any other instance variables of a class) by using the

instance_variables method

Like
Code:
$game_actors[1].instance_variables(:equips)

That is, IIRC, Im not sure if it takes a symbol or a string

But anyway if what you want access to are the actual equip objects, there shouldn't be a need for you to access @equips directly and just use the .equips method to get the item objects directly.

Though if you want to remove weapons from it, you do need access to @equips directly since .equip returns a new array containing the object form of the item ids, not the @equips array itself. That is also why you can't remove a weapon via .equips[1] = nil

Or you can use the script call posted by somebody above to remove weapons (or any equip from the array)
That is, IIRC, Im not sure if it takes a symbol or a string
*cough* it's
Code:
.instance_variable_get(:@equips)
*cough*

Why cannot you just use the built-in method like ".change_equip"?
Thanks @TheoAllen for correcting me

And yeah, the methods to manipulate the equip slots are already present in the game, so why not just utilize them?
Hey guys, thank you very much.
Actually i was wondering why can't i just remove/delete or do anything to
$game_actors[1].equips array.
I mistook it with @equips so i didn't think
it as a returned method but a variable, so i thought it was just unreasonable.

And i also wanted to know how to access to instance variables (i tried $game_actors[1].@equips =D)
There are various methods to access the instance variable itself. One of them is listed above while other options could be using instance_eval for example. It is not unreasonable as long as you know what you are doing and you have a reason for doing so.

Of course you should keep in mind that @equips is an array of objects and each element of that said array is an instance of Game_BaseItem. As long as you know this and act accordingly you should not run into issues.

If - for example - you want to create a completely new item and put it into equips then it is safe to do it using @equips directly. If you just want to access one of its elements to set it to nil or to change it to be a different item then the built-in method is the way. Having to create a new object, having to set it up and then putting it in the said array requires way more lines compared to just calling a single method.

Original thread: https://forums.rpgmakerweb.com/threads/ace-why-cant-i-straightly-delete-actors-weapon.106305/