Page 1 of 1

Python setRoomVariables Prob.

Posted: 03 May 2009, 12:15
by yaswanth
Hi!

I am setting a room variable as follows:

Code: Select all

	tableDeck = list(range(52))
	_server.trace("Setting Room Variable " + str(tableDeck))
	
	roomVarList = []
	roomVarList.append(RoomVariable("tableDeck", tableDeck, 1,1))
	
	_server.trace(_server.getCurrentRoom().getName())
	_server.trace("Room Variables appending!!!")

	_server.trace(roomVarList)
	_server.setRoomVariables( _server.getCurrentRoom(), None, roomVarList )

This throws up an error saying

Code: Select all

[cards.py]: Setting Room Variable [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51]
[cards.py]: GameRoom1
[cards.py]: Room Variables appending!!!
[cards.py]: [<main.RoomVariable instance 5>]
Traceback (innermost last):
  File "<string>", line 834, in init
  File "<string>", line 1217, in loadConfig
  File "<string>", line 563, in setRoomVariables
  File "<string>", line 593, in _prepareRoomVars
UnboundLocalError: local: 't'
18:41:30.906 - [ WARNING ] > Error in extension [ cards.py ]: Traceba
ck (innermost last):
  File "<string>", line 834, in init
  File "<string>", line 1217, in loadConfig
  File "<string>", line 563, in setRoomVariables
  File "<string>", line 593, in _prepareRoomVars
UnboundLocalError: local: 't'
 --- At line: 41
18:41:30.906 - [ INFO ] > Room [ GameRoom1 ] created!
I think I am setting everything correctly and all the variables have been initialized. The room has been created (The code prints the room name 'GameRoom1')

Can some one point out what possibly could have gone wrong?


Thanks,
Yaswanth

Posted: 03 May 2009, 16:55
by Lapo
Room Variables don't support arrays, only primitive values such as numbers, strings, booleans
It looks like you are trying to send a list as one RoomVariable.

You could do it, by flattening your list to a string (very easy in python) of comma separated values and then rebuilding the array on the client side. In Actionscript this can be done with String.split() method

Posted: 03 May 2009, 17:22
by yaswanth
Hi Lapo,

Referring to your previous post:
http://forums.smartfoxserver.com/viewtopic.php?t=1525

setRoomVariables takes array or list of RoomVariable().

I am appending all the room variables in a list and trying to pass the list. I dont see how this is different.

Anyways, as per your previous example mentioned in the above post.

I re-wrote the code but to no avail (throws up the same error):

Code: Select all

	roomVar1 = RoomVariable("tableDeck", tableDeck, 1,1)
	roomVar2 = RoomVariable("tableDeck2", tableDeck, 1,1)
	
	_server.trace(_server.getCurrentRoom().getName())
	_server.trace("Room Variables appending!!!")

	_server.trace(roomVarList)
	_server.setRoomVariables( _server.getCurrentRoom(), None, [roomVar1, roomVar2])

Could I be doing something wrong in the room creation? I am modifying SFSTris to act as the test client. Could there be something wrong in SFSTris, as SFSTris sends a request to the server to create a new room with Xtname and Xtscript (Correct me if I am wrong).

-Thanks,
Yaswanth