Wrappng up my Text Game! Need Help!

Hi, everyone. This is my first post!

Very quick background: I decided I wanted to learn Ruby so I could use
Watir to make some bots for my business to automate some repetitive
tasks. I was directed to “Learn Ruby the Hard Way” and went through the
program. At the end we are made to create a text based role playing
game. So I did, and with some help of others on an unrelated forum, I
managed to get my game to run in Terminal.

Here is the code : Game · GitHub

So after I finished that, I celebrated, but that wasn’t enough. I
wanted to share it. So I started researching compiling. I learned that
what I really wanted to do was create an application bundle so I could
pass it out to friends without them going through the hassle of
installing ruby, etc. And I wanted to be able to have a Windows and a
Mac version.

tar2rubyscript, rubyscript2exe, allinoneruby, crate… These are
supposed to be cross platform exectuable makers, but after spending
about 3 hours messing with the first three I learned how they are broken
and found some fixes, but they did not work. I learned it was somewhat
abandoned for Ocra, which helps me with Windows, but not Mac. I
couldn’t figure out Crate to be honest.

So I eventually found Platypus! Very cool program. Seems to do exactly
what I need, and it even encrypts the code (is this going to be enough
to actually protect my code from prying eyes?) So I’m trying to solve
this Mac problem first. I’ve created an application bundle that runs
but meets this error:

