I cannot for some reason check if my actor has anything equipped. Nothing works

eluukkanen

Composer
Veteran
Joined
Feb 16, 2016
Messages
329
Reaction score
217
First Language
Finnish
Primarily Uses
N/A
I cannot for reason check if my actor has anything equipped. This should be easy, but it just won't work. Not with a script call, not with anything.

I have looked help from this topic and from Conditional Branch+
https://forums.rpgmakerweb.com/index.php?threads/check-if-actor-has-equipment-type-equipped.103836/

Conditional Branch+ worked with weapons, but not with armor

I very much wish to have it as a script call, as I have plenty of actors in the game. Using variable in line where the actor id is placed is must.

I have tried a script call like this:

$gameActors.actor($gameVariables.value(57)).equips()[2] == 14;

$gameVariables.value(57) = variable that constantly checks who is party leader
equips()[2] = should be equipment type 2 (head)
14 = should be the id of the armor

But does not work.

What am I missing...? I have no scripts on when testing (only Conditional Branch+)
 

MushroomCake28

KAMO Studio
Moderator
Joined
Nov 18, 2015
Messages
2,219
Reaction score
3,585
First Language
English
Primarily Uses
RMMV
What does it say when you call it in the console?

What is the value of $gameVaraibles.value(57)? $gameActors is organized by actor Id while all actors in the party are organized by the order in which they were added to the party (I call it the party Id). So if the variables return the party Id of the leader instead of its actor Id, then it would explain why it doesn't work (the party leader is usually the first one, so party Id would be 0, and there is no actor Id 0 it's going to return null).

Additionally, you know you can use $gameParty.leader to get the leader? Unless you have a different system than the default party system.
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
29,210
Reaction score
6,762
First Language
German
Primarily Uses
RMMV
$gameVariables.value(57) = variable that constantly checks who is party leader
how did you do this?
by default all variables contain the value when they were set, they do NOT constantly update.

so one possible cause for the error is that the variable might point to the wrong actor, please show us how you set it.
 

eluukkanen

Composer
Veteran
Joined
Feb 16, 2016
Messages
329
Reaction score
217
First Language
Finnish
Primarily Uses
N/A
how did you do this?
by default all variables contain the value when they were set, they do NOT constantly update.

so one possible cause for the error is that the variable might point to the wrong actor, please show us how you set it.
You can do it with $gameParty.leader but $gameVaraibles.value(57) is not always the party leader. Script chooses depending on the situation what party member is doing what and etc. This is not that is not working. All my other setups have no problem making $gameActors.actor($gameVariables.value(57)) into $gameActors.actor(1) as example when needed.

The problem lies somehow on how I put the conditional branch on the script. I could use conditional branch of event, but as I am using a variable, having it scripted would help and save a ton of time.

What script conditional works for you when checking equipment?
 

eluukkanen

Composer
Veteran
Joined
Feb 16, 2016
Messages
329
Reaction score
217
First Language
Finnish
Primarily Uses
N/A
Here is a picture on the event + on the event. Am I missing something... :LZSooo:

testing armor.jpg
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
29,210
Reaction score
6,762
First Language
German
Primarily Uses
RMMV
Sometimes it's the small errors - I didn't spot it at first because I rarely use javascript, but if I remember correctly you need to use === instead of == for comparisons in javascript.
 

ramza

Lunatic Coder
Veteran
Joined
Jan 28, 2013
Messages
585
Reaction score
329
First Language
English
Primarily Uses
RMMV
I cannot for reason check if my actor has anything equipped. This should be easy, but it just won't work. Not with a script call, not with anything.

I have looked help from this topic and from Conditional Branch+
https://forums.rpgmakerweb.com/index.php?threads/check-if-actor-has-equipment-type-equipped.103836/

Conditional Branch+ worked with weapons, but not with armor

I very much wish to have it as a script call, as I have plenty of actors in the game. Using variable in line where the actor id is placed is must.

I have tried a script call like this:

$gameActors.actor($gameVariables.value(57)).equips()[2] == 14;

$gameVariables.value(57) = variable that constantly checks who is party leader
equips()[2] = should be equipment type 2 (head)
14 = should be the id of the armor

But does not work.

What am I missing...? I have no scripts on when testing (only Conditional Branch+)
Sorry for responding so late after your initial post, I hope that you've already found the issue here, but I have also found it and will explain why this doesn't work for you.

First, whatever you're using to set that variable to the actorId of the party leader is probably unnecessary. $gameParty.leader() is the leader of the party. $gameParty.members()[0] is also the leader of the party. To check the equipment of the leader, $gameParty.leader().equips()[x] returns the item in slot x of the leader. This is an important distinction to make, because it is returning an object, not the Armor Id of that object, and this is the reason your check is failing. The correct check is below:
$gameParty.leader().equips()[2].id === 14
 

eluukkanen

Composer
Veteran
Joined
Feb 16, 2016
Messages
329
Reaction score
217
First Language
Finnish
Primarily Uses
N/A
Much appreciated! It partly works. Only problem with it is that if the party leader has nothing equipped, there is a crash with the conditional event. It only functions if there is that certain equipment equipped, which kinda breaks any usage it has unfortunately ;_;

It says: Cannot Read property "id" of null

This was tested in a regular project without any other script involved.
 

eluukkanen

Composer
Veteran
Joined
Feb 16, 2016
Messages
329
Reaction score
217
First Language
Finnish
Primarily Uses
N/A
Sorry for responding so late after your initial post, I hope that you've already found the issue here, but I have also found it and will explain why this doesn't work for you.

First, whatever you're using to set that variable to the actorId of the party leader is probably unnecessary. $gameParty.leader() is the leader of the party. $gameParty.members()[0] is also the leader of the party. To check the equipment of the leader, $gameParty.leader().equips()[x] returns the item in slot x of the leader. This is an important distinction to make, because it is returning an object, not the Armor Id of that object, and this is the reason your check is failing. The correct check is below:
$gameParty.leader().equips()[2].id === 14
This is what it shows with
$gameParty.leader().equips()[2].id === 14
If there is nothing equipped

test it.jpg
 

ramza

Lunatic Coder
Veteran
Joined
Jan 28, 2013
Messages
585
Reaction score
329
First Language
English
Primarily Uses
RMMV
This is what it shows with
$gameParty.leader().equips()[2].id === 14
If there is nothing equipped

View attachment 134013
In your conditional branch, do an && check to make sure the item exists before the original check.

Code:
$gameParty.leader().equips()[2] && $gameParty.leader().equips()[2].id === 14
This will check first if the item exists (or isn't nothing), and then check the items Id if it does exist. It will return false if it doesn't exist, so it won't crash.
 

Attachments

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

Latest Threads

Latest Posts

Latest Profile Posts

i watched the sonic movie it was pretty good i hope they make a sequel
tomorrow I'ma go on a cruise for the first time ever... lets hope I'll survive the experience!
Omg! 8 years in this forum :o
Ksi
Streaming the last of the RMN Valentiny event games so feel free to drop on by and watch me cry (whether that's from laughter, rage or sheer pain, who knows?)
Today I went to sleep without setting an alarm, so I could sleep more than 2 hours. I woke up after 2 hours.

Forum statistics

Threads
94,309
Messages
919,827
Members
124,060
Latest member
jloppnow
Top