Can't get an image to reappear after set times

Creating Games? Developing something for fun?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Nico_C_GHS
Posts: 44
Joined: Wed Jun 12, 2013 2:36 pm

Can't get an image to reappear after set times

Post by Nico_C_GHS » Thu Nov 14, 2013 2:47 pm

I am having some troubles making an image disappear after a certain amount of time (let's say 3 seconds for arguments sake).

I am creating a game and a crucial part of the reaction-time aspect of the game (the concept upon which the game is founded) is not working and I can't seem to figure it out.

I know roughly that it will require a boolean variable to say whether or not the user has clicked on the image (clicking on an image adds points to your score and causes them to disappear and reappear elsewhere - this part works).
I know that I will also be required to use a "send to me in time" command which will include (in the send function) a "wait with messages" command.
However, I'm unaware of how to initialise the function and I'm not sure on what the code required to say "if this image hasn't been clicked on in the first 3 seconds after it has appear, make it disappear and reappear elsewhere after a further 5 seconds"

If anyone has any advice or guidance to offer it would be greatly appreciated. The section in quotation marks is the part I really need advice with. I can attach a replica of the screen containing the image that will need to be coded if it is required/requested.

Much appreciated,
Nico Colarusso
Nico Colarusso | Gracemount High School

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

Re: Can't get an image to reappear after set times

Post by Simon » Fri Nov 15, 2013 1:21 am

Hi Nico,
I can't remember precisely your code at the moment but:
send "mouseUp" to target in 4 seconds? (haven't tested that)
somewhere in your hide handler.

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

Nico_C_GHS
Posts: 44
Joined: Wed Jun 12, 2013 2:36 pm

Re: Can't get an image to reappear after set times

Post by Nico_C_GHS » Tue Nov 19, 2013 3:39 pm

Hi Simon,


I can give that a shot and see if it works, the logic is infallible so it should do. The only problem I have with that code is that in my "mouseDown" section, I have an area that adds 20 points to your score, if I send mouseDown to the target then wouldn't it add the 20 to the score also?

Also;
will that 4 seconds reset when the button is clicked on?
wouldn't the 4 second timer run while the fish is invisible? Essentially creating a never ending loop of hiding and adding points to the score?



Here's the code:

Code: Select all

on mouseDown
   add 20 to fld HitCount
   set the visible of me to false
   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
   send "show_the_fish" to me in random(20) seconds
end mouseDown
Nico Colarusso | Gracemount High School

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

Re: Can't get an image to reappear after set times

Post by Simon » Tue Nov 19, 2013 9:18 pm

Hi Nico,
Sorry I forgot about the score.
I'm thinking now a separate handler could be made in the fish, something like hideMySorrySelf <<that is a "made up" name can be anything you want as long as it's not used by liveCode.

on hideMySorrySelf
-- add 20 to fld HitCount
set the visible of me to false
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
send "show_the_fish" to me in random(20) seconds --I think you need to still do this? maybe reduce the time?
--yes, a loop, but I figure you want it to do that?
end hideMySorrySelf

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

Nico_C_GHS
Posts: 44
Joined: Wed Jun 12, 2013 2:36 pm

Re: Can't get an image to reappear after set times

Post by Nico_C_GHS » Thu Nov 21, 2013 2:39 pm

Hi Simon,

I see how that would work and that does make logical sense.
However, how would I set it up so that it only works when the image hasn't been clicked on? Or does that code work with that logic?
Nico Colarusso | Gracemount High School

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

Re: Can't get an image to reappear after set times

Post by Simon » Thu Nov 21, 2013 10:41 pm

Hi Nico,
You call it from "show_the_fish".

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

Nico_C_GHS
Posts: 44
Joined: Wed Jun 12, 2013 2:36 pm

Re: Can't get an image to reappear after set times

Post by Nico_C_GHS » Tue Nov 26, 2013 2:48 pm

Hi Simon,

I'm really sorry but the whole concept really is escaping me. I can see that it would work but I just can't seem to get it into code and onto the script. If I call the function on the image of the fish, how do I make it so that the fish doesn't just stay invisible after I've clicked on it? I'm sure that the timer would start running even when the fish is invisible before it turns visible for me to click on it again unless I set the times to be ridiculously short. If that isn't the case then I must be overlooking something.

all the best,
Nico
Nico Colarusso | Gracemount High School

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

Re: Can't get an image to reappear after set times

Post by Simon » Tue Nov 26, 2013 9:36 pm

Hi Nico,
Here this will help:

Code: Select all

  repeat for each line x in the pendingMessages
      if the short id of me is in x then cancel item 1 of x
   end repeat
Add that to the top of your mouseDown handler.
Now each of the three timers are in sequence one after the other. One timer doesn't start till the other is finished.

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

Nico_C_GHS
Posts: 44
Joined: Wed Jun 12, 2013 2:36 pm

Re: Can't get an image to reappear after set times

Post by Nico_C_GHS » Thu Nov 28, 2013 2:48 pm

Hi Simon,

That makes a lot of sense. Should I set the other timers into the card script?

Thank you for your feedback,
Nico
Nico Colarusso | Gracemount High School

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

Re: Can't get an image to reappear after set times

Post by Simon » Thu Nov 28, 2013 10:06 pm

Hi Nico,
Should I set the other timers into the card script?
I guess so, could be the stack.

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

Nico_C_GHS
Posts: 44
Joined: Wed Jun 12, 2013 2:36 pm

Re: Can't get an image to reappear after set times

Post by Nico_C_GHS » Mon Dec 02, 2013 9:49 am

Hi Simon,

The timers work! Thank you so much for that, I've only got a tiny bit left to do for the program now and it shouldn't be terribly difficult :) Could I be a pest and ask two quick questions about the images that I need a little help with? (Just niggly things really, I'm quite pedantic)
Nico Colarusso | Gracemount High School

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

Re: Can't get an image to reappear after set times

Post by Simon » Mon Dec 02, 2013 6:58 pm

Sure no problem.

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

Nico_C_GHS
Posts: 44
Joined: Wed Jun 12, 2013 2:36 pm

Re: Can't get an image to reappear after set times

Post by Nico_C_GHS » Thu Dec 05, 2013 3:20 pm

Hi Simon,
It turns out that I don't need any more help with the images, I have another thread for the final question I have about the program:

http://forums.runrev.com/viewtopic.php?f=22&t=18273
Nico Colarusso | Gracemount High School

Post Reply

Return to “Games”