How can I stop my game from stalling?
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- Posts: 44
- Joined: Wed Jun 12, 2013 2:36 pm
How can I stop my game from stalling?
I'm coding a game for a project.
The game is a simple reaction time game whereby you must click on objects on screen as they appear to earn points.
When you click on an object I have it set to turn invisible for a random(10) seconds.
However when the image is invisible, nothing else can happen on screen until the image becomes visible again.
Any advice would be appreciated.
The game is a simple reaction time game whereby you must click on objects on screen as they appear to earn points.
When you click on an object I have it set to turn invisible for a random(10) seconds.
However when the image is invisible, nothing else can happen on screen until the image becomes visible again.
Any advice would be appreciated.
Nico Colarusso | Gracemount High School
-
- VIP Livecode Opensource Backer
- Posts: 1236
- Joined: Sat Apr 08, 2006 1:10 pm
- Location: Zurich
- Contact:
Re: How can I stop my game from stalling?
I'm not sure what you are asking, but for a program to behave differently depending on some state, you'd need to use an if statement, for example:
Code: Select all
if the visible of button "click me" is false then
-- do nothing while invisible
else
-- do stuff because it's visible
end if
Various teststacks and stuff:
http://bjoernke.com
Chat with other RunRev developers:
chat.freenode.net:6666 #livecode
http://bjoernke.com
Chat with other RunRev developers:
chat.freenode.net:6666 #livecode
-
- VIP Livecode Opensource Backer
- Posts: 3901
- Joined: Sat Mar 24, 2007 2:54 am
- Location: Palo Alto
Re: How can I stop my game from stalling?
Hi Nico_C_GHS,
Maybe try a "wait with messages".
Even better:
The code will not be "blocked" during that.
Simon
Just a guess on my part, but are you using a "wait" command?...invisible for a random(10) seconds.
Maybe try a "wait with messages".
Even better:
Code: Select all
on mouseUp
set the vis of me to false
send "showMe" to me in random(10) seconds
end mouseUp
on showMe
set the vis of target to true
end showMe
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
-
- Posts: 44
- Joined: Wed Jun 12, 2013 2:36 pm
Re: How can I stop my game from stalling?
I apologise for the ambiguity, I'm merely a beginner in terms of programming knowledge so I'm not 100% sure on what I was attempting to say.
The image of the fish is to disappear when clicked on. It should then reappear within the next 10 seconds (this part works well), however there are other images on the card that can be clicked on which also disappear when clicked on but the card "freezes" while waiting on the fish to reappear.
Here's the code;
another problem is that the image of the fish sometimes ends up underneath another image on the screen, how do I stop the overlapping?
The image of the fish is to disappear when clicked on. It should then reappear within the next 10 seconds (this part works well), however there are other images on the card that can be clicked on which also disappear when clicked on but the card "freezes" while waiting on the fish to reappear.
Here's the code;
Code: Select all
Global HitCount
on mousedown
add 1 to HitCount
set the visible of image "fish." to false
// This is to set the fish to reappear at a random location on the page within a defined area (this part works)
set the loc of image "fish." to random(700),random(400)
if the left of image "fish." <0 then set the left of image "fish." to 0
if the right of image "fish." >500 then set the right of image "fish." to 700
if the top of image "fish." <40 then set the top of image "fish." to 50
if the bottom of image "fish." >450 then set the bottom of image "fish." to 45
// This is where I want the fish to reappear at a random time within 10 seconds (this is where the problem is)
wait random(10) seconds
set the visible of image "fish." to true
end mousedown
Nico Colarusso | Gracemount High School
Re: How can I stop my game from stalling?
Hi Nico,
what Simon says is that WAIT is "bocking/freeezing" your stack, because it does what it means!
So try this NON blocking/freezing code:
Best
Klaus
what Simon says is that WAIT is "bocking/freeezing" your stack, because it does what it means!
So try this NON blocking/freezing code:
Code: Select all
global HitCount
on mousedown
add 1 to HitCount
set the visible of image "fish." to false
// This is to set the fish to reappear at a random location on the page within a defined area (this part works)
set the loc of image "fish." to random(700),random(400)
if the left of image "fish." <0 then set the left of image "fish." to 0
if the right of image "fish." >500 then set the right of image "fish." to 700
if the top of image "fish." <40 then set the top of image "fish." to 50
if the bottom of image "fish." >450 then set the bottom of image "fish." to 45
// This is where I want the fish to reappear at a random time within 10 seconds (this is where the problem is)
send "show_the_fish" to me in random(10) seconds
end mousedown
command show_the_fish
set the visible of image "fish." to true
end show_the_fish
Klaus
-
- Posts: 44
- Joined: Wed Jun 12, 2013 2:36 pm
Re: How can I stop my game from stalling?
When I use the "send" command, the image reappears instantly, rather than waiting. How do I overcome that?
Nico Colarusso | Gracemount High School
Re: How can I stop my game from stalling?
Sure? What if you only click the button ONCE!Nico_C_GHS wrote:When I use the "send" command, the image reappears instantly, rather than waiting. How do I overcome that?
Since I don't know anything about your game, I suspect that you "stack" the commands, means that EVERYTIME you click your button the FISH will get hidden
and the "next" sent "show_the_fish" will show it again, but SOONER than you think.
-
- Posts: 44
- Joined: Wed Jun 12, 2013 2:36 pm
Re: How can I stop my game from stalling?
I don't think I have stacked the commands, if I have then I did it unknowingly. However, with regards to the number of clicks on the fish, it happens every time from the first time I click it.Klaus wrote: Sure? What if you only click the button ONCE!
Since I don't know anything about your game, I suspect that you "stack" the commands, means that EVERYTIME you click your button the FISH will get hidden
and the "next" sent "show_the_fish" will show it again, but SOONER than you think.
The fish needs to reappear and then will be clicked on again by the user, clicking the fish adds points to the user's score and so long as the user has lives left, the game continues running. So even if the code worked for the first time the fish was clicked, it would be useless in terms of the game as a whole. I'm honestly so sorry that this is so confusing, it's just as bad for me as it is for you, I can assure you of that.
Is there any way to extend the waiting time before the "Send" command actually executes? I code upload the game (as it stands) if that would help?
Nico Colarusso | Gracemount High School
Re: How can I stop my game from stalling?
Hi Nico,
hmmm, should work!
Sou you have:
1. an image "fish" that the user needs to click
2. then the image will disappear and
3. be shown again in random(10) seconds
4. the image is the object with the "mousedown" script?
Well, that should work actually! Could you please post all the involved scripts?
I think you need at least 10 posting before you can upload a stack (you will need to ZIP the file!)
Best
Klaus
hmmm, should work!
Sou you have:
1. an image "fish" that the user needs to click
2. then the image will disappear and
3. be shown again in random(10) seconds
4. the image is the object with the "mousedown" script?
Well, that should work actually! Could you please post all the involved scripts?
I think you need at least 10 posting before you can upload a stack (you will need to ZIP the file!)
Best
Klaus
-
- VIP Livecode Opensource Backer
- Posts: 3901
- Joined: Sat Mar 24, 2007 2:54 am
- Location: Palo Alto
Re: How can I stop my game from stalling?
Oh what FUN!
Simon
Edit: I guess I should say something more.
Note: All the fish contain exactly the same script, pretty much the same as yours (check out "me"), the card contains the show_the_fish command.
See the message path in action, the mouseDown command gets stopped on the fish and never makes it to the card mouseDown (unless you click n the card). For a test add "pass mouseDown" to the bottom of the fish scripts. What happens?
Advanced: For a better game figure out using a counting down variable "x" in "send "show_the_fish" to me in random(x) seconds". You might even want to change the seconds to milliseconds.
This time I really did "give a man a fish"
Simon
Edit: I guess I should say something more.
Note: All the fish contain exactly the same script, pretty much the same as yours (check out "me"), the card contains the show_the_fish command.
See the message path in action, the mouseDown command gets stopped on the fish and never makes it to the card mouseDown (unless you click n the card). For a test add "pass mouseDown" to the bottom of the fish scripts. What happens?
Advanced: For a better game figure out using a counting down variable "x" in "send "show_the_fish" to me in random(x) seconds". You might even want to change the seconds to milliseconds.
This time I really did "give a man a fish"
- Attachments
-
- Fishy.zip
- LC 6.1.2
- (9.07 KiB) Downloaded 290 times
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
Re: How can I stop my game from stalling?
So there is more than ONE fish?
Well, that explains something
Well, that explains something
-
- Posts: 44
- Joined: Wed Jun 12, 2013 2:36 pm
Re: How can I stop my game from stalling?
Yeah, there are other images to click (not all fish but they will be coded in the same way). I will test the code again tomorrow and come back with the results, I really hope it works this time thank you for your patience
Nico Colarusso | Gracemount High School
-
- VIP Livecode Opensource Backer
- Posts: 3901
- Joined: Sat Mar 24, 2007 2:54 am
- Location: Palo Alto
Re: How can I stop my game from stalling?
Oh, I overlooked that Nico is from Gracemount High School.
That is one of RunRev success stories.
Simon
That is one of RunRev success stories.
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
-
- Posts: 44
- Joined: Wed Jun 12, 2013 2:36 pm
Re: How can I stop my game from stalling?
Thank you, I am actually doing my advanced higher computing project right now, that's what the code is forSimon wrote:Oh, I overlooked that Nico is from Gracemount High School.
That is one of RunRev success stories.
Simon
Nico Colarusso | Gracemount High School
Re: How can I stop my game from stalling?
Does this affect the fish somehow?Simon wrote:Oh, I overlooked that Nico is from Gracemount High School.
That is one of RunRev success stories.
Simon