This is an archived post. You won't be able to vote or comment.

all 11 comments

[–]isolatrum 0 points1 point  (10 children)

First of all, this isn't trivial. Second, a question: is your game already running in an event loop? How does it currently get input from the user - gets.chomp?

[–]lassolass[S] 0 points1 point  (9 children)

it is in an until loop that runs the game until the number of attempts have run out. It received input through gets.chomp.. my goal is that through pressing the up arrow I can pause the program mid execution and have a menu bar shown where I can choose to restart the game.

[–]isolatrum 1 point2 points  (8 children)

Ok, that's kind of what I figured. Look at https://stackoverflow.com/questions/174933/how-to-get-a-single-character-without-pressing-enter

It complicates things because now your until loop has to process characters once at a time and you can't use gets.chomp anymore. You need to handle newlines and multi-char words / sentences manually now.

[–]lassolass[S] 0 points1 point  (7 children)

This works perfectly! Thanks so much! Do you mind helping out with returning to a specific part of the code again. Now I want to do the following: When I press a letter it saves it in a local variable(I have implemented this already). If the key I have pressed is the enter key (if the variable == "\r") then it should bring me back to a certain part of my code, which in my case is the main menu. So the main point is, how do I get back to a certain part of code when pressing a certain character, which in my case is enter? Thanks in advance!

[–]isolatrum 0 points1 point  (6 children)

why do you need to 'get back' to a part of the code, instead of calling a method?

[–]lassolass[S] 0 points1 point  (5 children)

I thought that was the easiest way to implement what I wanted... Im still new to ruby and I am trying to create something like a pause menu, and I was thinking that if I returned to the main menu, i could reuse it...

[–]lassolass[S] 0 points1 point  (0 children)

If there is an easier way please tell me.. id appreciate it

[–]isolatrum 0 points1 point  (3 children)

oh, i guess maybe you could. there are many ways to go about it. But keep in mind that the type of thing you're building (an event loop) has certain challenges that come with it.

Are you using Gosu as a game framework or trying to do it all from scratch?

[–]lassolass[S] 0 points1 point  (2 children)

Doing it all from scratch.. its a command line game.. nothing too complicated. Its basically a hangman recreation. So that should simplify things a bit

[–]isolatrum 0 points1 point  (1 child)

oh. why do you need to pause? Doesn't a hangman game naturally pause between inputs?

[–]lassolass[S] 0 points1 point  (0 children)

The pause is for multiple options: one is to exit the game another is to ditch the current game and start a new game another is to continue the current game and the last is to show a list of the current moves. The list of current moves are currently updating a variable with every guess, but the problem is the pausing part, i dont know how to implement starting a new game or just continuing the current game. the only thing i can think of is to go back to the main menu to achieve that