Arrays with mzScript Thread last updated on 2004-07-20 20:03:37

Posted by member 182 on 2004-07-18 20:20:27

Hey y'all :)

You know i've been at this for a while. Life getting too busy / me getting too lazy has put iLG on hold for far too long, so i figured what better place to come to than the Litestep.net community for help on the final part of this theme!

Okay, most of you already know there's a label setup atm which shows one drive's free space, which when left clicked toggles to another label, and back again.

What i want to do is have a $var$ in themevars.rc which will be something like
drives c d e f z


mzScript will read that in, and every time the label is clicked it'll cycle through all the drives, in that order.

atm the code is very half assed, ie:
*script bang !switchHDD

*script !varset drive_array %{drives}:end

*Script label loop

*script gotoif ("%{drivearray:%{\%{drvcount%}}" = "end") _counted
*script exec !varadd drvcount 1
*script goto loop

*Script label _counted

*script !ifeq drive2 %{drivearray:%{\%{drvcount%}} '|varset drive1 %{drive2}'

*script gotoif ("%{nextHDD}" = "end") _first

*Script label stopstop
*Script ~bang


You can kinda see what i'm getting at ..

The principle is that on startup the script will read $drives$ into %{drivearray}, insert 'end' as the last item in the array, and set the current displayed label to %{currentHDD}.

Whenever the label(s) are clicked, the script will read in the current drive, set the alternate label to the next drive in the array, and hide the current label. If the next drive in the array is equal to 'end' though, it's to show the first drive in the list.

So in short, you can keep clicking the label(s) and it cycles right through all the drives on your system!
Anyone wanna help me out so i can finally release this theme? :D

Posted by member 37809 on 2004-07-18 21:12:04 link

Using spaces in (newer) mzscript vars is asking for trouble.

But I don't want to follow your method because it has the exception of handling the "end". pika told me the cool way to cycle through a list, taking advantage of this data structure--mzscript doesn't yet have arrays :/

Let the user set your drives, separated by colons
drives c:d:e:f:z

...and you
*script start !varset drives $drives$
.

Now, if you want to cycle through the drives, simply
!varset drives %{drives:_}:%{drives:}
; ^this will grab the first of the list and stick it at the end of the list


The above assumes you have more than one list item in your list however. If you wanted to check if the user only had one drive you could try something like this:
*script gotoif ("%{drives:_}" = "") handleOnlyOneDrive
; user has set it to more than one drive
*script exit ; or jump elsewhere
*script label handleOnlyOneDrive


Anyhow, I guess you're using two labels to animate in transition or something.

Suppose your two labels are LabelA and LabelB

On startup, I guess you want to just
*script start !exec |LabelSetText LabelA "%{drives:}"
*script start !varset drives %{drives:_}:%{drives:}
*script start !exec |LabelSetText LabelB "%{drives:}"

...and keep a boolean variable to tell which label is 'active':
*script start !varset is_a_active 1


Then try a bang such as this:
*script bang !DriveCycle
*script gotoif ("%{is_a_active}" = "1") make_b_active
; make a active
*script exec !varset is_a_active 1
*script exec !LabelMove LabelA 0 0
*script exec !LabelMove LabelB 200 200
*script exec !varset drives %{drives:_}:%{drives:}
*script exec !LabelSetText LabelB "%{drives:}"
*script goto rest
*script label make_b_active
*script exec !varset is_a_active 0
*script exec !LabelMove LabelB 0 0
*script exec !LabelMove LabelA 200 200
*script exec !varset drives %{drives:_}:%{drives:}
*script exec !LabelSetText LabelA "%{drives:}"
*script label rest
*script ~bang


Of course, set all the label texts appropriately and instead of moving them do your transition.

It could get complicated if you wanted to remember the last 'view'. It's because of the setting of the mzscript var to the evar... So replace that *script start !varset drives $drives$ with a call to something (untested) like:
*script bang !DrivesCheck
*script exec !varset temp "%{drives}"
*script exec !varset seen "%{drives:}"
*script label loop
*script gotoif ("%{temp}" = "$drives$") old
*script exec !varset temp %{temp:_}:%{temp:}
*script gotoif ("%{temp:}" = "%{seen}") new
*script goto loop
*script label new
*script exec !varset drives $drives$
*script label old
*script ~bang

and have the var drives in a varfile.

Posted by member 37809 on 2004-07-18 23:12:26 link

You know what? I probably wouldn't have typed the above long reply if I would have read your post more closely the first time around. Of course if you're willing to rescript go ahead. See !listlen and !listget as I've just posted some of my old list bangs.

Posted by member 182 on 2004-07-20 20:03:37 link

hmmmmm
food for thought :D