Status
Not open for further replies.

Zelfore

Villager
Member
Joined
Apr 5, 2019
Messages
9
Reaction score
0
First Language
English
Primarily Uses
RMVXA
I've been scouring the internet for an answer to this for awhile with no clear result, so I'll make it as clear as possible so there's no confusion.

I need a way/method to hide/remove/disable the Items Command while in the middle of a battle (imperative), and also to turn it back on again (less important). Also, unless there's a pre-built-in script call to remove :item from the commands list after it's added, that won't work for this.

If "Items" is just not selectable without a toggle of some sort, that's fine too (if not better).

I've been experimenting with Yanfly Battle Commands a bit, but yielded no clear results. Closest I got is:
Code:
return if $game_switches[98] = false
add_item_command
The only conclusion being if I set it to FALSE, "Items" option appears. Set it to TRUE, "Items" doesn't appear. Either way it disregards whether the switch[#98] is actually on or off, before or in battle.

I'm willing to try this with or without an additional material script, so any help or suggestions are welcome.
 

Heirukichi

Veteran
Veteran
Joined
Sep 24, 2015
Messages
1,421
Reaction score
600
First Language
Italian
Primarily Uses
RMVXA
That happens because the syntax in your code is wrong. You have been using
Code:
$game_switches[98] = false
which is an assignment and, as every assignment, it returns the value that has been assigned (in your case false).

If you look at it from the perspective of the "if" statement before it, it looks like this:
Code:
return if false
This is never true because the whole condition is simply false by default. After that line is executed you simply have switch 98 set to false no matter what. Similarly, if you set the switch as true, the assignment returns true.

What you should be doing is check if the said switch is true, and you can do it like this:
Code:
return if ($game_switches[98] == true)
# or
return if $game_switches[98]
Since switches store boolean values, the second statement is the same as the first one. When the switch is true, the result of "$game_switches[98]" is true, conversely, when false, the result is false.

However, it is always a bad idea to change a method that has already been written in a script, regardless of who wrote the original script. You might forget that you changed it one day and issues might arise. If that happens, pinpointing the cause becomes much harder. A much better solution is that of adding a small script below the one you want to modify and alias the method with a new one. It will be absolutely compatible and, should any issue arise, it is easy to see and comment.

To do that you can add the return line to the add_item_command method itself.
Code:
#------------------------------------------------------------------------------
# ** Window_ActorCommand class
#------------------------------------------------------------------------------
class Window_ActorCommand
  #----------------------------------------------------------------------------
  # * Add Item Command
  #----------------------------------------------------------------------------
  alias hrk_add_item_command_old add_item_command
  def add_item_command
    return if $game_switches[98]
    hrk_add_item_command_old
  end # Add Item Command
end # end of Window_ActorCommand class
 

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,305
Reaction score
11,732
First Language
English
Primarily Uses
RMVXA
[move]Learning Ruby and RGSSx[/move]
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
6,137
Reaction score
7,328
First Language
Indonesian
Primarily Uses
RMVXA
Or if you don't want to hide/remove it, instead make it grayed out, you can always do this
Code:
  def add_item_command
    add_command(Vocab::item, :item, $game_switches[98])
  end
Depends on what you need, you can flip the condition like
Code:
  def add_item_command
    add_command(Vocab::item, :item, !$game_switches[98])
  end
 

Zelfore

Villager
Member
Joined
Apr 5, 2019
Messages
9
Reaction score
0
First Language
English
Primarily Uses
RMVXA
Thank you both, Heirukichi and TheoAllen, this is exactly what I've been looking for!
I've also learned a lot from this as well, especially about script etiquette. This will make things much smoother going forward.
 

mlogan

Global Moderators
Global Mod
Joined
Mar 18, 2012
Messages
15,959
Reaction score
8,872
First Language
English
Primarily Uses
RMMV

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

 
Status
Not open for further replies.

Latest Threads

Latest Profile Posts

oddly enough, at this point... 3 major things have kept me from porting my project to MZ... animations, and that's mainly because they don't match the artstyle of my game. and two... I NEED a YED Sideview Battler like plugin and I have yet to see one. 3rd, I don't have the money for all the stuff I need plugin wise. and I already have it on MV... lol
Generally speaking, would there be interest in some form of tutorial regarding general project management? I see there are a lot of indie/self-taught devs around here, and looking back i feel like there was a lack of resources on how to properly manage a project that might take several years to finish
I've been working on some ABS team A.I. for 'A New Suburbia', and thought I'd share.

I'm generally quite please although the AI is a little grenade heavy right now :rolleyes: - Sneaking and stalking next! Please excuse the terrible map... it was just for ease of viewing!
Voting for the second round of the Map Madness Tournament is now live! Vote for your favorite in each matchup! https://forums.rpgmakerweb.com/index.php?forums/map-madness-2021-polls.187/
Just bought the Visustella All Waves bundle... Time to go IN!!

Forum statistics

Threads
110,577
Messages
1,054,356
Members
143,693
Latest member
speedylmao
Top