[MacRuby-devel] NSTimer.timerWithTimeInterval ?
Hi, Noob to both MacRuby and Cocoa/Objective-C here (but not Ruby) so please forgive is this is obvious but when I try to call timer = NSTimer.timerWithTimeInterval(60, self, 'recheckAndUpdateTitle:', nil, true) NSRunLoop.currentRunLoop.addTimer(timer) I get: undefined method `timerWithTimeInterval' for NSTimer:Class (NoMethodError) which is very confusing given: http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSTimer_Class/Reference/NSTimer.html#//apple_ref/occ/cl/NSTimer and http://stackoverflow.com/questions/1449035/how-do-i-use-nstimer What am I missing here? Any advice appreciated!? -- Thanks in advance, /Robert Feldt ___ MacRuby-devel mailing list [email protected] http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
Re: [MacRuby-devel] NSTimer.timerWithTimeInterval ?
On Nov 7, 2011, at 11:33 AM, Robert Feldt wrote: > Hi, > > Noob to both MacRuby and Cocoa/Objective-C here (but not Ruby) so > please forgive is this is obvious but when I try to call > > timer = NSTimer.timerWithTimeInterval(60, self, > 'recheckAndUpdateTitle:', nil, true) > NSRunLoop.currentRunLoop.addTimer(timer) > > I get: > > undefined method `timerWithTimeInterval' for NSTimer:Class (NoMethodError) > > which is very confusing given: > > http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSTimer_Class/Reference/NSTimer.html#//apple_ref/occ/cl/NSTimer > > and > > http://stackoverflow.com/questions/1449035/how-do-i-use-nstimer > > What am I missing here? Any advice appreciated!? Here is a paste from my program where I successfully set up and use a timer. Looks like I used a slightly different method from the same API. Hope it helps: class LevelView < NSView attr_accessor :keyboard_view def initWithFrame frame $game = Game.new(self) super(frame) @timer = NSTimer.scheduledTimerWithTimeInterval 1.0/FPS, target:self, selector:'doTick:', userInfo:nil, repeats:true NSRunLoop.currentRunLoop.addTimer @timer, forMode:NSModalPanelRunLoopMode NSRunLoop.currentRunLoop.addTimer @timer, forMode:NSEventTrackingRunLoopMode -- Elliot Temple http://beginningofinfinity.com/ ___ MacRuby-devel mailing list [email protected] http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
Re: [MacRuby-devel] NSTimer.timerWithTimeInterval ?
Take the calling param sequence and turn it into a 1.9 hash statement in order :) timer = NSTimer.timerWithTimeInterval 60, target: self, selector: 'recheckAndUpdateTitle:', userInfo: nil, repeats: true because this is the actual selector: timerWithTimeInterval:target:selector:userInfo:repeats: On Nov 7, 2011, at 2:33 PM, Robert Feldt wrote: > Hi, > > Noob to both MacRuby and Cocoa/Objective-C here (but not Ruby) so > please forgive is this is obvious but when I try to call > > timer = NSTimer.timerWithTimeInterval(60, self, > 'recheckAndUpdateTitle:', nil, true) > NSRunLoop.currentRunLoop.addTimer(timer) > > I get: > > undefined method `timerWithTimeInterval' for NSTimer:Class (NoMethodError) > > which is very confusing given: > > http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSTimer_Class/Reference/NSTimer.html#//apple_ref/occ/cl/NSTimer > > and > > http://stackoverflow.com/questions/1449035/how-do-i-use-nstimer > > What am I missing here? Any advice appreciated!? > > -- > Thanks in advance, > > /Robert Feldt > ___ > MacRuby-devel mailing list > [email protected] > http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel ___ MacRuby-devel mailing list [email protected] http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
Re: [MacRuby-devel] NSTimer.timerWithTimeInterval ?
Thanks guys, I'll try to read up on some more tutorials before making a fool of myself again... ;) Cheers, Robert On Mon, Nov 7, 2011 at 8:42 PM, Richard Kilmer wrote: > Take the calling param sequence and turn it into a 1.9 hash statement in > order :) > > timer = NSTimer.timerWithTimeInterval 60, target: self, selector: > 'recheckAndUpdateTitle:', userInfo: nil, repeats: true > > because this is the actual selector: > timerWithTimeInterval:target:selector:userInfo:repeats: > > On Nov 7, 2011, at 2:33 PM, Robert Feldt wrote: > >> Hi, >> >> Noob to both MacRuby and Cocoa/Objective-C here (but not Ruby) so >> please forgive is this is obvious but when I try to call >> >> timer = NSTimer.timerWithTimeInterval(60, self, >> 'recheckAndUpdateTitle:', nil, true) >> NSRunLoop.currentRunLoop.addTimer(timer) >> >> I get: >> >> undefined method `timerWithTimeInterval' for NSTimer:Class (NoMethodError) >> >> which is very confusing given: >> >> http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSTimer_Class/Reference/NSTimer.html#//apple_ref/occ/cl/NSTimer >> >> and >> >> http://stackoverflow.com/questions/1449035/how-do-i-use-nstimer >> >> What am I missing here? Any advice appreciated!? >> >> -- >> Thanks in advance, >> >> /Robert Feldt >> ___ >> MacRuby-devel mailing list >> [email protected] >> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel > > ___ > MacRuby-devel mailing list > [email protected] > http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel > -- Best regards, /Robert Feldt -- Tech. Dr. (PhD), Assoc. Professor in Software Engineering Chalmers, Software Engineering Dept Blekinge Institute of Technology, Software Engineering Research Lab robert.feldt (a) chalmers.se or robert.feldt (a) gmail.com Mobile phone: +46 (0) 733 580 580 http://www.cse.chalmers.se/~feldt ___ MacRuby-devel mailing list [email protected] http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
Re: [MacRuby-devel] NSTimer.timerWithTimeInterval ?
Here is an example of a small game written entirely in MacRuby and which uses NSTimer to run the game loop: https://github.com/mattetti/phileas_frog/blob/master/game_loop.rb#L32-36 I hope it helps, - Matt On Mon, Nov 7, 2011 at 11:54 AM, Robert Feldt wrote: > Thanks guys, I'll try to read up on some more tutorials before making > a fool of myself again... ;) > > Cheers, > > Robert > > On Mon, Nov 7, 2011 at 8:42 PM, Richard Kilmer wrote: > > Take the calling param sequence and turn it into a 1.9 hash statement in > order :) > > > > timer = NSTimer.timerWithTimeInterval 60, target: self, selector: > 'recheckAndUpdateTitle:', userInfo: nil, repeats: true > > > > because this is the actual selector: > timerWithTimeInterval:target:selector:userInfo:repeats: > > > > On Nov 7, 2011, at 2:33 PM, Robert Feldt wrote: > > > >> Hi, > >> > >> Noob to both MacRuby and Cocoa/Objective-C here (but not Ruby) so > >> please forgive is this is obvious but when I try to call > >> > >> timer = NSTimer.timerWithTimeInterval(60, self, > >> 'recheckAndUpdateTitle:', nil, true) > >> NSRunLoop.currentRunLoop.addTimer(timer) > >> > >> I get: > >> > >> undefined method `timerWithTimeInterval' for NSTimer:Class > (NoMethodError) > >> > >> which is very confusing given: > >> > >> > http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSTimer_Class/Reference/NSTimer.html#//apple_ref/occ/cl/NSTimer > >> > >> and > >> > >> http://stackoverflow.com/questions/1449035/how-do-i-use-nstimer > >> > >> What am I missing here? Any advice appreciated!? > >> > >> -- > >> Thanks in advance, > >> > >> /Robert Feldt > >> ___ > >> MacRuby-devel mailing list > >> [email protected] > >> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel > > > > ___ > > MacRuby-devel mailing list > > [email protected] > > http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel > > > > > > -- > Best regards, > > /Robert Feldt > -- > Tech. Dr. (PhD), Assoc. Professor in Software Engineering > Chalmers, Software Engineering Dept > Blekinge Institute of Technology, Software Engineering Research Lab > robert.feldt (a) chalmers.se or robert.feldt (a) gmail.com > Mobile phone: +46 (0) 733 580 580 > http://www.cse.chalmers.se/~feldt > ___ > MacRuby-devel mailing list > [email protected] > http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel > ___ MacRuby-devel mailing list [email protected] http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
Re: [MacRuby-devel] NSTimer.timerWithTimeInterval ?
Yes, thanks again. What "got me" here is that the error message complained that the method wasn't there so I didn't really consider looking at the formatting of the parameters. I realize now that MacRuby probably does method lookup/disambiguation based on the "param names" (or what they are called in objective-c). So a suggestion to the MacRuby team would be to try to make the error message indicate this in some way if possible. So instead of simply: undefined method `scheduledTimerWithTimeInterval' for NSTimer:Class (NoMethodError) Something like: undefined method `scheduledTimerWithTimeInterval' (or missing/use of parameters) for NSTimer:Class (NoMethodError) would be helpful and imho more "true". OTOH this might make it into an ArgumentError so not easy to handle... Regards, Robert On Tue, Nov 8, 2011 at 12:32 AM, Matt Aimonetti wrote: > Here is an example of a small game written entirely in MacRuby and which > uses NSTimer to run the game > loop: https://github.com/mattetti/phileas_frog/blob/master/game_loop.rb#L32-36 > I hope it helps, > - Matt > > On Mon, Nov 7, 2011 at 11:54 AM, Robert Feldt > wrote: >> >> Thanks guys, I'll try to read up on some more tutorials before making >> a fool of myself again... ;) >> >> Cheers, >> >> Robert >> >> On Mon, Nov 7, 2011 at 8:42 PM, Richard Kilmer wrote: >> > Take the calling param sequence and turn it into a 1.9 hash statement in >> > order :) >> > >> > timer = NSTimer.timerWithTimeInterval 60, target: self, selector: >> > 'recheckAndUpdateTitle:', userInfo: nil, repeats: true >> > >> > because this is the actual selector: >> > timerWithTimeInterval:target:selector:userInfo:repeats: >> > >> > On Nov 7, 2011, at 2:33 PM, Robert Feldt wrote: >> > >> >> Hi, >> >> >> >> Noob to both MacRuby and Cocoa/Objective-C here (but not Ruby) so >> >> please forgive is this is obvious but when I try to call >> >> >> >> timer = NSTimer.timerWithTimeInterval(60, self, >> >> 'recheckAndUpdateTitle:', nil, true) >> >> NSRunLoop.currentRunLoop.addTimer(timer) >> >> >> >> I get: >> >> >> >> undefined method `timerWithTimeInterval' for NSTimer:Class >> >> (NoMethodError) >> >> >> >> which is very confusing given: >> >> >> >> >> >> http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSTimer_Class/Reference/NSTimer.html#//apple_ref/occ/cl/NSTimer >> >> >> >> and >> >> >> >> http://stackoverflow.com/questions/1449035/how-do-i-use-nstimer >> >> >> >> What am I missing here? Any advice appreciated!? >> >> >> >> -- >> >> Thanks in advance, >> >> >> >> /Robert Feldt >> >> ___ >> >> MacRuby-devel mailing list >> >> [email protected] >> >> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel >> > >> > ___ >> > MacRuby-devel mailing list >> > [email protected] >> > http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel >> > >> >> >> >> -- >> Best regards, >> >> /Robert Feldt >> -- >> Tech. Dr. (PhD), Assoc. Professor in Software Engineering >> Chalmers, Software Engineering Dept >> Blekinge Institute of Technology, Software Engineering Research Lab >> robert.feldt (a) chalmers.se or robert.feldt (a) gmail.com >> Mobile phone: +46 (0) 733 580 580 >> http://www.cse.chalmers.se/~feldt >> ___ >> MacRuby-devel mailing list >> [email protected] >> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel > > > ___ > MacRuby-devel mailing list > [email protected] > http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel > > -- Best regards, /Robert Feldt -- Tech. Dr. (PhD), Assoc. Professor in Software Engineering Chalmers, Software Engineering Dept Blekinge Institute of Technology, Software Engineering Research Lab robert.feldt (a) chalmers.se or robert.feldt (a) gmail.com Mobile phone: +46 (0) 733 580 580 http://www.cse.chalmers.se/~feldt ___ MacRuby-devel mailing list [email protected] http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
