I need a getUserVariables example for the iPhone client

Post here all your questions related with the SmartFoxServer iPhone API

Moderators: Lapo, Bax

intomo
Posts: 28
Joined: 22 Nov 2010, 21:21
Location: Los Angeles

I need a getUserVariables example for the iPhone client

Postby intomo » 25 Feb 2011, 21:02

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.
rahulvyas
Posts: 19
Joined: 05 Jul 2010, 05:23
Location: Jaipur,Rajasthan
Contact:

Postby rahulvyas » 28 Feb 2011, 05:03

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.
Thanks & Regards,
Rahul Vyas,
iPhone Developer.
intomo
Posts: 28
Joined: 22 Nov 2010, 21:21
Location: Los Angeles

Postby intomo » 28 Feb 2011, 16:52

Thanks.
Could you possibly post an example of how you would get variables looping thru all users in a room?
rahulvyas
Posts: 19
Joined: 05 Jul 2010, 05:23
Location: Jaipur,Rajasthan
Contact:

Postby rahulvyas » 01 Mar 2011, 01:33

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.
Thanks & Regards,

Rahul Vyas,

iPhone Developer.
intomo
Posts: 28
Joined: 22 Nov 2010, 21:21
Location: Los Angeles

Postby intomo » 01 Mar 2011, 15:45

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.

Return to “iPhone Objective-C API”

Who is online

Users browsing this forum: No registered users and 2 guests