Set Handlers

I have some questions about the commands and set handlers. First off, I was able to base using shortcuts to hashes to get their values to make the commands displayed without getting too much in trouble:

First, I created a hash:

module HeartFire Foods = { "Bacon" => {:bacon => $food_num = 1}, "Eggs" => {:eggs => $food_num = 2}, "Hamburger" => {:hamberger => $food_num = 3} }endand on the add_commands I tried doing it like this:

#-------------------------------------------------------------------------- # * Add Main Commands to List #-------------------------------------------------------------------------- def add_main_commands HeartFire::Foods.each_key { |i| add_command(i, :foods) } end so every commands are automatically displayed on the commands. My only problem is how can I upgrade my hash so it can also display the ones in the set_handler on the menu?

If so, how?
I don't understand your question.

My only problem is how can I upgrade my hash so it can also display the ones in the set_handler on the menu?
"the ones"?
I'm asking for the way to make the set handlers like the ones in the add_command that i did.

HeartFire::Foods.each_key { |i| add_command(i, :foods) }for example. I tried doing

HeartFire::Foods.each_key { |i| set_handler(i, :foods) }before but it doesn't work.
where did you get/set :foods?


take a good look for now of how the set_handler is used will yah?
the :foods was set for the entire command. The ones I access as a whole, but i am still doubtful how I can use it because no matter how many options I add in it the results won't actually come up.
I really think your set_handler method was wrong... I think it was set_handler(key,method)... yours was kind of set_handler(name,key)


PS: since your commands share the sme key 🙂foods) if you manage to set this up, all of those commands will be using just 1 method. You don't even need to loop thru the hash since the key is what matters in a handler, and right now, you are using the same key for all of those commands.
def add_main_commands HeartFire::Foods.each_key { |i| add_command(i, :bacon) add_command(i, :eggs) add_command(i, :hamburger) } end this should be the case, right?

Yes, my only problem was how to make the set handler though.
def add_main_commands HeartFire::Foods.each_key { |i| add_command(i, :bacon) add_command(i, :eggs) add_command(i, :hamburger) } end
 That... will make three commands for each key. That script will be equivalent with this:

Code:
add_command("Bacon", :bacon)add_command("Bacon", :eggs)add_command("Bacon", :hamburger)add_command("Eggs", :bacon)add_command("Eggs", :eggs)add_command("Eggs", :hamburger)add_command("Hamburger", :bacon)add_command("Hamburger", :eggs)add_command("Hamburger", :hamburger)
Actually, just make the hash a simple command mapping.

Code:
module HeartFire  Foods = {  "Bacon" => :bacon,  "Eggs" => :eggs,  "Hamburger" => :hamberger,  }end
then add the command:
Code:
  def add_main_commands    HeartFire::Foods.each { |key, value|      add_command(key, value)    }  end
and set handler for OK to a function (This is done in a scene).
Code:
def create_food_window  @food_window = Window_Food.new  @food_window.set_handle(:ok, method(:on_food_ok))end
Then in the same scene, create a method on_food_ok, that will handle the value returned from @food_window.
Code:
def on_food_ok  case @food_window.current_symbol  when :bacon    $food_num = 1  when :eggs    $food_num = 2  when :hamberger    $food_num = 3  endend
If you want to mimic the style in Item Menu scene (that updates the display when scrolling through category) though, that is a bit more complicated.
or you can opt to

@food_window.set_handler🙂bacon,method🙂on_bacon))@food_window.set_handler🙂eggs,method🙂on_eggs))Meaning if you want to put it to the hash too, you'd need to have the method symbols on the hashPS: the handler should be a method of the Scene or a class/module method that is denoted by it's class instance or module name
That solved a lot ShadowLurk!. Thanks for solving the prob! Mods can close this now.

Now I know what to do with the ones I am doing.

Original thread: https://forums.rpgmakerweb.com/threads/set-handlers.24733/