|
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Thu Jan 15, 2009 8:50 pm
[3.03a] Interesting threading problem with maps |
I just found an interesting problem that is undoubtedly related to threading race conditions with the map. I have some code that identifies a room description and signals #ok. The #ok command was at the end of the trigger. I also have some code that triggers on the exit line, immediately after the description. I found that when the exit trigger executed, %roomexit displayed the exit list of the previous room. I moved the #ok in the description trigger up several lines, and now the exit trigger properly shows the current room exit list from the map. This must be caused by a race condition in updating the location object. This could make a real mess. I think I have also noticed a similar problem in the OnRoomEnter event, in that the %room functions still point to the previous room. I need to check that further to see if that is correct.
|
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Thu Jan 15, 2009 9:11 pm |
Please show me your full script so that I can test this. The #OK command gets executed in the main thread, but it's possible it is just putting a notification message into the Windows message queue, which might prevent the location from updating immediately.
I don't think this is any sort of "race condition". But if you give me some specific code to test, then I might be able to learn more. |
|
|
|
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Thu Jan 15, 2009 9:25 pm |
I'll try to come up with some smaller test to demonstrate this tomorrow.
|
|
|
|
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Mon Feb 02, 2009 9:07 pm |
Sorry I didn't get back to this for a while. It got put on the back burner while other things cropped up. For a while I began to suspect the problem was within my triggers, but I can now demonstrate the problem in the untitled session:
Open the untitled session
In the Package Editor, add the English Directions package
Create the following two triggers:
Code: |
<trigger name="first trigger" priority="50" id="5">
<pattern>(*): (*) <(*)></pattern>
<value>#ok
#say move okay</value>
</trigger>
<trigger name="second trigger" priority="60" id="6">
<pattern>(*): (*) <(*)></pattern>
<value>#say room: %roomname</value>
</trigger>
|
Open the mapper
In Edit mode, create two rooms connected by one exit
Name the two rooms First Room and Second Room
Put the mapper in Safe Walk mode
Set the current location to be First Room
Keep the map in Edit mode
In the command line, type the direction to move to the Second Room (e.g. 'north')
In the command line, type: #show Test room: room description < s >
The map moves the location to the Second Room, but the second trigger returns: room: First Room
Type: #show %roomname
This now shows the correct room name
Do the same thing in the other direction
The second trigger fires after the #ok trigger, but the %roomname has not been corrected by the time it fires. |
|
|
|
Tech GURU
Joined: 18 Oct 2000 Posts: 2733 Location: Atlanta, USA
|
Posted: Mon Feb 09, 2009 5:14 am |
I finally got around to this. Zugg will have to decide if it's really an issue or not, but it turns out that the %roomname system variable is updated until the onRoomEvent is fired. I added the following events for clarity and statements to identify the different events.
Code: |
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
<trigger name="TriggerOne" priority="10" copy="yes">
<pattern>(*): (*) <(*)></pattern>
<value>#OK
#print trigger one
#say move okay</value>
</trigger>
<trigger name="TriggerTwo" priority="20" copy="yes">
<pattern>(*): (*) <(*)></pattern>
<value>#print trigger 2
#say room: %roomname
</value>
</trigger>
<event event="onRoomEnter" priority="70" copy="yes">
<value>#prinT ROOM ENTERED
#PRINT %ROOMNAME</value>
</event>
<event event="onRoomWalk" priority="60" copy="yes">
<value>#PRINT ON ROOM WALK</value>
</event>
</cmud> |
This is what I entered at the command line. My rooms were east - west instead of north - south.
Code: |
E
#print %roomname
#show Test room: room description < E >
#print %roomname |
This was my output.
Code: |
E
ON ROOM WALK
First Room
Test room: room description < E >
trigger one
move okay
trigger 2
room: First Room
First Room
ROOM ENTERED
Second Room |
|
|
_________________ Asati di tempari!
Last edited by Tech on Mon Feb 09, 2009 6:06 pm; edited 1 time in total |
|
|
|
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Mon Feb 09, 2009 2:46 pm |
Hm. Okay, that does make some sense. If Zugg decides this is not a problem (which does not seem unreasonable), then we'll just have to be aware that the location information does not change at #OK but at the onRoomEnter event. I may have to reconsider how to do what I want.
|
|
|
|
|
|