custom properties

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: custom properties

Post by Simon » Sun Feb 17, 2013 1:35 am

Very sorry, that should have been
repeat with N = 1 to...
N is just a variable, could be anything.
Probably should have used tNum to keep it consistent.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: custom properties

Post by Dixie » Sun Feb 17, 2013 2:05 am

KennyR…

Do not apologise for not knowing… this forum is here to help people understand just such problems. At one time or another we have all been through it… In fact as far as 'not knowing' is concerned', for me it seems to be a daily occurence...:-)

Code: Select all

on closeCard
set the defaultFolder to specialFolderPath("documents")
repeat N = 1 to the number of fields of this cd
put the foregroundColor of fld N into line N of tFile
end repeat
put tFile into url ("file:myFile.txt")
end closeCard
Using the example posted by Simon, here is a 'long winded' explanation of the above 'closeCard' handler…
The very fact that that the script lines are within the closeCard handler means that they are to be executed when the card closes.

The defaultfolder is being set to specialFolderPath("documents") is telling liveCode that you wish any work, on a file or files, to be done within this folder.

The 'repeat' statement allows to to perform certain actions a number of times… in this case the 'repeat statement will get the 'foregroundColor' of every field that is on the card and put it into a line of a variable, again in this case, allied 'tFile'….

So, to be a little verbose… let's assume there are 5 fields on this card, then

repeat with N = 1 to the number of fields of this card
will mean that the first time around the repeat loop N will equal 1, so liveCode will start at field 1… the second time around N will equal 2… and so on until N equals five, at which point liveCode will exit the repeat statement and carry on executing the rest of the lines within the 'closeCard' handler…

put the foregroundColor of fld N into line N of tFile
Now, for each loop of the repeat statement N will increment by 1… So, the third time around the repeat loop, when N would equal 3, would mean that liveCode is getting the foregroundColour of field 3 of this card and putting it into line 3 of the variable tFile…

After working its way through the repeat statement 5 times and having put the foregoundColor of each field into a line in the variable tFile, liveCode then executes the last line in the 'closeCard' handler'…

put tFile into URL("file:myFile.txt")
liveCode now writes the variable tFile to the file 'myFile.txt', which is located in the documents folder of your app...

Hope it helps,

Dixie

KennyR
Posts: 256
Joined: Thu Jan 19, 2012 4:25 am

Re: custom properties

Post by KennyR » Sun Feb 17, 2013 2:26 pm

DIxie,
This has got to be the BEST most concise explanation anyone could give regarding repeat loops! After reviewing your post, it now makes perfect sense to me how this works and how to implement this in the future. This bit of code has now opened up so much for me and has saved me countless hours of coding. I VERY much appreciate your time on my problem! Between you and Simon, I am now ready to wrap this application up...I can't wait to use this bit of information in the future. Thanks again!!!

KennyR
Posts: 256
Joined: Thu Jan 19, 2012 4:25 am

Re: custom properties

Post by KennyR » Mon Feb 18, 2013 4:33 am

I am having issues with changing the foregroundColor of multiple cards. I have tried this a few ways and keep running into issues. I am only able to change the first cards fields foregroundColor to "#FFFFFF". I am putting the bit of code I am using and maybe you can tell me why both of these cards wont change the foregroundColors...

Code: Select all

repeat with x = 1 to the number of fields of card "Airway"
      set the foregroundColor of fld x of card "Airway" to "#FFFFFF"
      repeat with N = 1 to the number of fields of card "ALS"
         set the foregroundColor of fld N of card "ALS" to "#FFFFFF"
      end repeat
      
end repeat

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: custom properties

Post by Simon » Mon Feb 18, 2013 4:43 am

Why are you using a nested loop (repeat)?

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

KennyR
Posts: 256
Joined: Thu Jan 19, 2012 4:25 am

Re: custom properties

Post by KennyR » Mon Feb 18, 2013 4:49 am

