API 1.6.4 Example from docs2x not working

Post here your questions about the C++ API for SFS2X

Moderators: Lapo, Bax, MBagnati

ToxaDev
Posts: 4
Joined: 21 Sep 2016, 18:22

API 1.6.4 Example from docs2x not working

Postby ToxaDev » 21 Sep 2016, 18:33

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

Re: API 1.6.4 Example from docs2x not working

Postby Lapo » 22 Sep 2016, 06:50

Hi,
thanks for reporting.
I think it should be --> new SFSUserVariable ...

Let me know if it fixes the problem.

Cheers
Lapo
--
gotoAndPlay()
...addicted to flash games
ToxaDev
Posts: 4
Joined: 21 Sep 2016, 18:22

Re: API 1.6.4 Example from docs2x not working

Postby ToxaDev » 22 Sep 2016, 08:28

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

Re: API 1.6.4 Example from docs2x not working

Postby Lapo » 22 Sep 2016, 13:24

I've forwarded your request to our C++ expert. Stay tuned...
Lapo

--

gotoAndPlay()

...addicted to flash games
MBagnati
Posts: 125
Joined: 12 Feb 2013, 10:57

Re: API 1.6.4 Example from docs2x not working

Postby MBagnati » 23 Sep 2016, 08:43

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
ToxaDev
Posts: 4
Joined: 21 Sep 2016, 18:22

Re: API 1.6.4 Example from docs2x not working

Postby ToxaDev » 23 Sep 2016, 13:26

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!
ToxaDev
Posts: 4
Joined: 21 Sep 2016, 18:22

Re: API 1.6.4 Example from docs2x not working

Postby ToxaDev » 25 Sep 2016, 21:03

Solved!

Return to “SFS2X C++ API”

Who is online

Users browsing this forum: No registered users and 1 guest