use of .OnCheckStateChanged
Hello community :)
I'm having troubles trying to call a function when the player check a check box.
Following the example of the StrategyGame that use .OnClicked(this, &SStrategyActionGrid::TriggerAction, i*GridRows+j) on a button I tried to do .OnCheckStateChanged(this, &SBookMarks::TextSelected) on my check box.
The function declaration goes like : FReply TextSelected() const;
And I'm getting : Error 1 error C2664: 'SCheckBox::FArguments::WidgetArgsType &SCheckBox::FArguments::OnCheckStateChanged(const FOnCheckStateChanged &)' : cannot convert argument 2 from 'FReply (__cdecl SBookMarks:: )(void) const' to 'void (__cdecl SBookMarks:: )(Param1Type)' C:\Users\Adinimys\Documents\Unreal Projects\MyProject6\Source\MyProject6\BookMarks.cpp 28
Additionaly, I noticed that even though the StrategyExample almost use "this" in the "parameters" (I don't know how is it called) of the widgets, the ShooterGame example do that really less often and I never used it in my own code that is working nonetheless (appart from the function call). Could someone explain my what is the point of "this" in that situation ? With slate documation currently returning a 404 error, the unique syntax of widgets is really tricky to understand :/
Thank you for answering my questions :)
asked Nov 25 '14 at 10:37 AM in C++ Programming
From the error you pasted I assume your SBookMarks::TextSelected looks like this:
this function can be used to create a delegate that will be called during SButton click (OnClicked) however SCheckBox::OnCheckStateChanged uses different function that returns nothing and takes one parameter, so your TextSelected function should look like this:
About "this" keyword. I assume you know what it does (if not: http://www.cplusplus.com/forum/beginner/39333/).
So Slate widgets can have different type of parameters. Most common would be:
If you go to SCheckBox.h file you can see that OnCheckStateChanged is actually SLATE_EVENT parameter so you will need to pass a pointer to a function that should be executed when "check state is changed".
Also, I would recommend going through examples stored in STestSuite.cpp and SWidgetGallery.cpp when it comes to basic stuff like this. Strategy/Shooter game examples are kinda more advanced and can be confusing if you're not at least somewhat familiar with Slate.
Hope this helps in some way.
answered Nov 25 '14 at 05:50 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here