Page 1 of 1

API 1.6.4 Example from docs2x not working

Posted: 21 Sep 2016, 18:33
by ToxaDev
Hi!

Example link - http://docs2x.smartfoxserver.com/api-docs/cpp-doc/class_sfs2_x_1_1_requests_1_1_set_user_variables_request.html

I try to send SetUserVariablesRequest like in example:

Code: Select all

boost::shared_ptr<UserVariable> variable (new UserVariable ("avatarType", "SwedishCook", VARIABLETYPE_STRING));


But compiler says:

Code: Select all

Error   C2259   'Sfs2X::Entities::Variables::UserVariable': cannot instantiate abstract class


API version 1.6.4
VS 2015

Help please

Re: API 1.6.4 Example from docs2x not working

Posted: 22 Sep 2016, 06:50
by Lapo
Hi,
thanks for reporting.
I think it should be --> new SFSUserVariable ...

Let me know if it fixes the problem.

Cheers

Re: API 1.6.4 Example from docs2x not working

Posted: 22 Sep 2016, 08:28
by ToxaDev
Thanks for response!

I also thought that we should try SFSUserVariable, but got new errors:

Code: Select all


Error   C2664   'Sfs2X::Entities::Variables::SFSUserVariable::SFSUserVariable(const Sfs2X::Entities::Variables::SFSUserVariable &)': cannot convert argument 2 from 'const char [6]' to 'boost::shared_ptr<void>'   

Error   C2664   'Sfs2X::Requests::SetUserVariablesRequest::SetUserVariablesRequest(const Sfs2X::Requests::SetUserVariablesRequest &)': cannot convert argument 1 from 'boost::shared_ptr<std::vector<boost::shared_ptr<Sfs2X::Entities::Variables::SFSUserVariable>,std::allocator<_Ty>>>' to 'boost::shared_ptr<std::vector<boost::shared_ptr<Sfs2X::Entities::Variables::UserVariable>,std::allocator<_Ty>>>'



May be you need to update docs for API 1.6.4

I really need to working example here

Thanks!

Re: API 1.6.4 Example from docs2x not working

Posted: 22 Sep 2016, 13:24
by Lapo
I've forwarded your request to our C++ expert. Stay tuned...

Re: API 1.6.4 Example from docs2x not working

Posted: 23 Sep 2016, 08:43
by MBagnati
Hi,
I am sorry...you are right....there is an error in documentation.

The UserVariable class is an abstract base class that is common to all "Variable" entities.
An instance of this class cannot be created.

To have an user variable you must use the SFSUserVariable item.
The SFSUserVariable constructor requires a string as variable name and a void pointer as variable value.
The void pointer is the trick to assign everything (a string...an integer...an SFSArray...etc.) as variable value.
To create a "avatarType" user variable with value "SwedishCook", you should write these statements:

Code: Select all

      boost::shared_ptr<std::string> variableValue(new string("SwedishCook"));
      boost::shared_ptr<UserVariable> variable(new SFSUserVariable("avatarType", variableValue, VARIABLETYPE_STRING));

Thanks for your report, I will update the documentation

Re: API 1.6.4 Example from docs2x not working

Posted: 23 Sep 2016, 13:26
by ToxaDev
MBagnati, thank you!

After some trys of convertation, now it work.

Code: Select all

boost::shared_ptr<UserVariable> variable(new SFSUserVariable("sModel", *reinterpret_cast<boost::shared_ptr<void>*>(&modelName), VARIABLETYPE_STRING));


And i need to ask you some other question about UserVariables
When i received OnUserVariablesUpdate event from server, i try to convert array of strings to TArray<FString>. But i got exception.
Can you give some working example for this issue?

Image
Image

Thank you!

Re: API 1.6.4 Example from docs2x not working

Posted: 25 Sep 2016, 21:03
by ToxaDev
Solved!