setRoomVariables() in Python anyone?

Post here your questions about Actionscript and Java server side extensions development.

Moderators: Lapo, Bax

Post Reply
JAraujo
Posts: 7
Joined: 19 Jun 2007, 21:44

setRoomVariables() in Python anyone?

Post by JAraujo »

I'm getting the following error when I try to use setRoomVariables() in a Python extension:

Error in extension [ slides.py ]: Traceback (innermost last):

File "<string>", line 469, in _handleJavaRequest

File "<string>", line 662, in handleRequest

File "<string>", line 709, in setNewParams

File "<string>", line 385, in setRoomVariables

File "<string>", line 403, in _prepareRoomVars

AttributeError: 'dict' object has no attribute 'val'



Here's the server-side code:

Code: Select all

def setNewParams( params, fromUser, fromRoom ):
        var1 = {}
        var1["name"] = "myRoomVar"
        var1["val"] = 99
        var1["priv"] = True
        newVars = [ var1 ]
        _server.setRoomVariables( fromRoom, None, newVars )
Thanks in advance,

Jay
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

In the mainLib.py there's a RoomVariable class that should be used to populate the list of room variables passed to the setRoomVariables() method.

This is the class constructor:

Code: Select all

def __init__(self, name, val, priv = False, persistent = False):
Here's an example of usage:

Code: Select all

# Create the variables
roomVar1 = RoomVariable("posx", 100) # by default private and persistent = False
roomVar2 = RoomVariable("class", "wizard", True, True)

# Create / Set the variables
_server.setRoomVariables(room, None, [roomVar1, roomVar2])
hope it helps
Lapo
--
gotoAndPlay()
...addicted to flash games
JAraujo
Posts: 7
Joined: 19 Jun 2007, 21:44

Post by JAraujo »

Thanks Lapo,

After some investigation I did manage to make it work using a generic Class.

I guess my main mistake was to be passing a roomId and not a roomObject in the first parameter

Code: Select all

var1 = Obj( name="myVar", val="hello world", priv=1, persistent=0 )
newVars = [ var1 ]
thisZone  = _server.getCurrentZone()
thisRoom = thisZone.getRoom(fromRoom)
_server.setRoomVariables( thisRoom, None, newVars )

For some reason I'm not getting the expected value from _server.getCurrentRoom() , as I'm supposedly running this extension in the Room Level.

I'll check the RoomVariables class and use it from now on, thanks
Post Reply