Jump to content
Kanonelsebas

Error trying to get armor id to a variable

Recommended Posts

Ehm... hope it's the right place to ask.
 
So, I got this complex common event used to Unequip the party gear, and then put it on again.
 
I have 6 variables getting the ID of every slot of equipment:
 
Example:

Variable 42
Script:

$game_actors[2].equips[0].id

 
Then script calls to unequip the equipment (redundant lol)
 

$game_actors[2].change_equip(0, $data_weapons[0]);

 
If the actor has all his slots occupied, everything goes fine.
 
But! When the player has nothing equiped on any slot, and try to unequip it, I get an error:
 

Script 'Game_Interpreter' line 542: NoMethodError occurred.

undefined method 'id' for nil:NilClass

 
Any help? :(
 
Just in case, the script calls used for re-equip the actor is:
 

$game_actors[2].change_equip_by_id(0, $game_variables[42]);

 
------------------------------------------------------------------------------------
 
(Also, is there a way to change this script call:
 

$game_actors[2].change_equip_by_id(0, $game_variables[42]);

to use a variable to get th id of the actor who is getting the equipment again?

Like:
 

$game_actors[$game_variables[6]].change_equip_by_id(0, $game_variables[42]);

or something?

I've tried the above and didn't work, neither if I replace the [] whit ()

 

Greetings!

Share this post


Link to post
Share on other sites

Tank you very much for the answer. Unfortunately it's not the solution I need. I already have a method to get the ID of the equipment and works fine.

The problem is that if the ID I get from any equipment slot is "0", I get the error Previously described.

 

Anyway, thanks for the answer. :)

Share this post


Link to post
Share on other sites

I only used vx a little bit back in the day but from the looks of it:

 

Below: You just equipped weapon of id 0 to slot 0. Which may or may not exist depending on your scripts. Default starts at weapon 1 and so on in the database.

 

 

 

$game_actors[2].change_equip(0, $data_weapons[0]);

 

Below: What you want might be "nil", to unequip what ever is there, like so.

 

 

$game_actors[2].change_equip(0, nil);

Can't really be sure. If only I still have vx~

 

Below: Not really sure what you are asking, but you already have the actor's id. It is $game_variables[6]. Change $game_variables[6] to a number and the actor with that number in the database will be the one changing equipment.

 

 

$game_actors[$game_variables[6]].change_equip_by_id(0, $game_variables[42]);

 

Share this post


Link to post
Share on other sites

You just equipped weapon of id 0 to slot 0. Which may or may not exist depending on your scripts. Default starts at weapon 1 and so on in the database.

 

$game_actors[2].change_equip(0, $data_weapons[0]);

 

Below: What you want might be "nil", to unequip what ever is there, like so.

$game_actors[2].change_equip(0, nil);

 

 

Ok, I just tried this, and still get an error.

 

I remove the scripts that gets the ID of the equipment and the code works fine. 

 

If I use this:

$game_actors[2].change_equip(0, $data_weapons[0]);

or this: 

$game_actors[2].change_equip(0, nil);
Works just fine, the equipment is removed.
 
But, the trouble seems to be the variable getting a "0" or "nil" value when nothing is equipped. That's when I get an error.
 
Hope someones has an idea that can work :(

 

 

 

 

 

-------------------------------------------------------------------------------------------------------------------------------------------------------------

 

Below: Not really sure what you are asking, but you already have the actor's id. It is $game_variables[6]. Change $game_variables[6] to a number and the actor with that number in the database will be the one changing equipment.

$game_actors[$game_variables[6]].change_equip_by_id(0, $game_variables[42]);

 

 

I was asking this because I have many actors, so for every party member and position I have to copy, paste and edit every single script call xD
 
It's something like:
Conditional Branch:
If Variable Party Leader is 1
      Get ID of the equipment of Actor 1
      Change Graphic of Actor 1
      Unequip Actor 1
 If Variable Party Leader is 2
      Get ID of the equipment of Actor 2
      Change Graphic of Actor 2
      Unequip Actor 2

 

 

 
And So on, with all the actors, the again with the second position of the party member. (All actors again)
 
So, If something like this can be done:
 
$game_actors[$game_variables[6]].change_equip_by_id(0, $game_variables[42]);
 
I just need to copy the code and paste it in every conditional branch without editing, and that saves a lot of time XD.
 
 
Anyway, thank You So much for answer!

Share this post


Link to post
Share on other sites

I think what you might need is "error catching". (This is why I prefer using event command over scripting, they catch all the errors for you. :D)

 

Try something like this:

if $game_variables[42] > 0
  $game_actors[$game_variables[6]].change_equip_by_id(0, $game_variables[42])
end

Share this post


Link to post
Share on other sites

First of all, thank you so much for answering this Topic.

 


if $game_variables[42] > 0
  $game_actors[$game_variables[6]].change_equip_by_id(0, $game_variables[42])
end

 

If I'm reading this correct, this script will equip back the actor with the equipment based on the variable, right?
 
But that is not the problem.
 
The thing is, I can take off and on the equipment.
 
But: If nothing Is Equipped, then the slot of equipment checked is "nil", not "0", so the variable gets no value, and then there's the Error (I guess)
 
So, based on that little script you posted, I've tried to make this script call for every slot of equipment (from 0 to 6)
if $game_actors[2].equips[0].id == nil
  $game_variables[42] = 0
else
$game_variables[42] = $game_actors[2].equips[0].id
end

But, I get This Error:

 

Script 'Game_Interpreter' line 1409: NoMethodError occurred.
undefined method `equips' for [2]:Array
I'm using Galv's Simple Debug and I Just realize that the first Variable, 42, which should give a value of 3, gets this value:
 
Variable 42 = #<Game_actors:0x9a6c684>
So, in short, the problem is that when the value of a Empty Equippment Slot is "Nil", I get an error instead of a value "0" for the variable.
 
Thanks for the Help Guys, hope there's a solution for this....

Share this post


Link to post
Share on other sites

 

 

If I'm reading this correct, this script will equip back the actor with the equipment based on the variable, right?

It error catches, if the slot is 0 then it skips that actor. However, it might not be what you are looking for.

 
if $game_actors[2].equips[0].id == nil
  $game_variables[42] = 0
else
$game_variables[42] = $game_actors[2].equips[0].id
end

should be written like this:

if $game_actors[2].equips[0] == nil
  $game_variables[42] = 0
else
  $game_variables[42] = $game_actors[2].equips[0].id
end

Maybe you should just post the entire thing so I can see what exactly you are trying to do.  :P

Edited by Adventurer_inc.

Share this post


Link to post
Share on other sites

Ok, that didn't work either.

 

So, I have RPG Maker in Spanish, so instead of posting a screenshot which not many people would understand xD, I typed the common Event in english so is more easy to understand.

 

First: This is The First Common Event I've Tried:

 

 

Note: This Example is Chequing One Actor, which is on the First Spot in the Party (aka Party Lider)

@>Control Variables: [0006:Party_Lider] = 1st Member's Actors 'ID'
@>Conditional Branch: Switch [0013:Unequiped] == Off
  @>Conditional Branch: Variable [0006:Party_Lider] == 2
    @>Control Variables: [0042:Lider s0] = $game_actors[2].equips[0].id
    @>Control Variables: [0042:Lider s1] = $game_actors[2].equips[1].id
    @>Control Variables: [0043:Lider s2] = $game_actors[2].equips[2].id
    @>Control Variables: [0044:Lider s4] = $game_actors[2].equips[4].id
    @>Control Variables: [0045:Lider s5] = $game_actors[2].equips[5].id
    @>Control Variables: [0046:Lider s6] = $game_actors[2].equips[6].id
    @>Change Actor Graphic: [Eric], 'Civilians',0,'Actor1',1
    @>Script: $game_actors[2].change_equip(0, nil);
    :        :$game_actors[2].change_equip(1, nil);
    :        :$game_actors[2].change_equip(2, nil);
    :        :$game_actors[2].change_equip(4, nil);
    :        :$game_actors[2].change_equip(5, nil);
    :        :$game_actors[2].change_equip(6, nil)
  :  Branch End
  @>##~Comment~##: This Part is repited for every Actor.
  :              : So, if Variable [0006] = 3, that's actor3, and so on.  
  @>Control Switches: Switch [0013:Unequiped] = On
 :  Else  
    @>Conditional Branch: Variable [0006:Party_Lider] == 2
      @>Change Actor Graphic: [Eric], 'Actor1',0,'Actor1',1
      @>Script: $game_actors[2].change_equip_by_id(0, 
              : $game_variables[42]);
              : $game_actors[2].change_equip_by_id(1, 
              : $game_variables[43]);
              : $game_actors[2].change_equip_by_id(2, 
              : $game_variables[44]);
              : $game_actors[2].change_equip_by_id(4, 
              : $game_variables[45]);
              : $game_actors[2].change_equip_by_id(5, 
              : $game_variables[46]);
  @>
   :  Branch End
    @>Control Switches: Switch [0013:Unequiped] = Off
 : Branch End
 

If the Actor has an equipment in every Slot, the common evet works completly fine.

 

But, if the Actor has any Slot Empty, then this error is given:

Script 'Game_Interpreter' line 542: NoMethodError occurred.

undefined method 'id' for nil:NilClass
So I've Tried This One:

 

@>Control Variables: [0006:Party_Lider] = 1st Member's Actors 'ID'
@>Conditional Branch: Switch [0013:Unequiped] == Off
  @>Conditional Branch: Variable [0006:Party_Lider] == 2
    @>Script: if $game_actors[2].equips[0].id == nil
            :   $game_variables[42] = 0
            : else 
            :   $game_variables[42] =  $game_actors
            : [2].equips[0].id
            : end
    @>Script: if $game_actors[2].equips[1].id == nil
            :   $game_variables[43] = 0
            : else 
            :   $game_variables[43] =  $game_actors
            : [2].equips[1].id
            : end			   
    @>Script: if $game_actors[2].equips[2].id == nil
            :   $game_variables[44] = 0
            : else 
            :   $game_variables[44] =  $game_actors
            : [2].equips[2].id
            : end
    @>Script: if $game_actors[2].equips[4].id == nil
            :   $game_variables[45] = 0
            : else 
            :   $game_variables[45] =  $game_actors
            : [2].equips[4].id
            : end
    @>Script: if $game_actors[2].equips[5].id == nil
            :   $game_variables[46] = 0
            : else 
            :   $game_variables[46] =  $game_actors
            : [2].equips[5].id
            : end
    @>Script: if $game_actors[2].equips[6].id == nil
            :   $game_variables[47] = 0
            : else 
            :   $game_variables[47] =  $game_actors
            : [2].equips[6].id
            : end
    @>Change Actor Graphic: [Eric], 'Civilians',0,'Actor1',1
    @>Script: $game_actors[2].change_equip(0, nil);
    :        :$game_actors[2].change_equip(1, nil);
    :        :$game_actors[2].change_equip(2, nil);
    :        :$game_actors[2].change_equip(4, nil);
    :        :$game_actors[2].change_equip(5, nil);
    :        :$game_actors[2].change_equip(6, nil)			   	   
  :  Branch End
    @>Control Switches: Switch [0013:Unequiped] = On
 :  Else  
    @>Conditional Branch: Variable [0006:Party_Lider] == 2
      @>Change Actor Graphic: [Eric], 'Actor1',0,'Actor1',1
      @>Script: $game_actors[2].change_equip_by_id(0, 
              : $game_variables[42]);
              : $game_actors[2].change_equip_by_id(1, 
              : $game_variables[43]);
              : $game_actors[2].change_equip_by_id(2, 
              : $game_variables[44]);
              : $game_actors[2].change_equip_by_id(4, 
              : $game_variables[45]);
              : $game_actors[2].change_equip_by_id(5, 
              : $game_variables[46]);
	   @>
  	:  Branch End
    @>Control Switches: Switch [0013:Unequiped] = Off
 : Branch End
Which Gives This Error, even when the Actor has all slots of equipment occupied:

 

Script 'Game_Interpreter' line 1409: NoMethodError occurred.
undefined method `equips' for [2]:Array
Hope I didn't mess up with the transcribed Events xD Edited by Kanonelsebas

Share this post


Link to post
Share on other sites

I've tried the script you posted, but get the same error:

Script 'Game_Interpreter' line 1409: NoMethodError occurred.
undefined method `equips' for [2]:Array
The strange thing is, with that script the variable don't get any value at all. The common event doesn't work.
 
The first one does, but get an error when 'nil' is a value.
 
I don't know what else try...

Share this post


Link to post
Share on other sites

I found your problem instead of fixing, I took it a step forward and wrote a snip.

Copy/Paste it under material. No credit needed, even claim it as your own if you want since I don't write scripts for public use, especially not custom ones.

 

You problem was slots. Default is 5 and you had 6, but you script it as 5 and 6.

#==============================================================================
# ** Equip Stuff Advance **
#
# Description: Works regardless of how many slots you are using.
#
# Calls: 
# unequip_everything_adv(game_actor, [var1, var2, var3, var4, var5])
# reequip_everything_adv(game_actor, [var1, var2, var3, var4, var5])
#
# "game_actor" is the number of the actor in the database
# "var1, etc." is the number of the variable you want to save the slot in
# Add or subtract slots as needed 
# EX: 4 slots
# unequip_everything_adv(game_actor, [var1, var2, var3, var4])
# EX: 6 slots
# unequip_everything_adv(game_actor, [var1, var2, var3, var4, var5, var6])
#==============================================================================
class Game_Interpreter
  # This unequips from actor and saves it in the variables.
  def unequip_everything_adv(actor,variable)
    num = variable.size
    num.times {|i| $game_variables[variable[i]] = 
     ($game_actors[actor].equips[i] == nil ? 0 : 
     $game_actors[actor].equips[i].id) 
     $game_actors[actor].change_equip(i,nil)
    }
  end
  # This takes all the variable above and equip it to actor
  def reequip_everything_adv(actor,variable)
    num = variable.size
    num.times {|i| 
     $game_actors[actor].change_equip_by_id(i,$game_variables[variable[i]])
    }
  end
end

The calls are as friendly as I can make them.

 

 

To accomplish exactly what you got above this is how it would look like: error free this is what it will look like if you have 6 equipment slots

@>Control Variables: [0006:Party_Lider] = 1st Member's Actors 'ID'
@>Conditional Branch: Switch [0013:Unequiped] == Off
@>Conditional Branch: Variable [0006:Party_Lider] == 2
@>Script: unequip_everything_adv($game_variables[6], [42, 43, 44, 45, 46, 47])

@>Control Switches: Switch [0013:Unequiped] = On
: Else
@>Conditional Branch: Variable [0006:Party_Lider] == 2
@>Change Actor Graphic: [Eric], 'Actor1',0,'Actor1',1
@>Script: reequip_everything_adv($game_variables[6], [42, 43, 44, 45, 46, 47])

@>Control Switches: Switch [0013:Unequiped] = Off
: Branch End

This is what it will look like if you have 5 equipment slots:

---- Only showing scripts
@>Script: unequip_everything_adv($game_variables[6], [42, 43, 44, 45, 46])
----
@>Script: reequip_everything_adv($game_variables[6], [42, 43, 44, 45, 46])
----

This is what it will look like if you have 10 equipment slots: (make sure you have those variables available)

--- Only showing scripts
@>Script: unequip_everything_adv($game_variables[6], [42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52])
---
@>Script: reequip_everything_adv($game_variables[6], [42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52])
---

Note: Scripts are a complete last resort for me. However, I didn't know if you had 5 or 6 slots. :D

I can do a common event version for you if you want, but it won't be able to change slot numbers.

Edited by Adventurer_inc.

Share this post


Link to post
Share on other sites

I found your problem instead of fixing, I took it a step forward and wrote a snip.

Copy/Paste it under material. No credit needed, even claim it as your own if you want since I don't write scripts for public use, especially not custom ones.

First of all, I have no words to thank you enough that you've taken the time to write a script to help me solve the problem.

 

I could finally take the time to try it, and it works beautifully. No more popping out errors.

 

If you do not mind, if I have any complications, I will be in contact via MP, as this Topic can be closed as Solved.

 

You problem was slots. Default is 5 and you had 6, but you script it as 5 and 6.

(I feel kind of Dumb, Since I should have warned I've used a "Extra Slots" Script

I realize just now lol.)

 

Actually, I have 7, but one was taken away individually xD

 

The calls are as friendly as I can make them.

Don't worry, they are completely easy to understand.

 

Note: Scripts are a complete last resort for me. However, I didn't know if you had 5 or 6 slots. :D

I can do a common event version for you if you want, but it won't be able to change slot numbers.

No problem, I get it from the example you left.

 

No credit needed, even claim it as your own if you want

Does people actually Do that? I mean, taking credit from a Script they didn't write? That's just low.

 

And You, My dear Sir, gonna get all the credit, I can't thank you enough! xD

 

Thank you for your help, guys!

 

So Happy xD

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.

  • Recently Browsing   0 members

    No registered users viewing this page.

×