GlovePIE:Multiscript Switch Script

From WiiLi

Jump to: navigation, search


Update: Batch File Version 1.1 is available: Similar to first batch implementation but includes 8 script paths defined by default for easy editing. I've edited LED code to allow for the 8 scripts. Also the debug window now shows script name defined by var.Script#Name. Lastly I've added optional speech code to say the scripts name when switching between selected scripts. Version 1.1 can be found below the basic implementation(Version 1) code.

Batch File Version Status: Working
The batch file version of this script requires 3 parts: a batch file, adding some code to the scripts you want to be able to switch between and the script switch script.

Warning this version forces to kill cmd.exe and GlovePIE.exe processes. Be aware that if working with these programs any unsaved changes will be lost!

In the following examples the "GlovePIE.exe" file is located @: "C:\Program Files\GlovePIE029\GlovePIE.exe"

The first part of this script is a batch file: The Batch file in this example is located @: "C:\go.bat"

This file should be a normal text file with a ".bat" extension. The contents of the file should be as follows:

taskkill /F /IM GlovePIE.exe
%1 %2

The second part of this script are the other script files which you want to be able to switch between. In this example the scripts which can be accessed using the script switch script are:
"C:\MyScripts\Test1.PIE"
"C:\MyScripts\Test2.PIE"
"C:\MyScripts\Test3.PIE"
"C:\MyScripts\Test4.PIE"

Every one of these scripts must contain the following code:

//Hold down Wiimote.A & Wiimote.B & Wiimote.One & Wiimote.Two for 2 seconds to close the current
//script and activate script switch script
if !var.init
   var.BatchFilePath = "C:\go.bat"
   var.GlovePIEPath = "C:\Progra~1\GlovePIE029\GlovePIE.exe"
   //Make sure script path begins with a dash "-" so script opens running
   var.ScriptSwitchPath = "-C:\MyScripts\ScriptSwitch.PIE"
   
   Execute("taskkill", "/F /IM cmd.exe")
   var.init = true
endif

if Pressed(HeldDown(Wiimote.A && Wiimote.B && Wiimote.One && Wiimote.Two, 2s))
   Execute(var.BatchFilePath, var.GlovePIEPath + " " + var.ScriptSwitchPath)
endif
   
//Script contents here


The third and final part of the script is the Script Switch Script itself.
The Script Switch Script in this example is located @: "C:\MyScripts\ScriptSwitch.PIE"

The contents of this file should be as follows:

/*            Multiscript Switch Script V1.0
***********************************************************
*                 Created by Rhys Legault                 *
*                 rhyslegault@hotmail.com                 *
*             Last Modified: June 7th, 2007               *
***********************************************************
*  Feel free to use, modify and redistribute this script  *
***********************************************************
*  Use the Plus and minus to scroll through the scripts
*  Press Wiimote.Home or Wiimote.A to select the current script
*  Current script allows for only 4 scripts.  
*  Use the LEDs to identify selected script
*
*  If you add more scripts you will have to:
*    1: Change var.TotalScripts = 4 to the new number of scripts
*    2: Add new var.Script#Path = "-<ScriptPath>" for each new script
*    3: Create a new elseif var.CurrentScript = # for each new script (add scripts in order)
*    4: Adjust LEDs code
*    5: You will probably have to add more detail to remember which script is which 
*       - For this I would either change the debug box to display the script name or use GlovePIE's speech feature
*/

if !var.init
   var.TotalScripts = 4
   var.CurrentScript = 1
   var.BatchFilePath = "C:\go.bat"
   var.GlovePIEPath = "C:\Progra~1\GlovePIE029\GlovePIE.exe"
   //Make sure script path begins with a dash "-" so script opens running
   var.Script1Path = "-C:\MyScripts\Test1.PIE"
   var.Script2Path = "-C:\MyScripts\Test2.PIE"
   var.Script3Path = "-C:\MyScripts\Test3.PIE"
   var.Script4Path = "-C:\MyScripts\Test4.PIE"

   Execute("taskkill", "/F /IM cmd.exe")
   var.init = true
endif

