Page 1 of 1

condition loop for image visibilty

Posted: Thu Mar 09, 2017 8:05 pm
by tomerp
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

Re: condition loop for image visibilty

Posted: Thu Mar 09, 2017 8:12 pm
by Klaus
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

Re: condition loop for image visibilty

Posted: Thu Mar 09, 2017 8:31 pm
by dunbarx
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

Re: condition loop for image visibilty

Posted: Sat Mar 25, 2017 5:45 pm
by tomerp
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

Re: condition loop for image visibilty

Posted: Sat Mar 25, 2017 7:19 pm
by jmburnod
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

Re: condition loop for image visibilty

Posted: Sat Mar 25, 2017 7:20 pm
by richmond62

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 . . .

Re: condition loop for image visibilty

Posted: Mon Mar 27, 2017 6:21 pm
by tomerp
thank you guysfor you help!

Re: condition loop for image visibilty

Posted: Mon Mar 27, 2017 7:44 pm
by dunbarx
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