condition loop for image visibilty

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

Post Reply
tomerp
Posts: 6
Joined: Thu Mar 09, 2017 8:01 pm

condition loop for image visibilty

Post by tomerp » Thu Mar 09, 2017 8:05 pm

Hi!

i would like to check in an app i have made how many images are still visible, and then print the answer to the user.
what would be the most effcient way of doing it?
i was thinking about a loop with a condition only that i lack the knowladge of phrasing it in LC.

can someone give me a hand?

tnx
Tomer

Klaus
Posts: 14198
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: condition loop for image visibilty

Post by Klaus » Thu Mar 09, 2017 8:12 pm

Hi Tomer,

1. welcome to the forum! :D

2. Do you need the number of images on the current card or on all cards in the stack?

3. Here some great learning resources for the basics of Livecode:
http://www.hyperactivesw.com/revscriptc ... ences.html

Best

Klaus

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10328
Joined: Wed May 06, 2009 2:28 pm

Re: condition loop for image visibilty

Post by dunbarx » Thu Mar 09, 2017 8:31 pm

Hi.

The "visible" is a property of all controls. So your idea of a loop "with a condition" is exactly right. That "condition" is testing the property of each control.(pseudo:)

Code: Select all

repeat with y = 1 to the number of controls either on this card or in the whole stack
   if the visible of control y then add 1 to totalVisible
end repeat
And as Klaus mentioned, do learn as you work, so your questions will be more useful to you.

Craig Newman
Last edited by dunbarx on Mon Mar 27, 2017 7:43 pm, edited 1 time in total.

tomerp
Posts: 6
Joined: Thu Mar 09, 2017 8:01 pm

Re: condition loop for image visibilty

Post by tomerp » Sat Mar 25, 2017 5:45 pm

hi guys!
thank u for replying my question - but yet im having a hard time finding the correct syntax for my problam.
here is what i am trying to do:
for a certain button, i would like to write a script that check how many of my images are still visible.
the images are all in the same card. finally it should print back to the user an answer for how many images are still visible.
how would you phrase it?

btw the tutorial u gave me is great, thank u for that!

Tomer

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: condition loop for image visibilty

Post by jmburnod » Sat Mar 25, 2017 7:19 pm

Hi Tomer,
You can use a function that you can call from all btns like this

Code: Select all

--••btn script
on mouseUp
   deMyButton
end mouseUp


--•• cd script
on deMyButton
   answer getNbImgVis()
end deMyButton

function getNbImgVis
   put 0 into tCount
   repeat with i = 1 to the num of imgs
      if the vis of img i then add 1 to tCount
   end repeat
   return tCount
end getNbImgVis
Best regards
Jean-Marc
https://alternatic.ch

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10099
Joined: Fri Feb 19, 2010 10:17 am

Re: condition loop for image visibilty

Post by richmond62 » Sat Mar 25, 2017 7:20 pm

Code: Select all

on mouseUp
repeat with y - 1 to the number of controls on this card
   if the visible of control y then add 1 to totalVisible
end repeat
put totalVisible
end mouseUp
stick that in a button on your card . . .

tomerp
Posts: 6
Joined: Thu Mar 09, 2017 8:01 pm

Re: condition loop for image visibilty

Post by tomerp » Mon Mar 27, 2017 6:21 pm

thank you guysfor you help!

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10328
Joined: Wed May 06, 2009 2:28 pm

Re: condition loop for image visibilty

Post by dunbarx » Mon Mar 27, 2017 7:44 pm

Just noticed that my earlier post, and Richmond's later take on it had:

Code: Select all

repeat with y - 1 to..
instead, of course,

Code: Select all

repeat with y = 1 to..
Craig

Post Reply