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.

Command Window Options by Name

I wouldn't stuff the title, so here goes a more in-depth explanation: I'd like to replace the following code ...

Code:
case @command_window.index
when 0
  # execute
when 1
  # execute
end

... with a code that asks for the name of the option that's highlighted. I tried that code (doubting it'd work, and expectedly, it didn't):

Code:
case @command_window.commands[index].to_s
when "Option 1"
  # execute
when "Option 2"
  # execute
end

I've seen something back in time in the old forums, but now is the first time I actually need it :P

Thanks in advance.
 
Add this into Window_Command before the initialize method:
Code:
attr_reader :commands
It should work now by using:
Code:
case @command_window.commands[@command_window.index]
when "Option 1"
  # execute
when "Option 2"
  # execute
end
 
Hell, it really was that simple? ^_^ Thank you, that's the second time you helped me out ... you're doing a CBS for me? :D (just kiddin ;) Strangely, I made huge process in that sector ^_^ )

This thread is resolved for me, but just for the sake of perfectionism, is there any way to check for the phrases that the commands are aligned to (by default i.e. s1[/blue]) ?
 
You mean what variable they are stored in?

You could if you made them instance variables, like @s1, @s2, etc. Then check if they are the current selected word by using:
Code:
case @command_window.commands[@command_window.index]
when @s1
  #code
when @s2
  #code
end
I think that's what you meant, and it should work.
 

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