|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
What does SendableChooser.GetSelected() return as?
http://first.wpi.edu/FRC/roborio/rel...leChooser.html
The library says it returns as a void pointer, but what does that information return like? Does it return the name of the option that is put in with this, autoChooser.AddObject("Lowbar Auto", new Auto); "Lowbar Auto" is the name of the option, and can I use it in an if statement like, if (autoChooser.GetSelected() == "Lowbar Auto") { //Stuff for lowbar auto } |
|
#2
|
|||
|
|||
|
Re: What does SendableChooser.GetSelected() return as?
I haven't used C++ for robot programming but being familiar with C and C++ APIs, it looks like it will return the object you passed in as the second parameter to AddObject().
This code: Code:
if (autoChooser.GetSelected() == "Lowbar Auto") {
//Stuff for lowbar auto
}
Also, Code:
autoChooser.AddObject("Lowbar Auto", new Auto);
|
|
#3
|
|||
|
|||
|
Re: What does SendableChooser.GetSelected() return as?
I knew already it didn't work, so that's why I was asking. And I found the solution anyways
autoSelected = *((std::string*)chooser->GetSelected()); if(autoSelected == autoNameCustom){ //Custom Auto goes here } else { //Default Auto goes here } |
|
#4
|
|||
|
|||
|
Re: What does SendableChooser.GetSelected() return as?
Out of curiosity, did you also change your second parameter to AddObject to a std::string?
|
|
#5
|
||||
|
||||
|
Re: What does SendableChooser.GetSelected() return as?
It returns a void*, which you cast to a Whatever* that you passed into AddObject (in your case, Command*)
Code:
autoChooser.AddObject("Lowbar Auto", new Auto);
// Then in autonomous init
((Command*) autoChooser.GetSelected())->Start();
It's not a memory leak since you'd never normally delete your auto commands anyway. |
|
#6
|
|||
|
|||
|
Re: What does SendableChooser.GetSelected() return as?
Yes I did, but I just didn't show it.
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|