Page 1 of 1

Disappearing if not clicked.

Posted: Tue Nov 05, 2013 3:49 pm
by Nico_C_GHS
I am completely stuck with this code, again.

There are images on the screen that can be clicked on which makes them invisible, this works fairly well.
However, I've been trying to write some code to make the image disappear again if it isn't clicked on after a set time period.

This aspect is fairly crucial to the gameplay, otherwise the game becomes unbalanced and I have been stuck on this bit for a while. Any and all advice or guidance will be greatly appreciated.

Here's my code for the object;

Code: Select all

on mouseDown
     add 20 to fld HitCount
     set the visible of me to false
     set the loc of me to random(700),random(400)
   if the left of me <0 then set the left of me to 0
   if the right of me >500 then set the right of me to 700
   if the top of me <40 then set the top of me to 50
   if the bottom of me >450 then set the bottom of me to 45
   send "show_the_fish" to me in random(20) seconds
   end mouseDown
This is the card script relating to the object code;

Code: Select all

if the vis of "fish." = true
then wait 4 seconds with messages
then set the vis of me to false
then send "show_the_fish" to me in random(5) seconds
end if
I know that the card script is awful, I've been experimenting a bit and that's the code at present.

Re: Disappearing if not clicked.

Posted: Tue Nov 05, 2013 7:49 pm
by Simon
Hi Nico,
I see you are trying not to use "send" again.
In the last example I gave it showed "send in time" and it's working well right?
Redo your code so that "show_the_fish" contains it's own "send in 4 seconds". Does that make sense?

The other thing that you can improve upon is getting rid of those 4 if/then statements in the mouseDown. Yes, I get what they are for, but read the dictionary entry for random again:
To generate a random number between two integers,
That is what you really want to use.
Can you figure out how to implement that and get rid of your if/then?
I found using your code ended up with the fish being pressed against one of the edges too often because the generated number fell outside the "box".

Simon

Re: Disappearing if not clicked.

Posted: Wed Nov 06, 2013 2:57 pm
by Nico_C_GHS
I've read up on the "random" statement and it's definitions in the dictionary and I understand the use of it, however I can't figure out how to do that with the x and y coordinates. Would I set the function individually for both coordinates?

Re: Disappearing if not clicked.

Posted: Wed Nov 06, 2013 6:31 pm
by Simon
Hi Nico,
Sorry, on reading your script again I see that there is something in the middle of your card that you are trying to avoid having the image show up in. Is that true?
Care to post a stack or maybe just an image?

Simon

Re: Disappearing if not clicked.

Posted: Thu Nov 07, 2013 3:23 pm
by Nico_C_GHS
Hi Simon,

Here is a duplicate of the card that I'm working on, I've not included all the other images as they aren't really important to this problem as if it can be fixed on the fish, it can be fixed for all of the others too :)

With regards to your question on trying to have the images avoid an area in the middle;
Not quite, as you will see when opening the card, I have an area for "lives", "score" and "pause" which the images must avoid so I have set an area in the middle that they are allowed to go within. Basically I was attempting to set it so that they would be able to move freely with the random repositioning function without colliding with these areas. Upon realising how difficult that would be, I just set them up so that the images couldn't go high enough to collide with the "scores" or "lives" areas and couldn't go low enough to collide with the "pause" button.


Also, on using the code that was recommended, I found that the fish would not move away from an area on the right of the screen. If it was that I used the code wrong then you should be able to see it in the stack I have posted.

Re: Disappearing if not clicked.

Posted: Thu Nov 07, 2013 9:10 pm
by Simon
Hi Nico,
You should lock the stack size (unselect the resizable) and try this:

Code: Select all

put random(731 - 35 + 1) + 35 - 1 into xPos
put random(431 - 73 + 1) + 73 - 1 into yPos
set the loc of me to xPos,yPos
Sorry the numbers are weird but you stack size is odd. At any rate that -35 is to locate the center of your image and keep it on the card, -73 is also a lower limit (35 + the distance to the bottom of your fields at the top).
If your images are different sizes you could calculate those values on the fly by using "rect".

Have you had any luck with hiding the image after 4 secs?

Simon

Re: Disappearing if not clicked.

Posted: Mon Nov 11, 2013 6:32 pm
by Nico_C_GHS
I still haven't had any luck in getting the image to reappear, it really has been bugging me :(

Re: Disappearing if not clicked.

Posted: Tue Nov 12, 2013 2:39 pm
by Nico_C_GHS
Simon,

The code you recommended for the repositioning of the fish was extremely helpful. It worked perfectly, thank you for the assistance, much appreciated :D