Posted by member 37809 on 2003-10-23 11:07:49
Traditional ways of using scripted bangs through mzscript to toggle modules' visibility with and without memory between litestep sessions/recycles.
This is for if you wish to have toggle buttons or the like to toggle visibility of modules instantly (without a recycle). It involves the hiding and showing of modules, as opposed to the loading/unloading (or creating/destroying stuff) of modules.*
METHOD 1: separate bangs.
To remember state, have variable FOO_visible "1" in a *mzVarFile (or in .rc, depending on mzscript version).
(hint: replace all instances of 'FOO' to whatever for copying/pasting)
METHOD 2: single bang, because you don't like method 1; "it's needlessly big!", etc.
Again have FOO_visible defined in a varfile.
METHOD 3: toggle bang only, without memory.
useful if one of the modules you want to control lacks a !toggle bang.
The way this one is designed, you need not have FOO_visible defined initially.
But it also assumes you have the module(s) whose visibility you wish to control initially hidden by settings. If you wanted them initially shown, you could have FOO_visible "1" in a varfile or have *script start !varset FOO_visible "1". Also do not autosave vars.
Modify as you see fit to get the behaviour you want. As with everything, mzscript is dumb, so you must coordinate scripting and settings.
For variation, you can also use textedit to set .rc settings for the visibility of modules instead of using *script start's. If you don't want to use textedit, you can simply put the relevant .rc settings in a varfile. You can manipulate these as variables through mzscript, and (use the step.rc directive) include <varfile> so that modules can still use them.
*IMO these methods are still potentially complicated to implement.
This is for if you wish to have toggle buttons or the like to toggle visibility of modules instantly (without a recycle). It involves the hiding and showing of modules, as opposed to the loading/unloading (or creating/destroying stuff) of modules.*
METHOD 1: separate bangs.
To remember state, have variable FOO_visible "1" in a *mzVarFile (or in .rc, depending on mzscript version).
*script bang !_FOO_toggle
*script exec !ifeval ("%{FOO_visible}" = "0") '|_FOO_show' else '|_FOO_hide'
*script ~bang
*script bang !_FOO_hide
*script exec !hideSomethingEtc
*script exec !hideSomethingElse
*script exec !varset FOO_visible 0
*script exec !varsave FOO_visible
*script ~bang
*script bang !_FOO_show
*script exec !showSomethingEtc
*script exec !showSomethingElse
*script exec !varset FOO_visible 1
*script exec !varsave FOO_visible
*script ~bang
; assumes you have whatever you want to toggle initially hidden by .rc settings
*script start !ifeval ("%{FOO_visible}" = "1") '|_FOO_show'
*script exec !ifeval ("%{FOO_visible}" = "0") '|_FOO_show' else '|_FOO_hide'
*script ~bang
*script bang !_FOO_hide
*script exec !hideSomethingEtc
*script exec !hideSomethingElse
*script exec !varset FOO_visible 0
*script exec !varsave FOO_visible
*script ~bang
*script bang !_FOO_show
*script exec !showSomethingEtc
*script exec !showSomethingElse
*script exec !varset FOO_visible 1
*script exec !varsave FOO_visible
*script ~bang
; assumes you have whatever you want to toggle initially hidden by .rc settings
*script start !ifeval ("%{FOO_visible}" = "1") '|_FOO_show'
(hint: replace all instances of 'FOO' to whatever for copying/pasting)
METHOD 2: single bang, because you don't like method 1; "it's needlessly big!", etc.
Again have FOO_visible defined in a varfile.
*script bang !_FOO_toggle
*script goto ("%{FOO_visible}" = "1") hide
*script exec !showSomethingEtc
*script exec !showSomethingElse
*script exec !varset FOO_visible 1
*script goto rest
*script label hide
*script exec !hideSomethingEtc
*script exec !hideSomethingElse
*script exec !varset FOO_visible 0
*script label rest
*script exec !varsave FOO_visible
*script ~bang
; and so you duplicate commands for showing here.
*script start !ifeval ("%{FOO_visible}" = "1") '|execute [!showSomethingEtc][!showSomethingElse]'
*script goto ("%{FOO_visible}" = "1") hide
*script exec !showSomethingEtc
*script exec !showSomethingElse
*script exec !varset FOO_visible 1
*script goto rest
*script label hide
*script exec !hideSomethingEtc
*script exec !hideSomethingElse
*script exec !varset FOO_visible 0
*script label rest
*script exec !varsave FOO_visible
*script ~bang
; and so you duplicate commands for showing here.
*script start !ifeval ("%{FOO_visible}" = "1") '|execute [!showSomethingEtc][!showSomethingElse]'
METHOD 3: toggle bang only, without memory.
useful if one of the modules you want to control lacks a !toggle bang.
The way this one is designed, you need not have FOO_visible defined initially.
*script bang !_FOO_toggle
*script gotoif ("%{FOO_visible}" <> "1") show
*script exec !hideSomethingEtc
*script exec !hideSomethingElse
*script exec !varset FOO_visible 0
*script exit
*script label show
*script exec !showSomethingEtc
*script exec !showSomethingElse
*script exec !varset FOO_visible 1
*script ~bang
*script gotoif ("%{FOO_visible}" <> "1") show
*script exec !hideSomethingEtc
*script exec !hideSomethingElse
*script exec !varset FOO_visible 0
*script exit
*script label show
*script exec !showSomethingEtc
*script exec !showSomethingElse
*script exec !varset FOO_visible 1
*script ~bang
But it also assumes you have the module(s) whose visibility you wish to control initially hidden by settings. If you wanted them initially shown, you could have FOO_visible "1" in a varfile or have *script start !varset FOO_visible "1". Also do not autosave vars.
Modify as you see fit to get the behaviour you want. As with everything, mzscript is dumb, so you must coordinate scripting and settings.
For variation, you can also use textedit to set .rc settings for the visibility of modules instead of using *script start's. If you don't want to use textedit, you can simply put the relevant .rc settings in a varfile. You can manipulate these as variables through mzscript, and (use the step.rc directive) include <varfile> so that modules can still use them.
*IMO these methods are still potentially complicated to implement.