Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

[Resolved]Enable Items

Status
Not open for further replies.
Okay... so I'm making a script, and I need something to shorten the code. I need the lines to make it so that an in-game variable makes items enabled in a command window. For example, if variable is 0, none of the items will be selectable. If the variable is 15, item 15, and all the command numbers below 15 will be selectable.

How can this be done?
 
I'd suggest using a loop...

Code:
for i in 0..@variable.size # replace @ with your variable identifier and variable with your variable
  @command_window.disable_command(i)
end

Untested, though...
 
What is your entire code?

Lets say this is your command window creation:

Code:
commands = []
for i in 1...$data_items.size
  commands << $data_items[i].name
end
command_window = Window_Command.new(160, commands)
for i in 0..variable
  command_window.disable_command(i)
end

Is that what you are trying to do?
 
Code:
class Window_Command
  def disable_items(indexes)
    case indexes
    when Integer
      (0..indexes).each {|i| disable_item(i) }
    when Array
      indexes.each {|i| disable_item(i) }
    end
  end
end

Usage..
Code:
#To disable the first 3 items call this..
@command_window.disable_items(2)

#To disable items that are not in series use an array like this..
@command_window.disable_items([0, 2, 4])
It should be easy enough to modify to what you want.
 
This topic has been resolved. If Dark Ruby or any other users have any questions or further problems regarding this topic, please create a new thread about them.

Thank you!
 
Status
Not open for further replies.

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top