Script turn switch on

Hello, ich have a little problem. I have a crafting script, if i close the craftwindow the menu ist popping up. If i switch the switch menu off bevor the craftmenu is starting the normal menu don´t pop up pressing B after i close the crafting system. The switch for the menu is switch 24. The script part to close the craftmenu is this

Code:
def update_material
   # if B Button is pressed
   if Input.trigger?(Input::B)
     # Play cancel SE
     $game_system.se_play($data_system.cancel_se)
     # Switch to map screen
     $scene = Scene_Map.new
     return
   end

So, how can i switch the switch 24 to on?
Moved to: RGSSx Script Support

This is for XP
$game_switches[24] = true

Place it above $scene = Scene_Map.new

Original thread: https://forums.rpgmakerweb.com/threads/script-turn-switch-on.154472/