SFSUserVariable, please give example

Post here your questions about the Objective-C API for SFS2X

Moderators: Lapo, Bax

uncleunvoid
Posts: 34
Joined: 11 Aug 2011, 12:40

SFSUserVariable, please give example

Postby uncleunvoid » 21 May 2012, 19:43

I have this in my code:

Code: Select all

NSArray *tVariables = [NSArray arrayWithObjects:[SFSUserVariable variableWithName:@"playerType" value:@"PLAYERTYPE_CHASER" type:nil],
                               [SFSUserVariable variableWithName:@"longitude" value:tLon type:nil],
                               [SFSUserVariable variableWithName:@"latitude" value:tLat type:nil],
                                        nil];


and it throws all sorts of irritations. also to retrieve the values after the event, is not quiet working, I only get the names of the vars not their values.

Could you guys generally update the iOS support with examples, please, its full of Flash stuff.
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Re: SFSUserVariable, please give example

Postby rjgtav » 21 May 2012, 20:21

Hello.
According to this documentation page, which also applies to all the other Client APIs, in the UserVariablesUpdate you only get a list of the names of the variables which were updated.
That said, in order to get the updated variable, you run something like (sorry I'm not an Objective-C programmer):

user.getVariable(myVariableName);

As you can then check by yourself, this method only returns a reference to the SFSUserVariable instance, not its value. In order to retrieve its value, you'll have to use one of the methods located here which return the correct value.
For example, for retrieving a Boolean variable with the name "myBool", you would something like (java code syntax, but the method names are correct):

Boolean myBoolean = user.getVariable("myBool").getBoolValue();
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
User avatar
A51Integrated
Posts: 240
Joined: 03 Jan 2012, 19:55
Location: Toronto, Canada
Contact:

Re: SFSUserVariable, please give example

Postby A51Integrated » 22 May 2012, 14:48

Here's an Obj-C example of setting and retrieving UserVariables on update:

Setting:

Code: Select all

SFSUserVariable *var = [SFSUserVariable variableWithName:@"myVarName" value:[NSNumber numberWithBool:YES]];
   
   [client send:[SetUserVariablesRequest requestWithUserVariables:[NSArray arrayWithObject:var]]];


Of course you can set a number of different data types. See the docs for more on that.

Getting a user variable on update:

Code: Select all

-(void)onUserVariablesUpdate:(SFSEvent *)evt {
   NSLog(@"onUserVariablesUpdate");
   NSArray *keys = [evt.params allKeys];
   
   for (NSString *key in keys) {
      NSLog(@"%@: %@", key, [evt.params objectForKey:key]);
   }
}


There are iOS examples - you can find them here: http://docs2x.smartfoxserver.com/Exampl ... troduction
A51 Integrated
http://a51integrated.com / +1 416-703-2300

Return to “SFS2X iPhone / iPad / OSX API”

Who is online

Users browsing this forum: No registered users and 18 guests