Page 1 of 1

I need a getUserVariables example for the iPhone client

Posted: 25 Feb 2011, 21:02
by intomo
Could someone give me an example of getUserVariables? I don't see that in the provided iPhone examples. Specifically, I am setting a score variable in each client. And then at a specific time all clients call getUserVariables, loop through all the clients, and see all clients scores. Many thanks in advance for your help.

Posted: 28 Feb 2011, 05:03
by rahulvyas
here you can get it like this

INFSmartFoxUser *user = //get user form somewhere as per your requirement
[user getVariable:@"Key"];

Here key = The Key you have used when updating user variable

Here in my case I'm updating it like this

Code: Select all

NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:your_Object,@"key",nil];


Then I call my created function

Code: Select all

[self setAdditionalDetailsForSFSUser:params roomID:[SFSRoom getId]];



Here is the method I've created

Code: Select all

- (void)setAdditionalDetailsForSFSUser:(NSDictionary*)object roomID:(NSInteger)roomID {
   
   [self.smartFox setUserVariables:object roomId:roomID];
}




The above code is an example of working iPhone app.

Posted: 28 Feb 2011, 16:52
by intomo
Thanks.
Could you possibly post an example of how you would get variables looping thru all users in a room?

Posted: 01 Mar 2011, 01:33
by rahulvyas
What do you want to create?

A Game or something else?

You can do it like this way

Suppose you are creating a card game. And you need to pass turn each time a player plays his card. So you can do this. First Update a room variable named turnToThrow like 1,2,3 for each player the id will be different as you enter in the room each player will get different id. Now when player 1 who has id 1 got the first chance he can play his card. To play his card update p1Card named room variable with his card value. then when you receive onRoomVariablesUpdate display on screen through a method.Also in that method update turnToThrow by increasing id number. I hope you understand.

Posted: 01 Mar 2011, 15:45
by intomo
Thank you for taking the time to respond.

My game is a little different and onUserVariablesUpdate isn't appropriate for what I'm doing.

My task is to display a scoreboard at a certain time in the game.
The scoreboard will display the scores of all players in the room.
There will be 10 players.
So at that time the game has run a loop that will go through all the users in the room, get their score variable and save that into an array.