Problem getting roomVariable

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

Moderators: Lapo, Bax

Post Reply
Lymeh
Posts: 5
Joined: 07 Jul 2010, 11:45

Problem getting roomVariable

Post 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 ?
Lymeh
Posts: 5
Joined: 07 Jul 2010, 11:45

Post by Lymeh »

up !!

Anyone could help me ? any Idea ?
Lymeh
Posts: 5
Joined: 07 Jul 2010, 11:45

Post 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
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

Sorry for the delay.
What server version do you use?
Lapo
--
gotoAndPlay()
...addicted to flash games
Lymeh
Posts: 5
Joined: 07 Jul 2010, 11:45

Post by Lymeh »

it's the 1.6.8 version
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post 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
Lapo
--
gotoAndPlay()
...addicted to flash games
shlomi
Posts: 83
Joined: 21 Feb 2010, 10:38
Location: Israel

did you solved it?

Post 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.
BigFIsh
Posts: 1698
Joined: 25 Feb 2008, 19:26
Location: New Zealand

Post 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
Smartfox's forum is my daily newspaper.
shlomi
Posts: 83
Joined: 21 Feb 2010, 10:38
Location: Israel

Post 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)..
Post Reply