bounce room script ...timer

Post new topic   Reply to topic Scripting Questions View previous topic :: View next topic  
Author Message
Cheiron



Joined: 21 Apr 2005
Posts: 388
Location: Copenhagen, Denmark

PostPosted: Thu Oct 04, 2007 9:21 am    Post subject: bounce room script ...timer Reply with quote

Hullo

we have a bounce room thing at MP... you type sr and it kicks you to a bounce room and you pop back to room you came from... here it is:

In room you are currently in... there is following spotscript that holds the globals:
Code:
#Python title= globals for Manor entrance

import manor

#globals for new sr
fromRoom = 0
bounceRoom = 244
xpos = 0
ypos = 0
srInProgress = 0


other spot in room triggers it:
Code:
#Python title = script for Manor room

import manor

import globals

def mnr_outchat(chatText):

    if chatText == "sr":

        globals.srInProgress = 1

        chatText = ""

        globals.xpos, globals.ypos = manor.getUserPos(manor.myID())

        globals.fromRoom = manor.getRoomNumber()

        manor.gotoRoom(globals.bounceRoom)

    return chatText

def mnr_enter(userID):

    if userID == manor.myID():

        if globals.srInProgress == 1:

            globals.srInProgress = 0

            manor.setPos(globals.xpos, globals.ypos)



Then in the bounceroom (here ID 244) you have this:

Code:
import manor
import globals

def mnr_enter(userID):

    if userID == manor.myID():

        manor.gotoRoom(globals.fromRoom)


Now... the question here is:

I want a timer to slow down the bounce back a bit... how do I do that?...

my birdbrain guess is that I need to embed the gotoRoom function in a timer.. something like this:

Code:
manor.setTimer(manor.tickcount()+100, manor.gotoRoom, globals.fromRoom)


would that work, or do I misunderstand especially parameter thing in setTimer function completely?
_________________
Cheiron
______________________________
"Any scientist with respect for himself should start
the day by rejecting his own pet hypotheses".
(Konrad Lorenz)

"Wir müssen wissen
Wir werden wissen"
(David Hilbert)
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Scotsman
Site Admin


Joined: 03 Aug 2004
Posts: 705
Location: MadWolf Software

PostPosted: Thu Oct 04, 2007 11:49 am    Post subject: Reply with quote

To avoid some nasty race conditions, I would create a seperate routine to call the gotoRoom, and then instantiate that routine from the timer call.

In general it's a bad idea to call any of the manor api routines directly from a timer. It may work fine for you, but I can virtually guarentee it will break for somebody.
Back to top
View user's profile Send private message Visit poster's website
Cheiron



Joined: 21 Apr 2005
Posts: 388
Location: Copenhagen, Denmark

PostPosted: Thu Oct 04, 2007 6:30 pm    Post subject: Reply with quote

OK...well a lot of manors ...if not all, use the manor.setTimer(... then functions inside).. so I guess we are all screwed then?? ... if I understand you right

could you elaborate on that in above example, please?
_________________
Cheiron
______________________________
"Any scientist with respect for himself should start
the day by rejecting his own pet hypotheses".
(Konrad Lorenz)

"Wir müssen wissen
Wir werden wissen"
(David Hilbert)
Back to top
View user's profile Send private message Send e-mail Visit poster's website
mimee



Joined: 10 Oct 2004
Posts: 81
Location: mendota, illinois

PostPosted: Thu Oct 04, 2007 8:34 pm    Post subject: bounce room script Reply with quote

Here is the script i used for my bounce room ....... the timer is nested .........and it works...

the sr for each room:

[code]

import manor
import string

roomnumber = 100

def find(str, ch):
index = 0
while index < len(str):
if str[index] == ch:
return index
index = index +1
return -1

def setPos(userpos):
global index
try:
xpos = int(userpos[0:index])
ypos = int(userpos[index + 1:len(userpos)])
manor.setPos(xpos, ypos)
except:
pass
return

def mnr_inchat(userID, chatText):
global roomnumber
if chatText == "sr":
if userID == manor.myID():
chatText = ""
userpos = manor.getUserPos(manor.myID())
userpos = str(userpos)

#write cookie
f=open('WM-subret.txt', 'w')
f.write(str(roomnumber)+chr(10))
f.write(str(userpos))
f.close
manor.gotoRoom(500)
return chatText

def mnr_enter(userID):
global index
if userID == manor.myID():
try:
f=open('WM-subret.txt', 'r')
f.readline()
userpos = f.readline()
f.close()
f=open('WM-subret.txt', 'w')
f.write("" + chr(10))
f.write("" + chr(10))
f.close()
userpos = userpos[1:len(userpos) - 1]
index = find(userpos, ",")
manor.setTimer(manor.tickcount() + 15, setPos, userpos)
except:
pass
return





Bounceroom script:

import manor

go = 1

def mnr_inchat(userID, chatText):

global go
if chatText == "reset":
go = 0
return chatText



def mnr_enter(userID):

