button_state works for me ! look at the following example, it uses button_state to switch the state of the toggle button ! it uses a toggle button and switches it on/off depending on its current state, using button_state (when space is pressed) ! The state is also changed if you press the button, but remember to move the mouse away from the button to see it's state (because of mouseOver and mouseOverOff)
Code:
// here's some sample code
private static PANEL p;
private static IEnumerable<ScheduleMethod> switchStateOfButtonUsingButtonState()
{
// first get old state... -1 means DON'T change state of the button
double oldState =
p.button_state(1, -1);
// then switch the state, according to the return value
if (oldState == 0)
{
// switch to on
p.button_state(1, 1);
}
else
{
// switch to off
p.button_state(1, 0);
}
yield break;
}
public static IEnumerable<ScheduleMethod> myMainMethod()
{
// use mouse !!
EngVar.mouse_mode = 4;
p =
PANEL.pan_create(null, 1);
p.SHOW = true;
p.pos_x = 100;
p.pos_y = 100;
p.size_x = 500;
p.size_y = 500;
BMAP on =
BMAP.bmap_createblack(200, 200, 32);
on.bmap_fill(new Color(0, 255, 0), 50);
BMAP off =
BMAP.bmap_createblack(200, 200, 32);
off.bmap_fill(new Color(0, 0, 255), 50);
BMAP over =
BMAP.bmap_createblack(200, 200, 32);
over.bmap_fill(new Color(200, 200, 20), 50);
p.pan_setbutton(
0,
2,
50,
50,
on,
off,
over,
over,
null,
null,
null);
EngVar.on_space +=
switchStateOfButtonUsingButtonState;
yield break;
}
static void Main(string[] args)
{
EngFun.engine_open(null, null);
EngFun.level_load(null);
Scheduler.StartScheduler(myMainMethod);
}