lol...I don't know! I was just trying everything, because breaking it up into two separate loops wasn't working.....This was just my last ditch effort to make it work...what is the best way to do it then? Thanks Simon!

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: custom properties

Post by Simon » Mon Feb 18, 2013 4:58 am

Code: Select all

on preOpenCard
repeat with x = 1 to the number of fields of this card
      set the foregroundColor of fld x of this card to "#FFFFFF"
end repeat
end preOpenCard
Try that on each card, I not sure how well that will work because you are using "sliding" cards as I remember.

Other then that... hmm
Have you actually used that "exit to top" anywhere?

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

KennyR
Posts: 256
Joined: Thu Jan 19, 2012 4:25 am

Re: custom properties

Post by KennyR » Mon Feb 18, 2013 5:06 am

well here is the thing....I basically want to have a "reset" button that sets all the cards back to their original state. So really it is nothing more than putting all the buttons back to "WHITE" (#FFFFFF) and reseting the variables that keep track of button presses. So really I need a handler that is in the stack of the program and is responsible for setting all the buttons back to white. Putting a handler on each card will work, but its not practical to have the user visit each card to reset the program. The code you posted does work fine, but again, I need to be able to loop through each cards fields, record the foreground color of each field and reset the fields back when the user clicks a single button. Something like this..

*in the stack script*
on mouseUp
repeat with x =1 to the number of fields in this stack
set the foregroundColor of fld x to "FFFFFF"
end repeat
end mouseUp

or something similar.....when I try this, the first card of the stack is changed back, but the other cards are left untouched....curious...

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: custom properties

Post by Simon » Mon Feb 18, 2013 5:46 am

Ahhh... OK I see.
Does the loading from the myFile.txt work?
Is it in the preOpenStack message?

This sounds like a screen refresh problem (Rats!).

Maybe a workaround could be:

Code: Select all

on mouseUp
lock screen
go card "Airway"
repeat with N = 1 to the number of fields of card "Airway"
         set the foregroundColor of fld N of card "Airway" to "#FFFFFF"
end repeat
go card "ALS"
repeat with N = 1 to the number of fields of card "ALS"
         set the foregroundColor of fld N of card "ALS" to "#FFFFFF"
end repeat
--etc
go cd 1
unlock screen
end mouseUp
The lock screen may prevent this from working but if you can stand the flipping cards try removing it.
and YES, this is a hack

Simon
EDIT: You should actually try it without the lock so you see what lock screen does.
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: custom properties

Post by Dixie » Mon Feb 18, 2013 7:02 am

KennyR...

Place this 'mouseUp' script in a button on a card... or from wherever you want to initiate the reset of the colours from...

Code: Select all

on mouseUp
   resetColours
end mouseUp
place this 'resetColours' handler in your stack script...

Code: Select all

on resetColours
   lock screen
   push card
   repeat with count = 1 to the number of cards of this stack
      repeat with count2 = 1 to the number of fields of card count
         set the foregroundColor of fld count2 of card count to "#FFFFFF"
      end repeat
   end repeat
   pop card
end resetColours
That should do the job for you...:-)

Dixie

KennyR
Posts: 256
Joined: Thu Jan 19, 2012 4:25 am

Re: custom properties

Post by KennyR » Mon Feb 18, 2013 12:48 pm

once again, thank you kindly for the help! I can't wait to get to work and try this! That's the great thing about being a paramedic....it allows for 12 hours a day of coding with the occasional emergency call! I'll report back and tell you how it goes....

*Simon, to answer your question about saving to "URL ("file:blah.txt").....yes! I have been using this quite a bit in my program...currently I am using this for saving the variables and loading them back into the script at runtime, also to solve the original problem of storing the state of the buttons at closeStack...been working like a charm for me. I will say this though, since your guys last post, I am going to make some changes in the script to update the saved states of the buttons all at once, because currently, the user has to visit each card to get the buttons to update. I would like to have them update at openStack all at once and I think what you guys just taught me will do the trick!

Post Reply