Repeating a hilite command over several cards

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

bidgeeman
Posts: 495
Joined: Wed Feb 21, 2007 7:58 am

Repeating a hilite command over several cards

Post by bidgeeman » Sun Jun 14, 2009 7:24 am

Hello.
Can anyone offer me some advice on a new user question please?

I am trying to set the hilite of a set of buttons over several cards using.

Code: Select all

   repeat with i = 1 to the number of buttons 
      if the short name of button i contains "Track" then 
         set the hilite of button i to false
      end if
   end repeat
This works fine for buttons on the current card. So I added

Code: Select all

repeat with i = 1 to number of cards

But this does not work for the other cards in the stack.
I'm not sure why?



Any help would be really appreciated :)
Thanks
Bidge

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Post by bn » Sun Jun 14, 2009 8:46 am

bidge,

it works if you do this routine lets say from a button on the card where the "track" buttons are (tested). Rev assumes that the button i is the 'button i of this card of this stack'. If you issue that command from another card it will fail because Rev does not know where to find your buttons (tested). Of course the same holds true for another stack. What happens if you change all references to your button to: button x of card y. Or if you call it from another stack to
button x of card y of stack z.

edit:


you have to do 2 repeat loops
1 that loops through the cards
and 1 that loops through the buttons.

Code: Select all

repeat with k = 1 to the number of cards
        repeat with i = 1 to the number of buttons of card k
            if the short name of button i of card k contains "Track" then
                set the hilite of button i of card k to  false
            end if
        end repeat
    end repeat
regards
Bernd

bidgeeman
Posts: 495
Joined: Wed Feb 21, 2007 7:58 am

Post by bidgeeman » Sun Jun 14, 2009 9:06 am

Ahh Thanks Bernd...that makes perfect sense. I'm kicking myself as I was going to ask what the value of "i" was in an earlier thread :( Then I would have understood a bit better not to use "i" :) That stack you did is excellent for learning mate!!! Thank you.

AS I'm slowly going through it I am discovering certain areas where I do get stuck, for instance. When you load a library of sounds into one card the Track buttons on other cards do not load. They have to be individually loaded from each card. I am looking into working out a loop to do this. I am new to loops :)

Cheers
Bidge

bidgeeman
Posts: 495
Joined: Wed Feb 21, 2007 7:58 am

Post by bidgeeman » Sun Jun 14, 2009 9:19 am

Hmmm....I tried adding this line to load all the buttons on different cards.

Code: Select all

         repeat with k = 1 to the number of cards 
   repeat with i = 1 to the number of items of tButtonList
      set the label of button (item i of tButtonlist) to line i of field "AudioNames"
   end repeat
   end repeat
Not sure why it did'nt work?
I'll keep trying :(

Cheers
Bidge

bidgeeman
Posts: 495
Joined: Wed Feb 21, 2007 7:58 am

Post by bidgeeman » Sun Jun 14, 2009 9:23 am

I think I worked it out! The field "AudioNames" is not shared on all cards. I will try that.

Bidge

bidgeeman
Posts: 495
Joined: Wed Feb 21, 2007 7:58 am

Post by bidgeeman » Sun Jun 14, 2009 9:26 am

No.That did'nt work. The list still has to be loaded via the button.
I'll keep trying ;)

Cheers
Bidge

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Post by bn » Sun Jun 14, 2009 9:32 am

bidge,
I dont quite get what you are trying to do.
repeat with k = 1 to the number of cards
repeat with i = 1 to the number of items of tButtonList
set the label of button (item i of tButtonlist) to line i of field "AudioNames"
end repeat
end repeat
You dont do anything with the variable k.
You have to tell rev exactly which button you mean.
What is in the tButtonlist?
regards
Bernd

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Sun Jun 14, 2009 9:32 am

Hi Bidge,

If the sharedHilite of your buttons is false, you need to set the hilite of each button on each card separately. I believe you got that right already, but when you run the repeat loop (above), the script still look for the button on the current card and does that number of cards times. To refer to each button on each card, you need to write "button (item 1 of tButtonList) of cd k).

Code: Select all

repeat with k = 1 to the number of cards
   repeat with i = 1 to the number of items of tButtonList
      set the label of button (item i of tButtonlist) of cd k to line i of field "AudioNames"
   end repeat
end repeat
This assumes that the current stack is the stack containing the buttons and cards. If not, then you stillneed to add a reference to the right stack.

Best regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

bidgeeman
Posts: 495
Joined: Wed Feb 21, 2007 7:58 am

Post by bidgeeman » Sun Jun 14, 2009 9:36 am

Thanks Mark :)

Can I ask a very basic question? In your code does "cd" stand for card?
I ask because I notice in some scripts there are shorcuts made, ie, "field" and "fld". Is it wise to use shortcuts or preferrable to use the correct spelling?

Cheers
Bidge

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Post by bn » Sun Jun 14, 2009 9:55 am

Bidge,

what is in i?
put this into a button and than look at the message box that will appear.
Make shure to understand what you are seeing and how it is done

Code: Select all

on mouseUp
   repeat with k = 1 to 3
   repeat with i = 1 to 10
      put k into message box
      put return & i after message box
      wait 1 second
   end repeat
   end repeat
end mouseUp
yes cd is the abbreviation of card. You can look up the synonyms in the dictionary:
card (synonym of cd)

Type: object

Synonyms:
cd
regards

Bernd

bidgeeman
Posts: 495
Joined: Wed Feb 21, 2007 7:58 am

Post by bidgeeman » Sun Jun 14, 2009 10:18 am

bidge,
I dont quite get what you are trying to do.
Sorry for the confusion :(

http://www.errolgray.com.au/BNaudiomixer.zip

You will see that when a library selection is made the buttons on the "Next" card do not get re-named like the ones on the first card.

Cheers
Bidge

bidgeeman
Posts: 495
Joined: Wed Feb 21, 2007 7:58 am

Post by bidgeeman » Sun Jun 14, 2009 10:31 am

Hello Mark.

I get a chunk error with that code at line 3 for some reason:

button "ChooseAudioFiles": execution error at line 41 (Chunk: no such object) near "button "Track 1"", char 15

Cheers
Bidge

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Post by bn » Sun Jun 14, 2009 10:33 am

Bidge,

ok, I see.

But what is it supposed to do?
When you import more then the seven tracks should they overflow into the next card?
If you want to do an export should the selections of card 1 and card 2 be appended into one file?
Or do you want the selection on card 1 to be independent of the selections on card 2?.
Do you have a maximum of wav files you want to import or could it be more than 14 (7 on each card)?
regards
Bernd

bidgeeman
Posts: 495
Joined: Wed Feb 21, 2007 7:58 am

Post by bidgeeman » Sun Jun 14, 2009 10:39 am

Hi Bend.
It would be great to be able to mix all cards...so you could have different styles to pick from. I hav'nt tried mixing from seperate cards yet. I suppose that was going to be the next stumbling block :( It would be good to have as many styles as possible.

Cheers
Bidge

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Post by bn » Sun Jun 14, 2009 1:29 pm

Bidge,

I adapted the import script to import into 2 cards with 7 track buttons each.

Code: Select all

on mouseUp
   answer folder "choose folder with audio files of type .wav"
   if it is empty then exit mouseUp
   put it into tFolder
   put the defaultfolder into tOldDefault
   set the defaultfolder to tFolder
   put the files into tFiles
   set the defaultfolder to tOldDefault
   filter tFiles with "*.wav"
   put tFiles into field "AudioNames"
   repeat with i = 1 to the number of lines of tFiles
      put tFolder & "/" before line i of tFiles
   end repeat
   put tFiles into field "AudioNamesAndPathes"
   
   put empty into tbuttonList
   repeat with i = 1 to the number of buttons
      if name of button i contains "Track" then put the name of button i & comma after tbuttonList
   end repeat
   delete last char of tButtonlist
   sort items numeric of tButtonlist by last word of each
   
   put empty into tButtonListCard2
   repeat with i = 1 to the number of buttons of card 2
      if name of button i of card 2 contains "Track" then put the name of button i of card 2 & comma after tButtonListCard2
   end repeat
   delete last char of tButtonListCard2
   sort items numeric of tButtonListCard2 by last word of each
   
   put the number of lines of field "AudioNames"  into tSoManyTracks
   
   if tSoManyTracks > 7  then 
      answer "only the first 7 tracks will be put on this card. and on card the rest from track 8 up to 14 and on card 2."
   end if
   
   ## we have more then 7 tracks, import first into card 1 and the rest up to #14 into card 2
   if the number of lines of field "AudioNames" > 7 then 
      repeat with i = 1 to the number of items of tButtonList
         set the label of button (item i of tButtonlist) to line i of field "AudioNames"
      end repeat
      
      put tSoManyTracks - 7 into tTracksRemaining
      if tTracksRemaining > 7 then put 7 into tTracksRemaining
      
      repeat with i = 1 to tTracksRemaining
         set the label of button (item i of tButtonListCard2) of card 2 to line i + 7 of field "AudioNames"
      end repeat
   else ## less then 7 so the old routine
      repeat with i = 1 to the number of items of tButtonList
         set the label of button (item i of tButtonlist) to line i of field "AudioNames"
      end repeat
   end if
end mouseUp
I did not change anything on the export side, it will probably fail. Not if you do the export from card 1 though. Be careful. But you will fix that.
What I did is I set the sharedText to true for the 3 fields in your background group.

regards
Bernd

Post Reply