if !var.Select
   //Sets Wiimote LEDs
   Wiimote.Leds = 2**(var.CurrentScript-1)
   
   //Wiimote.Plus and Wiimote.Minus cycles through modes
   if Pressed(Wiimote.Plus)
      if var.CurrentScript >= var.TotalScripts
         var.CurrentScript = 1
      else
         var.CurrentScript++
      endif
   elseif Pressed(Wiimote.Minus)
      if var.CurrentScript <= 1
         var.CurrentScript = var.TotalScripts
      else
         var.CurrentScript--
      endif
   endif
   
   //Wiimote.Home or Wiimote.A selects script
   if Pressed(Wiimote.Home) || Pressed(Wiimote.A) then var.Select = true
else
   if var.CurrentScript = 1
      Execute(var.BatchFilePath, var.GlovePIEPath + " " + var.Script1Path)
   elseif var.CurrentScript = 2
      Execute(var.BatchFilePath, var.GlovePIEPath + " " + var.Script2Path)
   elseif var.CurrentScript = 3
      Execute(var.BatchFilePath, var.GlovePIEPath + " " + var.Script3Path)
   elseif var.CurrentScript = 4
      Execute(var.BatchFilePath, var.GlovePIEPath + " " + var.Script4Path)
   endif
   var.Select = false
endif

debug = "Current Script: " + var.CurrentScript

Script Switch Script Version 1.1:

/*            Multiscript Switch Script V1.1
***********************************************************
*                 Created by Rhys Legault                 *
*                 rhyslegault@hotmail.com                 *
*             Last Modified: June 10th, 2007              *
***********************************************************
*  Feel free to use, modify and redistribute this script  *
***********************************************************
*  Use the Plus and minus to scroll through the scripts
*  Press Wiimote.Home or Wiimote.A to select the current script
*  The following script allows for 8 scripts.
*  Current selected script may be identified by:
*     LEDs, debug window identify selected script (Optional: say script name)
*
*  To use this script you must:
*  
*  1. Change var.BatchFilePath to path of a batch file with contents:
*     taskkill /F /IM GlovePIE.exe
*     %1 %2
*  2. Adjust var.SayScript = false if you want to disable speech
*  3. Adjust var.TotalScripts = # of scripts you want to switch between
*  4. Adjust var.Script#Path & var.Script#Name settings for all scripts up to
*     the var.TotalScripts you've defined
*     *You do not need to delete the path and name settings of scripts greater
*      than the var.TotalScripts*
*  5. If you add more than 8 scripts you will have to add led, debug window,
*     speech and execution settings.
*     Note: If you have a large number of scripts which you want to be able to
*     switch between using GlovePIE I suggest:
*        a. Editing this script to include a mode/genre select (using the d-pad)
*        b. Create a single script switch script to execute other script switch
*           scripts (one for each genre/related scripts)
*/

if !var.init
   //If set to true, script name spoken aloud - set to false to disable speech
   var.SayScript = true
   //Adjust if you add or remove scripts
   var.TotalScripts = 8

   var.BatchFilePath = "C:\go.bat"
   var.GlovePIEPath = "C:\Progra~1\GlovePIE029\GlovePIE.exe"

   //Make sure script path begins with a dash "-" so script opens running
   var.Script1Path = "-C:\MyScripts\Test1.PIE"
   var.Script1Name = "Test Script 1"

   var.Script2Path = "-C:\MyScripts\Test2.PIE"
   var.Script2Name = "Test Script 2"

   var.Script3Path = "-C:\MyScripts\Test3.PIE"
   var.Script3Name = "Test Script 3"

   var.Script4Path = "-C:\MyScripts\Test4.PIE"
   var.Script4Name = "Test Script 4"

   var.Script5Path = "-C:\MyScripts\Test5.PIE"
   var.Script5Name = "Test Script 5"

   var.Script6Path = "-C:\MyScripts\Test6.PIE"
   var.Script6Name = "Test Script 6"

   var.Script7Path = "-C:\MyScripts\Test7.PIE"
   var.Script7Name = "Test Script 7"

   var.Script8Path = "-C:\MyScripts\Test8.PIE"
   var.Script8Name = "Test Script 8"

   Execute("taskkill", "/F /IM cmd.exe")

   //Initial selected script settings
   var.CurrentScript = 0
   Wiimote.Leds = 0
   debug = "No script selected! Use + or - to select script"
   var.init = true
endif

if !var.Select

   //Wiimote.Plus and Wiimote.Minus cycles through modes
   if Pressed(Wiimote.Plus) || Pressed(Wiimote.Minus)
      if Pressed(Wiimote.Plus)
         if var.CurrentScript >= var.TotalScripts
            var.CurrentScript = 1
         else
            var.CurrentScript++
         endif
      elseif Pressed(Wiimote.Minus)
         if var.CurrentScript <= 1
            var.CurrentScript = var.TotalScripts
         else
            var.CurrentScript--
         endif
      endif

      if var.CurrentScript = 1
         Wiimote.Leds = 1
         debug = "Current Script: " + var.Script1Name
         if var.SayScript then say var.Script1Name
      elseif var.CurrentScript = 2
         Wiimote.Leds = 2
         debug = "Current Script: " + var.Script2Name
         if var.SayScript then say var.Script2Name
      elseif var.CurrentScript = 3
         Wiimote.Leds = 4
         debug = "Current Script: " + var.Script3Name
         if var.SayScript then say var.Script3Name
      elseif var.CurrentScript = 4
         Wiimote.Leds = 8
         debug = "Current Script: " + var.Script4Name
         if var.SayScript then say var.Script4Name
      elseif var.CurrentScript = 5
         Wiimote.Leds = 3
         debug = "Current Script: " + var.Script5Name
         if var.SayScript then say var.Script5Name
      elseif var.CurrentScript = 6
         Wiimote.Leds = 6
         debug = "Current Script: " + var.Script6Name
         if var.SayScript then say var.Script6Name
      elseif var.CurrentScript = 7
         Wiimote.Leds = 12
         debug = "Current Script: " + var.Script7Name
         if var.SayScript then say var.Script7Name
      elseif var.CurrentScript = 8
         Wiimote.Leds = 15
         debug = "Current Script: " + var.Script8Name
         if var.SayScript then say var.Script8Name
      endif
   endif
   
   //Wiimote.Home or Wiimote.A selects script
   if ((Pressed(Wiimote.Home) || Pressed(Wiimote.A)) && (var.CurrentScript != 0)) then var.Select = true

else
   Wiimote.Leds = 0
   debug = debug + " Loading..."   
   if var.SayScript then say "Loading Script"
   if var.SayScript then wait 1s

   if var.CurrentScript = 1
      Execute(var.BatchFilePath, var.GlovePIEPath + " " + var.Script1Path)
   elseif var.CurrentScript = 2
      Execute(var.BatchFilePath, var.GlovePIEPath + " " + var.Script2Path)
   elseif var.CurrentScript = 3
      Execute(var.BatchFilePath, var.GlovePIEPath + " " + var.Script3Path)
   elseif var.CurrentScript = 4
      Execute(var.BatchFilePath, var.GlovePIEPath + " " + var.Script4Path)
   elseif var.CurrentScript = 5
      Execute(var.BatchFilePath, var.GlovePIEPath + " " + var.Script5Path)
   elseif var.CurrentScript = 6
      Execute(var.BatchFilePath, var.GlovePIEPath + " " + var.Script6Path)
   elseif var.CurrentScript = 7
      Execute(var.BatchFilePath, var.GlovePIEPath + " " + var.Script7Path)
   elseif var.CurrentScript = 8
      Execute(var.BatchFilePath, var.GlovePIEPath + " " + var.Script8Path)
   endif

   var.Select = false
endif


The following is another implementation of the Script Switch Script which does not require the use of batch files. Currently this version DOES NOT work properly.

DO NOT USE THE FOLLOWING SCRIPT! ExitPIE does not work properly. The GUI disappears but the process remains in memory. If the ExitPIE function bug is eliminated in the future the following script would a better implementation than the batch file solution for obvious reasons.

Warning: Save your scripts before running these scripts. The function ExitPIE is used which closes the current script without prompting for save. This means any changes you have made to the script will be lost.

This script has 2 parts: The first part is the switch script file. The second part is a partial script which must be contained in all the scripts you want to be able to switch between.

You must change the paths in these scripts for them to work.
GlovePIE's directory in this example is contained in the "C:\Program Files\GlovePIE029\" directory
All scripts are contained in the "C:\MyScripts\" directory:
"C:\MyScripts\ScriptSwitch.PIE" - Script switch script
"C:\MyScripts\Test1-4.PIE" - Sample scripts which you can switch between

ScriptSwitch.PIE - Script Switch Script:

/* Use the Plus and minus to scroll through the scripts
*  Press Wiimote.Home or Wiimote.A to select the current script
*  Current script allows for only 4 scripts.  
*  Use the LEDs to identify selected script
*
*  If you add more scripts you will have to:
*    1: Change var.TotalScripts = 4 to the new number of scripts
*    2: Add new var.Script#Path = "-<ScriptPath>" for each new script
*    3: Create a new elseif var.CurrentScript = # for each new script (add scripts in order)
*    4: Adjust LEDs code
*    5: You will probably have to add more detail to remember which script is which 
*       - For this I would either change the debug box to display the script name or use GlovePIE's speech feature
*/

if !var.Initialize
   var.TotalScripts = 4
   var.CurrentScript = 1
   var.GlovePIEPath = "C:\Progra~1\GlovePIE029\GlovePIE.exe"
   //Make sure script path begins with a dash "-" so script opens running
   var.Script1Path = "-C:\MyScripts\Test1.PIE"
   var.Script2Path = "-C:\MyScripts\Test2.PIE"
   var.Script3Path = "-C:\MyScripts\Test3.PIE"
   var.Script4Path = "-C:\MyScripts\Test4.PIE"
   var.Initialize = true
endif

if !var.Select
   //Sets Wiimote LEDs
   Wiimote.Leds = 2**(var.CurrentScript-1)
   
   //Wiimote.Plus and Wiimote.Minus cycles through modes
   if Pressed(Wiimote.Plus)
      if var.CurrentScript >= var.TotalScripts
         var.CurrentScript = 1
      else
         var.CurrentScript++
      endif
   elseif Pressed(Wiimote.Minus)
      if var.CurrentScript <= 1
         var.CurrentScript = var.TotalScripts
      else
         var.CurrentScript--
      endif
   endif
   
   //Wiimote.Home or Wiimote.A selects script
   if Pressed(Wiimote.Home) || Pressed(Wiimote.A) then var.Select = true
else
   if var.CurrentScript = 1
      Execute(var.GlovePIEPath, var.Script1Path)
      ExitPIE
   elseif var.CurrentScript = 2
      Execute(var.GlovePIEPath, var.Script2Path)
      ExitPIE
   elseif var.CurrentScript = 3
      Execute(var.GlovePIEPath, var.Script3Path)
      ExitPIE
   elseif var.CurrentScript = 4
      Execute(var.GlovePIEPath, var.Script4Path)
      ExitPIE
   endif
endif

debug = "Current Script: " + var.CurrentScript

This next script must be contained in all scripts you are switching between. It simply opens up the script switch script and then closes the current script.

Test1-4.PIE - Sample Scripts:

//Hold down Wiimote.Home for 3 seconds to execute the script switch script

if !var.Initialize
   var.GlovePIEPath = "C:\Progra~1\GlovePIE029\GlovePIE.exe"
   //Make sure script path begins with a dash "-" so script opens running
   var.ScriptSwitchPath = "-C:\MyScripts\ScriptSwitch.PIE"
   var.Initialize = true
endif

//Holding down Wiimote.Home for 3 seconds executes the script switch script and then closes the current script
if Pressed(HeldDown(Wiimote.Home, 3s))
   Execute(var.GlovePIEPath, var.ScriptSwitchPath)
   ExitPIE
endif
   
//Add script content here
Personal tools