Page 1 of 1

Problem getting roomVariable

Posted: 07 Jul 2010, 12:02
by Lymeh
Hello,

I currently having some problems with roomVariables.

This is the code used to create the roomVar

Code: Select all

HashMap<String, RoomVariable> vars = new HashMap<String, RoomVariable>();
vars.put("gaming", new RoomVariable("true",RoomVariable.TYPE_BOOLEAN,null, true, true));
helper.setRoomVariables(room, null, vars, false, false);
And i'm trying to get this roomVariable "gaming" like that :

Code: Select all

    roomVars = room.getVariableNames();
    if (roomVars.contains("gaming"))
    {
        RoomVariable roomVar = room.getVariable("gaming");
        if (roomVar.getBooleanValue())
        {
            continue;
        }
     }
It works but the getBooleanValue() function return false instead of true. What's my error ? The admin tool confirm that the room has a roomVariable called "gaming" wich is a Boolean and it's value is true...

Theses codes are used on the server side (an extension to joining room).

Someone could help me ?

Posted: 09 Jul 2010, 14:38
by Lymeh
up !!

Anyone could help me ? any Idea ?

Posted: 23 Jul 2010, 08:53
by Lymeh
Hi!

Lapo ? an advice ?? can i get roomVariable from a server extension or not ? what's the way to get it ? pls i realy need some help on this

Posted: 23 Jul 2010, 17:30
by Lapo
Sorry for the delay.
What server version do you use?

Posted: 26 Jul 2010, 07:18
by Lymeh
it's the 1.6.8 version

Posted: 27 Jul 2010, 04:52
by Lapo
Try using this instead:

Code: Select all

vars.put("gaming", new RoomVariable("1",RoomVariable.TYPE_BOOLEAN,null, true, true)); 
1 == true
0 == false

I think this should fix the problem.
We'll make sure to add this to the documentation. Plus the next update will provide new constructors for the RoomVariable type to simplify the creation

did you solved it?

Posted: 29 Jul 2010, 07:22
by shlomi
hi Lymeh,

did Lapo's solution solved your problem? i have the same problem..

tnx.

BTW, Lapo, you wrote:
I think this should fix the problem.
We'll make sure to add this to the documentation. Plus the next update will provide new constructors for the RoomVariable type to simplify the creation
so you mean the 1.6.9 already solved it? because i still have this problem in this version. or you meant the new 2.X version?


Shlomi.

Posted: 29 Jul 2010, 07:38
by BigFIsh
Also be aware that Flash threats all "String" variable as False when casted into Boolean type.

i.e.

var zero:Boolean = Boolean("0") - traces out False
var one:Boolean = Boolean("1") - traces out False

So you may need to convert string type value to a numeric type value before casting to Boolean type - so..

var zero:Boolean = Boolean(int("0")) - traces out False
var one:Boolean = Boolean(int("1")) - traces out True

Posted: 29 Jul 2010, 07:55
by shlomi
first of all, thanks BigFIsh, i'll be aware for that..

secondly, i made the change and it seems like it's working.

now, just for your info i have a comment:

before i changed the code to:

Code: Select all

String intVal = isActive ? "1" : "0";

roomVars.put("testVar", new RoomVariable(intVal, RoomVariable.TYPE_BOOLEAN, null, true, true));
i have this one:

Code: Select all

roomVars.put("testVar", new RoomVariable(String.valueOf(isActive), RoomVariable.TYPE_BOOLEAN, null, true, true));
so it's seems like Java's String.valueOf function not return "1" and "0" for Boolean values by default, so i looks at Java's documentation for the function's return values and this is what they say:
if the argument is true, a string equal to "true" is returned; otherwise, a string equal to "false" is returned.
SO BE AWARE DUDES (and dudette)..