Not logged inGosu Forums
Forum back to libgosu.org Help Search Register Login
Up Topic Gosu / Gosu Exchange / beginner's question
- - By bob8166 Date 2011-11-12 03:26
I wanna add Tutorial's score function in CptnRuby which is in examples,

but it says score is undefined when running,

and display text :
CptnRuby.rb:238: syntax error, unexpected $end, expecting keyword_end
Parent - - By jlnr (dev) Date 2011-11-12 12:12
It means you have forgotten one end somewhere. (It found the "$end" of the file, but expected end.)
Parent - - By bob8166 Date 2011-11-12 12:39
but now it says

CptnRuby.rb:226:in draw': undefined method score' for nil:NilClass (NoMethodError)

I just combine score counting in Tutorial and CptnRuby
Parent - - By Quit Date 2011-11-12 12:54
Could you perhaps upload your code somewhere?
Parent - - By bob8166 Date 2011-11-12 14:24
Parent - - By jlnr (dev) Date 2011-11-12 14:25
You can attach files to your postings in this forum (but only after posting).
Parent - By Jwosty Date 2011-11-12 14:29
Wow. Twice in a row someone beats me to posting :P
Parent - By RavensKrag Date 2011-11-16 07:11
Or for code, you could use a gist, or pastebin.   That would be more convenient than one of those filesharing websites.
Parent - By Jwosty Date 2011-11-12 14:28
Awesome, looking for a problem. Also, you know you can attach files directly to your post after you post it. ;)
Parent - By Quit Date 2011-11-12 14:35
Like the others said, you can attach your file directly. I'm no Ruby wizard, but I'll tell you one thing already: I'd use proper indention. It makes reading scripts so much easier and you won't have those bugs you are experiencing right now.
Parent - By Jwosty Date 2011-11-12 14:33
Huh, didn't find anything. I'll try looking at it through IntelliJ
Parent - By Jwosty Date 2011-11-12 14:52
As for the first problem, I figured out that the problem code is in line 226. It happens because you never set @CptnRuby to anything, so it is nil by default. And, you never even define a score method anywhere, so it says that you never defined it for nil. Perhaps you meant to type @score?
----
I'll try this in a second and see what I get.
Parent - - By Jwosty Date 2011-11-12 14:54
Tried this and it didn't exit with any errors. When I played it, the collisions were WAY off... Do you want me to attach the fixed file?
Parent - - By bob8166 Date 2011-11-12 15:07
thanks for helping and i would like to see the fixed one,could you please attach it.

I thought class CptnRuby contain score,then CptnRuby.score will work.

Now i knew that the forum can attach,and I am wondering what other software can run Ruby I'm still using CMD.
Parent - - By Jwosty Date 2011-11-12 15:14
Yeah, sure!

Also, when referencing to classes, don't prefix it with @. This means it's an instance variable, like your score. But using CptnRuby.score won't work until you define that method. It isn't defined right now. Fixing this right now for you; I'll attach it when done. Should take longer than a minute total. :)

Well I assume you want to be able to run it by double-clicking on the file like you would an executable. If so and you're on a Windows computer, you should already be able to do just that. If not, then try writing a shell script for it. Need an example?
Attachment: CptnRuby.rb.zip - There we go! (3k)
Parent - - By bob8166 Date 2011-11-12 15:31 Edited 2011-11-12 15:39
thank you!

I can see the score now, and i will try to fix collisions by myself.

thanks again for helping!!
Parent - - By Jwosty Date 2011-11-14 03:00
No problem! ;)

Sorry it took so long to reply though; I've been busy
Parent - - By bob8166 Date 2011-11-16 10:23
I would like to turn the file into .exe, hence I searched for it and found exerb.

But it doesn't work. I think it doesn't create .bat in the folder bin.

Do you know the solutions or other ways to turn to executable?
Parent - - By bob8166 Date 2011-11-16 14:31
I gonna change the icon.but it can not work..

C:\Ruby191\123>ocra --icon <DISTLSTL.ico> CptnRuby.rb

C:/Ruby191/lib/ruby/gems/1.9.1/gems/ocra-1.3.0/bin/ocra:381:in parseargs': undefined method exist?' for nil:NilClass (NoMethodError)
        from C:/Ruby191/lib/ruby/gems/1.9.1/gems/ocra-1.3.0/bin/ocra:447:in init'
        from C:/Ruby191/lib/ruby/gems/1.9.1/gems/ocra-1.3.0/bin/ocra:1129:in
<top (required)>'
        from C:/Ruby191/bin/ocra:19:in load'
        from C:/Ruby191/bin/ocra:19:in
<main>'
Parent - - By jlnr (dev) Date 2011-11-16 14:41
It should work without the <> (unless you named the file that way, which would be dangerous as those are reserved characters).
Parent - By bob8166 Date 2011-11-16 14:51
...quite simple

thanks a lot!
Up Topic Gosu / Gosu Exchange / beginner's question

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill