Room variables

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

Moderators: Lapo, Bax

User avatar
goodguy20k
Posts: 71
Joined: 10 Jan 2006, 23:58
Location: Texas, USA
Contact:

Room variables

Postby goodguy20k » 17 Feb 2006, 22:26

Well, I tried and tried, and can't get this to make sense. Here's what I'm trying to do:

Server starts up and loads information from the database.
Server creates rooms using the info.
Server SHOULD create room variables for the rooms after they are created.
Server finishes extension code.

Here's my code:

Code: Select all

         var roomObj = {}
         var deck1Obj = {}
         var deck2Obj = {}
         var deck3Obj = {}
         
         // From the record object we can get each field value
         roomObj.name      = tempRow.getItem("shipname")
         deck1Obj.name      = tempRow.getItem("shipname")+"_"+tempRow.getItem("deck1")
         deck2Obj.name      = tempRow.getItem("shipname")+"_"+tempRow.getItem("deck2")
         deck3Obj.name      = tempRow.getItem("shipname")+"_"+tempRow.getItem("deck3")
         roomObj.pwd      = ""
         deck1Obj.pwd      = ""
         deck2Obj.pwd      = ""
         deck3Obj.pwd      = ""
         roomObj.maxU      = 50
         deck1Obj.maxU      = 50
         deck2Obj.maxU      = 50
         deck3Obj.maxU      = 50
         roomObj.maxS      = 0
         deck1Obj.maxS      = 0
         deck2Obj.maxS      = 0
         deck3Obj.maxS      = 0
         roomObj.isGame   = false
         deck1Obj.isGame   = false
         deck2Obj.isGame   = false
         deck3Obj.isGame   = false
         roomObj.uCount   = false
         deck1Obj.uCount   = false
         deck2Obj.uCount   = false
         deck3Obj.uCount   = false
         
         _server.createRoom(roomObj, null)
         _server.createRoom(deck1Obj, null)
         _server.createRoom(deck2Obj, null)
         _server.createRoom(deck3Obj, null)
         
         var rVars = []
         rVars.push( {name:"deckmaptype", val:1} )
         rVars.push( {name:"backgroundtype", val:1} )
         
         for (var j in rVars) {
            trace(rVars[j]);
         }
         // Set the variables
         _server.setRoomVariables(deck1Obj, null, rVars, false, false)


I've even inserted this code I found in the docs (chapter 7.1 AS Serverside API under createRoomVariables).

Code: Select all

var rVars = []

rVars.push( {name:"highscore", val:12000, priv:true} )

// Set the variables
_server.setRoomVariables(roomObj, null, rVars)


Both end up with the same error (the rooms are generated fine now, thanks to your help. 8) )
Error in extension [ VIP_ships.as ]: Can't find method it.gotoandplay.smartfoxserver.extensions.ExtensionHelper.setRoomVariables(object,null,java.util.HashMap,boolean,boolean). (VIP_ships.as#483) Line: -471 (MainLib line: 483)


What am I doing wrong NOW, Lapo? :lol:
User avatar
Lapo
Site Admin
Posts: 23026
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 18 Feb 2006, 07:05

Hi,
you're passing the wrong room object.

Your roomObj variable is a generic object containing the properties of the room you want to create. When you call the createRoom() method you will receive an it.gotoandplay.smartfoxserver.Room object, that's the right one! :)

In other words what you need to pass as first argument is roomObj:Room, not roomObj:Object

The code should change to:

Code: Select all

var theRoom = _server.createRoom(deck1Obj, null)
...
...
...
_server.setRoomVariables(theRoom, null, rVars, false, false)


hope it helps
Lapo
--
gotoAndPlay()
...addicted to flash games
Francois
Posts: 35
Joined: 15 Mar 2006, 14:00

Postby Francois » 27 Mar 2006, 13:03

Hi lapo,

here is my problem:

I'd like to set a room variable from the server but I get the following error...

Code: Select all

15:08:35.239 - [ WARNING ] > Error in extension [ simpleExtTest.as ]: Can't find
 method it.gotoandplay.smartfoxserver.extensions.ExtensionHelper.setRoomVariable
s(string,null,java.util.HashMap,boolean,boolean). (simpleExtTest.as#504) Line: -
485 (MainLib line: 504)




Code: Select all

function handleRequest(cmd, params, user, fromRoom)
{
   if (cmd == "startTheGame")
   {
      var rVars = [];
      rVars.push({name:"gameStarted", val:true});
      _server.setRoomVariables(fromRoom, null, rVars);
   }
}


The function handleRequest works fine but it reports an error on the setRoomVariable.

thx
User avatar
Virusescu
Posts: 260
Joined: 07 Sep 2005, 09:36
Location: [RO]Bucharest
Contact:

Postby Virusescu » 27 Mar 2006, 13:09

Hi Francois: There was a thread some little time ago about the same issue, but I can't seem to find it.
The problem was solved passing all the parameters to the _server.setRoomVariables() method. Use null if you don't need a param. It worked for that guy.
As this seemed like a bug I'd sugest you upgrading to the stable 1.4 version as there are chances that this problem won't occur anymore.

Hope this helps
function onJoin(usr) {if (usr.getName() == "Lapo") trace ("All Hail Lapo");}
Francois
Posts: 35
Joined: 15 Mar 2006, 14:00

Postby Francois » 27 Mar 2006, 13:41

Thx for your reply Virusescu,

I tried

Code: Select all

_server.setRoomVariables(fromRoom, null, rVars,true,true);


still returns me the message

Code: Select all

Error in extension [ simpleExtTest.as ]: Can't find method it.gotoandplay.smartfoxserver.extensions.ExtensionHelper.setRoomVariables(string,null,java.util.HashMap,boolean,boolean). (simpleExtTest.as#504) Line: -485 (MainLib line: 504)


...
so I commented the setRoomVar. and put that before...


Code: Select all

      var room = _server.getCurrentRoom()
      trace("Extension is running in room: " + room.getName())
      trace("Users in this room: " + room.getUserCount())


it returns me the following error:

Code: Select all

Error in extension [ simpleExtTest.as ]: TypeError: Cannot call method "getName" of null (simpleExtTest.as#1008) Line: 19


I've got the latest version of SFS... any idea ? ... thanx !!

Another detail: this extension is at Zone Level... here is a preview of the config.xml

Code: Select all

      <Zone name="sftris" emptyNames="true">
         <Rooms>
            <Room name="The Entrance" maxUsers="50" isPrivate="false" isTemp="false" autoJoin="true" />
         </Rooms>
         <Extensions>
            <extension name="simpleExtTest"  className="simpleExtTest.as" type="script" />
         </Extensions>
      </Zone>
User avatar
Lapo
Site Admin
Posts: 23026
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 28 Mar 2006, 09:39

I have no problems using this code:

Code: Select all

var o = {name:"TestVar", val:"TestValue", priv:true}
var hall = zone.getRoomByName("The Hall")

_server.setRoomVariables(hall, null, [o])


Are you sure you're passing a list of objects? As specified in the docs?
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “Server Side Extension Development”

Who is online

Users browsing this forum: No registered users and 39 guests