getRoomByName

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

Moderators: Lapo, Bax

rik.schennink
Posts: 21
Joined: 28 Mar 2006, 15:08
Location: The Netherlands

getRoomByName

Postby rik.schennink » 03 Apr 2006, 09:44

I have a problem with the getRooMByName function. It seems that it returns only the last added room data. it doesnt matter what danceID i give (the dance ID is the rooms name) it returns the same room ID each time.

When i retrieve the roomlist with getRooms and loop through the room array i can get the correct room ID.

Code: Select all

function getRoomIdByRoomName(danceID)
{
var tmproom = zone.getRoomByName(danceID);   
trace("DanceID: " + danceID + " has roomID: " + tmproom.getId());
   
var roomList = zone.getRooms();   
   
for(var i=0;i<roomList.length;i++)
{
     if (roomList[i].getName() == (danceID + ""))
     {
   //return roomList[i].getId();
     }
      
     trace("ROOM: " + roomlist[i].getName() + " | " + roomlist[i].getId());
}
   
return -1;
}


Code: Select all

[mcZone.as]: DanceID: 19 has roomID: 3
[mcZone.as]:   Room: dummyRoom | 2
[mcZone.as]:   Room: holderRoom | 1
[mcZone.as]:   Room: 18 | 3
[mcZone.as]: DanceID: 18 has roomID: 3
[mcZone.as]:   Room: dummyRoom | 2
[mcZone.as]:   Room: holderRoom | 1
[mcZone.as]:   Room: 18 | 3
[mcZone.as]: DanceID: 12 has roomID: 3
[mcZone.as]:   Room: dummyRoom | 2
[mcZone.as]:   Room: holderRoom | 1
[mcZone.as]:   Room: 18 | 3


What i am trying to do: There are 3 rooms defined. I am looking for the room with name 18, i want the room id of that room. (the above code is located within a function to do that). i give danceID 12, the code matches roomID 3 (??) i give danceID 19, the code matches roomID 3 (??) it should only match roomID 3 to danceID 18... why is this happening?
Last edited by rik.schennink on 03 Apr 2006, 12:34, edited 1 time in total.
User avatar
Virusescu
Posts: 260
Joined: 07 Sep 2005, 09:36
Location: [RO]Bucharest
Contact:

Postby Virusescu » 03 Apr 2006, 11:48

I don't really understand how is your code structured. What is the function and how you call it?
i'm guessing it is getRoomByName. But where do you call it.

And from the commented line of code I see you return an id, but in the first lines of code you act like the function would return a room object.
function onJoin(usr) {if (usr.getName() == "Lapo") trace ("All Hail Lapo");}
rik.schennink
Posts: 21
Joined: 28 Mar 2006, 15:08
Location: The Netherlands

Postby rik.schennink » 03 Apr 2006, 12:38

Okay the function is now visible above. It is written as a testcase.. to show that something is not going right.

the first part prints the danceID given and the matching roomID found with the getRoomByName function. I have 3 rooms in the database (as stated) when i enter danceid 18 it should give room id 3, this works, except that when i enter danceid 9805275389 it also returns room id 3, while dance id 9805275389 doesnt even exist.

The second part loops through the available rooms and prints the roomname and id to the screen, if the roomname matches the danceid it returns the roomid..

The problem is that i would like to get the room ID like the way i do in the first part. But that that doesnt work. The second part works however that is not the code i would prefer to use.
User avatar
Virusescu
Posts: 260
Joined: 07 Sep 2005, 09:36
Location: [RO]Bucharest
Contact:

Postby Virusescu » 03 Apr 2006, 12:49

Now I understand. It seems like a bug.
Try this (it's a blind shot but I would try it):
Since getRoomByName expects a string as the room name make sure you pass it a string.
function onJoin(usr) {if (usr.getName() == "Lapo") trace ("All Hail Lapo");}
rik.schennink
Posts: 21
Joined: 28 Mar 2006, 15:08
Location: The Netherlands

Postby rik.schennink » 03 Apr 2006, 12:50

tried it already :) didnt work. :(
User avatar
Virusescu
Posts: 260
Joined: 07 Sep 2005, 09:36
Location: [RO]Bucharest
Contact:

Postby Virusescu » 03 Apr 2006, 12:51

Ah.. it finaly hit me.
What is zone?

unless you defined zone somewhere before in your code like
zone = _server.getCurrentZone(); you should define it inside.

The function should look like

Code: Select all

function getRoomIdByRoomName(danceID){
return _server.getCurrentZone().getRoomByName(danceID).getId();
}


Hope this works ;)
function onJoin(usr) {if (usr.getName() == "Lapo") trace ("All Hail Lapo");}
User avatar
Virusescu
Posts: 260
Joined: 07 Sep 2005, 09:36
Location: [RO]Bucharest
Contact:

Postby Virusescu » 03 Apr 2006, 12:56

Although... this kind of looks like a bug. Because if zone was undefined it wouldn't work and throw an error like "can not getRoomName of undefined" or something similar.
function onJoin(usr) {if (usr.getName() == "Lapo") trace ("All Hail Lapo");}
rik.schennink
Posts: 21
Joined: 28 Mar 2006, 15:08
Location: The Netherlands

Postby rik.schennink » 03 Apr 2006, 12:57

i have a

var zone;

then in the init function i set the zone var to the currentzone..

but i tried your suggestion, unfortunately it didn't work

Code: Select all

trace(danceID + " | " + _server.getCurrentZone().getRoomByName(danceID).getId());


Code: Select all

[mcZone.as]: 19 | 3
[mcZone.as]: 18 | 3
[mcZone.as]: 12 | 3


Its rather strange :)
User avatar
Lapo
Site Admin
Posts: 23027
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 03 Apr 2006, 16:32

There must be something weird in your code. I have no problems getting whatever room object with the getRoomByName() method...

I'd suggest to make the simplest test possible, try getting a room object from its name and check if the correct room is returned by tracing its name.
This will at least show what's going on...

thnx
Lapo
--
gotoAndPlay()
...addicted to flash games

Return to “Server Side Extension Development”

Who is online

Users browsing this forum: No registered users and 41 guests