Image Visibility

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: heatherlaine, Klaus, FourthWorld, kevinmiller

Post Reply
JCiberkiller
Posts: 12
Joined: Tue Apr 08, 2014 12:46 pm

Image Visibility

Post by JCiberkiller » Tue Apr 08, 2014 12:50 pm

Hello everyone,

How would I be able to make an image disappear and visible again when clicking on it with the mouse or later on with your finger on your phone?
If anyone knows the coding for this or has an Idea on how to do this, please inform me as quick as possible.

Thank you in advance
- JC

Klaus
Posts: 10171
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Image Visibility

Post by Klaus » Tue Apr 08, 2014 1:18 pm

Hi JC,

1. welcome to the forum! :D

2. I moved this thread to the correct forum! 8)

3. you can set "the visible" of your image of just SHOW and HIDE the image:

Code: Select all

on mouseup

  ## Make it visible
  set the visible of img "your image here..." to TRUE
  ## or invisible -> FALSE

  ## show image "your image here..."
  ## hide img...
end mouseup
I recommend to work through these stacks to get the basics of Livecode:
http://www.hyperactivesw.com/revscriptc ... ences.html


Best

Klaus

JCiberkiller
Posts: 12
Joined: Tue Apr 08, 2014 12:46 pm

Re: Image Visibility

Post by JCiberkiller » Tue Apr 08, 2014 2:20 pm

Thank you very much for your help!

I am sorry to say that I have another question :)
Which would be: How would I be able to set a timer if I have hided the object already, so that it pops up again after for example 3 sec? Best would be without needing to use a field.

Thank you in advance
- JC

Klaus
Posts: 10171
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Image Visibility

Post by Klaus » Tue Apr 08, 2014 3:19 pm

Hi JC,

you can send a message in time!

Do this:
1. Create a handler in the CARD script of the card where you want to show the image(s) again:

Code: Select all

command show_image theImageName
  show img theImageName
end show_image
2. Then you can script something lije this in the button(s) that hide the image:

Code: Select all

on mouseup

  ## Store name of the image you want to show again in a variable, 
  ## so we can pass this as a parameter to the above mentioned handler
  put "name of image you are going to hide here..." into tImage

  ## Now hide it:
  hide img tImage

  ## You could also script:
  ## set the visible of img tImage to FALSE

  ## Now send the above mentioned hanlder name with the name of the image you just hid as a parameter:
  send "show_image tImage" to this cd in 3 secs
end mouseup
Et voila, image will pop up again in 3 seconds :D


Best

Klaus

JCiberkiller
Posts: 12
Joined: Tue Apr 08, 2014 12:46 pm

Re: Image Visibility

Post by JCiberkiller » Tue Apr 08, 2014 4:01 pm

I have tried to convert your code but an error has occured on line 11: button "Button": execution error at line 11 (Chunk: no such object) near "bild3", char 1

This is the code I used!

var bild_var

command show_image bild3
//set the visible of img "bild3" to TRUE
show img "bild3"
end show_image

on mouseUp
put "bild3" into bild_var

hide image bild_var

send "show_image bild_var" to this cd in 3 secs


end mouseUp

Thank you in advance
- JC

Klaus
Posts: 10171
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Image Visibility

Post by Klaus » Tue Apr 08, 2014 4:40 pm

Hi JC,

bild3? Du deutsch? :D

I made a quick test and it works as expected!?
Make sure your images is in fact named -> bild3! 8)

OK, lets see...

Code: Select all

## This is Livecode not BASIC or whatever :-D
## var bild_var

## In Liveocde you can do:
local bild_var
 
## Other than my script, you HARDCODE the image name here.
## Can be done, but then you do not need to pass any parameter to this handler!
## I would advice to use my approach, so this handler can show ANY image, 
## as long a you pass a valid image name to it!
command show_image das_bild
   show img das_bild
end show_image
 
on mouseUp
  put "bild3" into bild_var 
  hide image bild_var 
  send "show_image bild_var" to this cd in 3 secs
end mouseUp
With these two scripts my test run successfully!


Best

Klaus

JCiberkiller
Posts: 12
Joined: Tue Apr 08, 2014 12:46 pm

Re: Image Visibility

Post by JCiberkiller » Wed Apr 09, 2014 7:44 am

Hallo Klaus,

vielen Dank für deine Hilfe, unser problem hat sich dardurch behoben!! :)

Allerdings habe ich noch 2 Fragen.
Und zwar, wie impliementiere ich einen counter der zählt wie oft ein Bild angeklickt wurde? Den Counter benötigen wir für die Score ermittlung.

Es geht hier um das Spiel Hau den Maulwurf, und zwar sollten die bilder nicht nur verschwinden wenn man drauf klickt sondern auch wenn nicht, mit gewissen abständen versteht sich. Wie könnte ich es automatiesieren, sozusagen genau das gegenteil von dem was wir jetzt haben. Statt das die Bilder alle drei sekunden wieder angezeigt werden, sollten sie stattdessen alle drei sekunden wieder verschwinden.

Danke im voraus
- JC

Ps: Hoffentlich ist das nicht zu kompleziert? :)

Klaus
Posts: 10171
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Image Visibility

Post by Klaus » Wed Apr 09, 2014 12:25 pm

Hi JC,

Okie Dokie :D
But please lets continue in english in behalf of the forum!
How can I implement a counter that counts the clicks on an image?
You could use a (local or global) variable which holds the clicks.
Example script of image:

Code: Select all

global tNumberOfClicks
on mouseup
  add 1 to tNumberOfClicks
enbd mouseup
You get the picture :D

The rest is a tad more complex! 8)
You can write me personally, if you like to discuss this in german: klaus ÄTT major-k.de


Best

Klaus

JCiberkiller
Posts: 12
Joined: Tue Apr 08, 2014 12:46 pm

Re: Image Visibility

Post by JCiberkiller » Fri Apr 11, 2014 10:43 am

Good morning Klaus,

the problem now is that when I click the picture it hides after 3 sec and not directly. In addition it stays gone and doesn't appear again.

How can we slove this problem?

Thank you in advance
- JC

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”