global go
f=open('WM-subret.txt', 'r')
roomnumber = int(f.readline())
f.close
if go == 1:
manor.setTimer(manor.tickcount() + 30, manor.gotoRoom, roomnumber)

return

Scots, now does this have the same "issues" as the suggestion Cheiron made ???

Mine has a timer and somewhat the same structure as setTimer.
It has never caused me any problems.

Mimee


Last edited by mimee on Thu Oct 04, 2007 8:50 pm; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail MSN Messenger
Scotsman
Site Admin


Joined: 03 Aug 2004
Posts: 705
Location: MadWolf Software

PostPosted: Fri Oct 05, 2007 12:34 am    Post subject: Reply with quote

Not saying it is going to cause everyone problems right away, it may even be a minority of users.

What I am saying is it's not a good idea. The only reason that works today with some API calls is just a coincidence. Future versions the specifics of the internal parameter passing may change. Not to mention timers are implemented in threads, and threads have different subtleties between Windows, OS X, and Mac Classic.

The developer recommended way to do this (meaning the one I am sure to test and make sure works in future versions) is to have your own python routine that you give to the timer to call that then takes the desired action.
Back to top
View user's profile Send private message Visit poster's website
Bri



Joined: 06 Aug 2004
Posts: 237
Location: Palm Springs, CA

PostPosted: Fri Oct 05, 2007 10:01 pm    Post subject: SR Reply with quote

I seem to remember the SR script was in the ‘manor command’ candidate list. Years ago, about every other room was using it so the total python lines to just “Front my Avatar“ was huge.
Front as in change Z.
_________________
RL..now with 100% less lag!
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Lisa



Joined: 04 Aug 2004
Posts: 118
Location: Amsterdam

PostPosted: Wed Oct 10, 2007 12:47 pm    Post subject: Reply with quote

Quote:
The developer recommended way to do this


Now he's telling us. It would be nicer if there was a manual available at the time I wrote this lil routine which in my opinion should be a basic Manor command.
_________________
-Lisa-
Back to top
View user's profile Send private message MSN Messenger
mimee



Joined: 10 Oct 2004
Posts: 81
Location: mendota, illinois

PostPosted: Thu Oct 11, 2007 8:43 am    Post subject: SR timer Reply with quote

hey Lisa hugss

as u see not much has changed in manor...Sad no answers !! the sr i posted , you wrote and worked fine....... why make things so damn complicated ?? Rolling Eyes

Mimee
Back to top
View user's profile Send private message Send e-mail MSN Messenger
Scotsman
Site Admin


Joined: 03 Aug 2004
Posts: 705
Location: MadWolf Software

PostPosted: Thu Oct 11, 2007 9:58 am    Post subject: Reply with quote

Pardon my feeble memory, SR script? Wuz Dat?
Back to top
View user's profile Send private message Visit poster's website
Cheiron



Joined: 21 Apr 2005
Posts: 388
Location: Copenhagen, Denmark

PostPosted: Thu Oct 11, 2007 3:32 pm    Post subject: Reply with quote

hmmm....
_________________
Cheiron
______________________________
"Any scientist with respect for himself should start
the day by rejecting his own pet hypotheses".
(Konrad Lorenz)

"Wir müssen wissen
Wir werden wissen"
(David Hilbert)


Last edited by Cheiron on Fri Oct 12, 2007 4:57 am; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Lisa



Joined: 04 Aug 2004
Posts: 118
Location: Amsterdam

PostPosted: Thu Oct 11, 2007 4:00 pm    Post subject: Reply with quote

Scotsman wrote:
Pardon my feeble memory, SR script? Wuz Dat?


You're getting senile or what? What are they talking about here? Duh Confused
_________________
-Lisa-
Back to top
View user's profile Send private message MSN Messenger
Scotsman
Site Admin


Joined: 03 Aug 2004
Posts: 705
Location: MadWolf Software

PostPosted: Fri Oct 12, 2007 2:15 pm    Post subject: Reply with quote

oh duh. No just have a cold making it hard to keep things straight.

Will look at this a bit, I question the need for the timer function at all unless it's trying to work around an issue in the software.

If so relying on timers is something that is normally avoided if possible (you don't even want to know how often one has to work around quirks in the OS, that change from one revision to another no less) as different machines will have different timing for the issue your trying to work around.
Back to top
View user's profile Send private message Visit poster's website
Jade



Joined: 22 Oct 2005
Posts: 120
Location: Ireland

PostPosted: Fri Oct 12, 2007 5:17 pm    Post subject: Reply with quote

get well soon Scots, passing the tissues Wink
Jade
Back to top
View user's profile Send private message
Lisa



Joined: 04 Aug 2004
Posts: 118
Location: Amsterdam

PostPosted: Sat Oct 13, 2007 1:35 am    Post subject: Reply with quote

The timer was used to avoid a quirk in the software, I forgot what quirk because it's ages ago I wrote this lil beauty. I will think about it and maybe it will pop up.
_________________
-Lisa-
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic All times are GMT - 6 Hours
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum