Subject: Player.parse, regex, player timers, bug?... and then some
Author: Massaria
Posted: 01/17/2006 03:38AM
Hey Tyche,
I've collected a few items of interest - at least they are to me - can't have you getting all complacent and fat from inactivity ;-)
So 2.7 is out? Sorry if I'm a bit slow to get how this repository works, but how would I go about getting my hands on new releases (preferrably everything at once)?
Perhaps the new release changes this, but I think you've overlooked something with players and the hamster - one of us did, in any case ;-)
I've added a timer to the players which just counts. So far:
when :timer
if @session
@ptimer += 2
sendto("Timed")
if @ptimer >= 5
@ptimer = 0
sendto("Timed!")
end
end
fart(e)
I was really having problems with this because the timer was sent along even if no player is connected... I simply couldn't understand why @ptimer wasn't initialized. Adding the 'if @session' did the trick, but perhaps such a check would be better at the hamster itself?
Related to this is the registering with the hamster. It's not up to the players to decide whether they need energy or not, so I was trying to automatically register them with
Player.parse("@set ptimer #{@oid} on")
- as I've seen you've done something to that effect elsewhere. I can't remember where that was tho...
How would I register 'timer' with the hamster in player.initialize?
I've been messing with regex'es recently, trying to pass the result directly into a method as argument, sorta like this:
def test(arg)
arg
end
a = "tmud rocks"
test(a =~ /([^\s]+)/)
This doesn't work - I know now ;-)
Could it work though, with the match inside the parenthesis like that?
Also, logging into the site just before, I forgot to enter the password, which generated a page describing in detail what went wrong. Dunno is this is on purpose - it just didn't do that before, so I thought I'd mention it :-)
Mass,
can't hardly wait to get his hands on the new release :-)
____________
EDIT:
> How would I register 'timer' with the hamster in player.initialize?
ah, seems it does register. My mistake, as usual :-(
____________
ANOTHER EDIT:
> So 2.7 is out? Sorry if I'm a bit slow to get how this repository works, but how would I go about getting my hands on new releases (preferrably everything at once)?
Hehe.
I've heard of people who speak without thinking, but writing before thinking?!
*blush*
reply
Subject: Player.parse, regex, player timers, bug?... and then some
Author: Tyche
Posted: 01/17/2006 12:32PM
Massaria wrote:
> ... the timer was sent along even if no player is connected...
Yep that would be a bug now. When the game boots I register all players to receive timer events, regardless of whether they are connected or not. In the current setup only connected players are assumed to be "in the world" should receive events.
> I simply couldn't understand why @ptimer wasn't initialized. Adding the 'if @session' did the trick, but perhaps such a check would be better at the hamster itself?
My plans for the next release will be to focus on the Engine parts, of which the eventmanager and hamster are part. What's missing as the hamster bug reveals is the complete lack of any sort of saved system state. A place to define and save how things work.
Whether or not a player is left in the world when disconnected (and continues to receive events) is something that should be left up to the game itself. In the 'Tyche's Big RolePlaying
? Game' players are left in the world, while in 'Tyche's Big Adventure Game', players are removed from the world. ;-)
> Related to this is the registering with the hamster. It's not up to the players to decide whether they need energy or not, so I was trying to automatically register them with
>
> Player.parse("@set ptimer #{@oid} on")
>
> - as I've seen you've done something to that effect elsewhere. I can't remember where that was tho...
> How would I register 'timer' with the hamster in player.initialize?
I do it in Engine#run currently
@world.db.each {|obj| @world.hamster.register(obj) if obj.powered}
I'd be wary of doing it in Player#initialize as that would only be called for new players, not old players. Maybe register them in Account#login and unregister them in Player#update for :logged_out and :disconnected events.
$engine.world.hamster.register(playerobject)
$engine.world.hamster.unregister(playerobject)
> I've been messing with regex'es recently, trying to pass the result directly into a method as argument, sorta like this:
>
> def test(arg)
> arg
> end
> a = "tmud rocks"
> test(a =~ /([^\s]+)/)
>
> This doesn't work - I know now ;-)
> Could it work though, with the match inside the parenthesis like that?
=~ returns the position in the string of the match or nil of none
Maybe...
test(a =~ /([^\s]+)/ ? $1 : nil)
> Also, logging into the site just before, I forgot to enter the password, which generated a page describing in detail what went wrong. Dunno is this is on purpose - it just didn't do that before, so I thought I'd mention it :-)
Yes I'm running the site in what they call development mode. Instead of getting a standard error page, you get a trace message. Public debugging. :-P
If you get any more of them could you cut and paste them in a message?
> > So 2.7 is out? Sorry if I'm a bit slow to get how this repository works, but how would I go about getting my hands on new releases (preferrably everything at once)?
Oh it's there. I'm still working on a public release announcement that will pass the censor.
reply