How can I stop my game from stalling?

Creating Games? Developing something for fun?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

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

How can I stop my game from stalling?

Post by Nico_C_GHS » Tue Oct 22, 2013 2:27 pm

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.
Nico Colarusso | Gracemount High School

BvG
VIP Livecode Opensource Backer
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?

Post by BvG » Tue Oct 22, 2013 2:30 pm

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

Simon
VIP Livecode Opensource Backer
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?

Post by Simon » Tue Oct 22, 2013 6:00 pm

Hi Nico_C_GHS,
...invisible for a random(10) seconds.
Just a guess on my part, but are you using a "wait" command?
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
The code will not be "blocked" during that.

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: How can I stop my game from stalling?

Post by Nico_C_GHS » Thu Oct 24, 2013 1:39 pm

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;

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
another problem is that the image of the fish sometimes ends up underneath another image on the screen, how do I stop the overlapping?
Nico Colarusso | Gracemount High School

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

Re: How can I stop my game from stalling?

Post by Klaus » Thu Oct 24, 2013 2:27 pm

Hi Nico,

what Simon says is that WAIT is "bocking/freeezing" your stack, because it does what it means! :D

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
Best

Klaus

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

Re: How can I stop my game from stalling?

Post by Nico_C_GHS » Thu Oct 24, 2013 2:34 pm

When I use the "send" command, the image reappears instantly, rather than waiting. How do I overcome that?
Nico Colarusso | Gracemount High School

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

Re: How can I stop my game from stalling?

Post by Klaus » Thu Oct 24, 2013 2:50 pm

Nico_C_GHS wrote:When I use the "send" command, the image reappears instantly, rather than waiting. How do I overcome that?
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.

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

Re: How can I stop my game from stalling?

Post by Nico_C_GHS » Thu Oct 24, 2013 2:56 pm

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

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

Re: How can I stop my game from stalling?

Post by Klaus » Thu Oct 24, 2013 3:32 pm

Hi Nico,

hmmm, should work! :D

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

Simon
VIP Livecode Opensource Backer
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?

Post by Simon » Thu Oct 24, 2013 8:03 pm

Oh what FUN! :D

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!

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

Re: How can I stop my game from stalling?

Post by Klaus » Thu Oct 24, 2013 10:11 pm

So there is more than ONE fish? :shock:
Well, that explains something :D

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

Re: How can I stop my game from stalling?

Post by Nico_C_GHS » Thu Oct 24, 2013 10:57 pm

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 :lol: thank you for your patience :)
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: How can I stop my game from stalling?

Post by Simon » Thu Oct 24, 2013 11:07 pm

Oh, I overlooked that Nico is from Gracemount High School.
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!

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

Re: How can I stop my game from stalling?

Post by Nico_C_GHS » Fri Oct 25, 2013 10:55 pm

Simon wrote:Oh, I overlooked that Nico is from Gracemount High School.
That is one of RunRev success stories.

Simon
Thank you, I am actually doing my advanced higher computing project right now, that's what the code is for :)
Nico Colarusso | Gracemount High School

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

Re: How can I stop my game from stalling?

Post by Klaus » Sat Oct 26, 2013 12:06 pm

Simon wrote:Oh, I overlooked that Nico is from Gracemount High School.
That is one of RunRev success stories.

Simon
Does this affect the fish somehow? 8)

:D :D :D

Post Reply

Return to “Games”