/Users//Desktop/Guardians At The
Threshold.app/Contents/Resources/script:98:in beginning_room': private method chomp’ called for nil:NilClass (NoMethodError)
from /Users/
/Desktop/Guardians At The
Threshold.app/Contents/Resources/script:629:in send' from /Users/*/Desktop/Guardians At The Threshold.app/Contents/Resources/script:629:in runner’
from /Users/*/Desktop/Guardians At The
Threshold.app/Contents/Resources/script:635

I don’t understand why this runs in Terminal but doesn’t in the
Application. I’d say that I’ve jumped in way over my head, but I really
want to be able to pass this around. Can you guys give me any insight
or help? Anyone using Platypus successfully?

Thanks a ton!

On Apr 26, 2012, at 08:26 , Jared Hobbs wrote:

So after I finished that, I celebrated, but that wasn’t enough. I
wanted to share it. So I started researching compiling.

Why?

W dniu 26 kwietnia 2012 22:00 użytkownik Ryan D.
[email protected] napisał:

On Apr 26, 2012, at 08:26 , Jared Hobbs wrote:

So after I finished that, I celebrated, but that wasn’t enough. I
wanted to share it. So I started researching compiling.

Why?

W dniu 26 kwietnia 2012 17:26 użytkownik Jared Hobbs
[email protected] napisał:

so I could
pass it out to friends without them going through the hassle of
installing ruby, etc.

@Jared: I have never used Platypus, but it seems like it’s not passing
the input you might type into the console window to the Ruby script.
Thus the result of “gets” is “nil”, and the error you described
happens. Why is it doing this, I have no idea - maybe try asking on
its forum or list or whatever.

– Matma R.

Hmmm, you guys got any other suggestions that could handle user input?
For the Mac?

On Apr 26, 2012, at 13:48 , Bartosz Dziewoński wrote:

@Jared: I have never used Platypus, but it seems like it’s not passing
the input you might type into the console window to the Ruby script.
Thus the result of “gets” is “nil”, and the error you described
happens. Why is it doing this, I have no idea - maybe try asking on
its forum or list or whatever.

That’s correct. I just verified this by creating a simple platypus
bundle with the script ‘p gets’.

It really doesn’t seem to be meant for user input.

You should try shoes, and have a look at samples/expert-irb.rb[1]

1: shoes-deprecated/samples/expert-irb.rb at develop · shoes/shoes-deprecated · GitHub

On Thu, Apr 26, 2012 at 8:10 PM, Eric C.

On Thu, Apr 26, 2012 at 6:41 PM, Jared H. [email protected] wrote:

Hmmm, you guys got any other suggestions that could handle user input?
For the Mac?

I’m thinking Shoes could do the trick, if you want to learn a little
extra (but it’s supposed to be really easy). The only thing is I don’t
know if it has a terminal widget. Perhaps someone else here knows.

In the end, you guys were right. Shoes will do what I want for now, but
it’s not going to be the solution forever. I’ll accept it on this text
game. I talked to someone today who sent me a link to…

He hasn’t used it but it’s another option to try.

I’ll share my game when it’s all said and done with Shoes. Thanks!

Okay guys, question about Shoes:

I’ve built a basic set up for the game like this:

Shoes.app :title => “Guardians at the Threshold”,
:width => 700, :height => 700, :resizable => false do

azure = rgb(240, 255, 255)
background azure

stack do
background black, :height => 25
caption “<> <> <> Guardians at the Threshold <> <> <>”, :align
=> “center”,
:stroke => white
end

stack :height => 635, :margin => 30, do
# RUN PROGRAM HERE?
end

flow :height => 29 do
background black
caption " Progress: “, :stroke => white
@p = progress :width => 0.5, :margin_top => 0.1
caption " __%”, :stroke => white
animate do
@i = 0.1
@p.fraction = @i
end
end
end

That’s all fine and dandy. But this my game is a long piece of code:

My question is, I have the game fully coded out in standard Ruby and it
runs in terminal. I know I won’t be able to simply call the class or
whatever and run it perfectly as it is. Ruby uses “puts” and Shoes uses
“para”. Ruby uses “sleep” and Shoes uses “timer” and a do loop for it.

It’s not going to be as simple as doing a find > replace all. I want to
make it so each “room” appears on the screen, and there is an
“edit_line” box that appears for the user to punch in the number they
choose.

Is it going to be possible to have this run without doing a massive
rewrite or am I screwed on this?

Hell, as much as I like the way this looks, I’d be happy to just package
up ruby and my code into an app if I could figure out how to make it
open up a terminal for the user, and could find a app bundler.

If you guys have any insight before I waste tons of time, that’d be
awesome. Thanks for the help.

Ashbb,

Thank you for this! You managed to do what I was asking, saving tons of
time. I’m going to see if I can use your idea to take it closer to what
I was already doing with “red shoes” I think. Whichever the main shoes
is. If not, I’ll just roll with your idea. Solid work! I’ll report
back with my progress!

Hi Jared,

this my game is a long piece of code: Game · GitHub
Cool!

Is it going to be possible to have this run without doing a massive
rewrite or am I screwed on this?
Oh, umm,…
I’m not sure this is what you want to do…
But look at this: Text Game on Purple Shoes · GitHub
and read the comment: Text Game on Purple Shoes · GitHub

Okay guys, question about Shoes:
Yes, Shoes!
If you post your question to Shoes ML
(http://librelist.com/browser/shoes/),
you will get more help by many Shosers. :wink:

ashbb

On Sun, Apr 29, 2012 at 9:07 PM, Jared H. [email protected] wrote:
[…]

Game in Shoes and Ruby · GitHub
[…]
/Applications/Shoes.app/Contents/MacOS/lib/shoes.rb:435:in ‘eval’
/Applications/Shoes.app/Contents/MacOS/lib/shoes.rb:435.in ‘visit’
/Applications/Shoes.app/Contents/MacOS/lib/shoes.rb:124:in
‘show_selector’
(eval):1:in '"

reincarnation is an instance method of Map, not a class method, so you
need to either make it a class method (by defining it with def self.reincarnation ...), or call it with a Map instance as receiver.

Okay guys, again, I thank you for helping me!

Ashbb,
I ended up converting everything I could to the standard Shoes
language because I wanted the nice GUI interface to pop up. I liked it
more than what you had going with Purple Shoes, but that sent me in the
right direction.

There is my code at this point. I debugged about 100 errors, which
finally has it running in Shoes somewhat. The GUI window pops up and it
tries to run, but I’m still getting some errors. I know that I have the
window not allowed to be resized, and I want to strategically place some
“clear()” around to kind of refresh the middle stack.

I also still want to get the progress bar on the bottom moving
correctly. But I figured I’d get to that once the main part runs
correctly.

I’m to the point now where i have no clue what the errors mean. I
wonder if I need to pass “app” and “self” around, but again its beyond
me at this point. I’ve reached my limit and need help. When I run it
at this point I get the following errors:

undefined method ‘reincarnation’ for Map:Class
GameBuild.rb:15:in ‘blcok (2 levels) in ’
GameBuild.rb 13:in ‘call’
GameBuild.rb 13:in ‘stack’
GameBuild.rb:13 ‘block in ’
(eval):1:in ‘instance_eval’
(eval)1:in ‘block in’
GameBuild.rb:1:in ‘call’
GameBuild.rb"1in ‘app’
GameBuild.rb:1in ‘’
/Applications/Shoes.app/Contents/MacOS/lib/shoes.rb:435:in ‘eval’
/Applications/Shoes.app/Contents/MacOS/lib/shoes.rb:435.in ‘visit’
/Applications/Shoes.app/Contents/MacOS/lib/shoes.rb:124:in
‘show_selector’
(eval):1:in '"

Haaaaaaalp!!!
Thank you guys for your continued help. I really appreciate it.

Hi Jared,

undefined method ‘reincarnation’ for Map:Class
About this error, Eric has already answered.

But wait a little bit before you go ahead. :wink:
I think you need to know the following two things about Shoes.

1st: Try out this snippet.

class Test
def hello
para ‘hello’
end
end

Shoes.app do
Test.new.hello
end

Yeah,… it doesn’t work well.
You’ll get an error “undefined method ‘para’ for (Test):Test” on the
Shoes
Console window.

The following is one of solutions.

class Test
def initialize app
@app = app
end
def hello
@app.para ‘hello’
end
end

Shoes.app do
Test.new(self).hello
end

2nd: Try out another snippet.

Shoes.app do
def test_run
stack do
timer(5){para ‘first’}
timer(3){para ‘second’}
timer(1){return ‘third’} # line 6
end
end
ret = test_run # line 9
para ret
end

You’ll see the output: (Shoes::Stack) second first

Because, timer() method forks a new thread, but doesn’t wait for the
thread
to end.

And you’ll get an error on Shoes Console Window: Unexpected retrun

Because, when Shoes executes the line 6: “return ‘third’”, the test_run
method at line 9 has already ended.

I wanted the nice GUI interface to pop up.
Fantastic!
I think Shoes is a good choice!
Although there are a few specific behaviors for GUI programming. :wink:

Let’s have fun with Shoes,
ashbb

Ash!

I just saw this! It looks so awesome! Thank you for working on this
with me! You are teaching me and saving me tens of hours of
frustration. I will review your code to figure out what you did and get
back to you!

Goals:

  1. Get the screen to clear after each text entry.
  2. Have the text entries be edit_line’s instead of the ‘>’ prompt
  3. Get the progress bar to work!
  4. Create an intro screen with an image before the game begins!
  5. Possibly play a background song? (Is this possible with Shoes?)

Any comments while I keep chugging are greatly appreciated!

Jared

Hi Jared,

Wow, Cool! Great goals!

  1. Possibly play a background song? (Is this possible with Shoes?)
    Ah,… bloopsaphone is available on Shoes.
    But I’ve tested it only on Windows. Look at Gallery No.14 (*1).

Enjoy ruby programming with Shoes! :smiley:

ashbb

ps. If you have any more questions about Shoes, Shoes ML (*2) may be the
best place.

*1:
http://shoes-tutorial-note.heroku.com/html/01130_Fancy_Gallery_11-15.html
*2: http://librelist.com/browser/shoes/

Hi Jared and folks,

I came up with an idea for Red Shoes. :wink:

Try this out: Text Game on Red Shoes · GitHub

A little demo:
http://www.rin-shun.com/shoes/text-game-on-red-shoes.swf.html

Hope you like it,
ashbb

Hey Ash, I’m trying to run this last version you uploaded. I downloaded
the files into one folder on my desktop and tried to open text_game.rb
with shoes and it didn’t work. I tried all three files actually. It
says “cannot infer basepath”. I’m guessing I have to put the files in a
specific location?

Also, I hit you up on Twitter :slight_smile: