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

VeryXInh

Veteran
Veteran
Joined
Jan 7, 2019
Messages
90
Reaction score
114
First Language
Japanese
Primarily Uses
RMXP
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?
 

bgillisp

Global Moderators
Global Mod
Joined
Jul 2, 2014
Messages
12,607
Reaction score
12,927
First Language
English
Primarily Uses
RMVXA

I've moved this thread to RGSSx Support. Please be sure to post your threads in the correct forum next time. 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
 

Heirukichi

Veteran
Veteran
Joined
Sep 24, 2015
Messages
1,344
Reaction score
566
First Language
Italian
Primarily Uses
RMVXA
@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.
 

VeryXInh

Veteran
Veteran
Joined
Jan 7, 2019
Messages
90
Reaction score
114
First Language
Japanese
Primarily Uses
RMXP
Hey, thanks guy.
So how can access @equips variable via script call? Is it possible?
 

VeryXInh

Veteran
Veteran
Joined
Jan 7, 2019
Messages
90
Reaction score
114
First Language
Japanese
Primarily Uses
RMXP
@Roninator2 i want to know how to access variables within a method via script call? can you help me?
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
29,230
Reaction score
6,774
First Language
German
Primarily Uses
RMMV
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.
 

Roninator2

Gamer
Veteran
Joined
May 22, 2016
Messages
1,878
Reaction score
410
First Language
English
Primarily Uses
RMVXA
@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.
 
Last edited:

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,670
Reaction score
2,991
First Language
Tagalog
Primarily Uses
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)
 
Last edited:

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,670
Reaction score
2,991
First Language
Tagalog
Primarily Uses
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?
 

VeryXInh

Veteran
Veteran
Joined
Jan 7, 2019
Messages
90
Reaction score
114
First Language
Japanese
Primarily Uses
RMXP
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)
 

Heirukichi

Veteran
Veteran
Joined
Sep 24, 2015
Messages
1,344
Reaction score
566
First Language
Italian
Primarily Uses
RMVXA
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.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

A friend told me to stop making nomnom or gulping noise when eating or drinking. Plot twist of my life. I thought people can't hear that!
Inside you are two wolves. They take in oxygen while getting rid of the Co2 gas in your body...
Ah wait, sorry. Lungs. Not wolves. that'd be silly. Wolves are huge. You probably couldnt even fit one wolf inside you.
Tag: hack and slash | gameplay: point and click. Me: "How tf two are related to each other?"
I picked up For The King in a Humble Bundle sale, and one mechanic that stuck out to me was a physical change to the world map when finishing a side quest. That got me thinking about special map-effect rewards for certain side quests in my game.
Stream will be live shortly with some Witcher 3! Feel free to drop by!

Forum statistics

Threads
94,403
Messages
920,690
Members
124,192
Latest member
Cremo
Top