Need help to get data from RoomVariablesUpdate Callback

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

Moderators: Lapo, Bax, MBagnati

JustinTimbersaw
Posts: 4
Joined: 28 Feb 2017, 08:19

Need help to get data from RoomVariablesUpdate Callback

Postby JustinTimbersaw » 28 Feb 2017, 08:58

Hi guys, i'm have a trouble when get data from callback of ROOM_VARIABLES_UPDAPTE event.
Here is my code:

Code: Select all

void MyClass::OnRoomVariablesUpdate(unsigned long long ptrContext, boost::shared_ptr<BaseEvent> ptrEvent)
{
   boost::shared_ptr<map<string, boost::shared_ptr<void>>> ptrEventParams = ptrEvent->Params();
   boost::shared_ptr<void> ptrEventParamValueVars = (*ptrEventParams)["changedVars"];
   boost::shared_ptr<vector<boost::shared_ptr<string>>> changedVars = ((boost::static_pointer_cast<vector<boost::shared_ptr<string>>>)(ptrEventParamValueVars));

   vector<boost::shared_ptr<string>> MyVector = *changedVars; // Error in this step.
}

I got this message: http://imgur.com/1Nr8GPk
I am not experienced with C++ so i really need help.
User avatar
Lapo
Site Admin
Posts: 19941
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Need help to get data from RoomVariablesUpdate Callback

Postby Lapo » 01 Mar 2017, 17:10

Hi,
I've asked our C++ developer to look into it. We'll try to reproduce it.
Stay tuned.
Lapo
--
gotoAndPlay()
...addicted to flash games
JustinTimbersaw
Posts: 4
Joined: 28 Feb 2017, 08:19

Re: Need help to get data from RoomVariablesUpdate Callback

Postby JustinTimbersaw » 02 Mar 2017, 03:16

Thanks for your response.
JustinTimbersaw
Posts: 4
Joined: 28 Feb 2017, 08:19

Re: Need help to get data from RoomVariablesUpdate Callback

Postby JustinTimbersaw » 05 Mar 2017, 15:10

Any help please!
MBagnati
Posts: 125
Joined: 12 Feb 2013, 10:57

Re: Need help to get data from RoomVariablesUpdate Callback

Postby MBagnati » 06 Mar 2017, 11:52

Hi,
Please try this code

Code: Select all

   boost::shared_ptr<map<string, boost::shared_ptr<void>>> ptrEventParams = ptrEvent->Params();
   boost::shared_ptr<void> ptrEventParamValueVars = (*ptrEventParams)["changedVars"];
   boost::shared_ptr<vector<string>> changedVars = ((boost::static_pointer_cast<vector<string>>)(ptrEventParamValueVars));

   vector<string> MyVector = *changedVars;


The question is that changedVars vector contains strings; not shared_ptr of strings

therefore use
boost::shared_ptr<vector<string>> changedVars = ((boost::static_pointer_cast<vector<string>>)(ptrEventParamValueVars));
vector<string> MyVector = *changedVars;

instead of
boost::shared_ptr<vector<boost::shared_ptr<string>>> changedVars = ((boost::static_pointer_cast<vector<boost::shared_ptr<string>>>)(ptrEventParamValueVars));
vector<boost::shared_ptr<string>> MyVector = *changedVars;

Let me know if this suggestion has been useful
JustinTimbersaw
Posts: 4
Joined: 28 Feb 2017, 08:19

Re: Need help to get data from RoomVariablesUpdate Callback

Postby JustinTimbersaw » 07 Mar 2017, 02:30

Thanks, it's solved my problem. I followed the example #2 of bellow URL and got that error, so pls update :)
http://docs2x.smartfoxserver.com/api-docs/cpp-doc/class_sfs2_x_1_1_requests_1_1_set_room_variables_request.html#a033f8c65b724c7b18e0d267a11722416

Return to “SFS2X C++ API”

Who is online

Users browsing this forum: No registered users and 1 guest