Page 1 of 1

Need help to get data from RoomVariablesUpdate Callback

Posted: 28 Feb 2017, 08:58
by JustinTimbersaw
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.

Re: Need help to get data from RoomVariablesUpdate Callback

Posted: 01 Mar 2017, 17:10
by Lapo
Hi,
I've asked our C++ developer to look into it. We'll try to reproduce it.
Stay tuned.

Re: Need help to get data from RoomVariablesUpdate Callback

Posted: 02 Mar 2017, 03:16
by JustinTimbersaw
Thanks for your response.

Re: Need help to get data from RoomVariablesUpdate Callback

Posted: 05 Mar 2017, 15:10
by JustinTimbersaw
Any help please!

Re: Need help to get data from RoomVariablesUpdate Callback

Posted: 06 Mar 2017, 11:52
by MBagnati
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

Re: Need help to get data from RoomVariablesUpdate Callback

Posted: 07 Mar 2017, 02:30
by JustinTimbersaw
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