Computer Science Canada Exiting and re-entering multiple loops |
Author: | Hack.saw [ Tue May 09, 2006 2:57 pm ] |
Post subject: | Exiting and re-entering multiple loops |
This is my first post... so be nice ![]() But now I have a problem my teacher can't help me with... the loop used to keep getting input from the key board of course never ends so nothing else can run. Is it possible to leave a loop using exit when nothing is being touched/pressed down and then re-enter the loop if something is pressed down? Is it possible for two loops to run at once? (I will attach my file below when I get back on my school comp for some constructive critisism) |
Author: | Cervantes [ Tue May 09, 2006 3:23 pm ] | ||
Post subject: | |||
Welcome to CompSci.ca, Hack.saw! ![]() To directly answer your question, yes. It is possible to have two loops running simultaneously. However, you have to realize that they're not actually running simultaneously. Your processor can only do one thing at a time. Thus, unless you have a dual processor machine, only one loop at a time can run. To imitate two loops running simultaneously, we use something called threads. This is handled by the operating system (Windows, in this case). Turing uses a different word than "thread": turing calls them processes. You can probably solve your problem like this. HOWEVER, processes in Turing are implemented very poorly. They don't actually run code in a 1:1 ratio. It's rather random. Unless you want to go very far and implement a system that steadies and controls how the processes run, I highly recommend you don't use processes. In fact, this has been said so many times that I wrote an article about it. So, if you're not going to use processes, what are you going to do? The thing you need to realize is that you don't need two loops running simultaneously. Yes, getch pauses the program for input, and that's probably a bad thing. There are two things you can do to fix this.
|
Author: | Hack.saw [ Tue May 09, 2006 6:04 pm ] | ||
Post subject: | |||
O.K. thanks for help,I used the code from the tutorial and someof your hasch to make a simple program that creates a growing box at the bottom of the screen and allows you to move a little red circle at the same time. Tommorow I'll have to completely redo that part of my game because Input.KeyDown works waaaayyyyy better than getch.
|
Author: | Hack.saw [ Tue May 09, 2006 6:09 pm ] |
Post subject: | |
Also, I was just wondering if I can keep posting on this thread with new problems that may not be related to the first or should I make a new topic all together? ![]() |
Author: | Hack.saw [ Tue May 09, 2006 6:10 pm ] |
Post subject: | |
Also, I was just wondering if I can keep posting on this thread with new problems that may not be related to the first or should I make a new topic all together? ![]() |
Author: | Cervantes [ Tue May 09, 2006 6:12 pm ] |
Post subject: | |
Hack.saw wrote: Also, I was just wondering if I can keep posting on this thread with new problems that may not be related to the first or should I make a new topic all together?
![]() Do what you think is best. ![]() If your next question is related to this (getch/Input.KeyDown/looping), by all means, post here. If you think it's rather different, make a new topic. |
Author: | Hack.saw [ Tue May 09, 2006 6:54 pm ] | ||
Post subject: | |||
I've started a new mini demo program to test my new looping abilities and am making a maze that a colour changing oval must go through. Now I know I've seen this before on a help thread but I couldn't find it. I need the oval to not be able ot go through the first green wall I have made. So far I have
P.S. Sorry if I have a few questions right now, my TIK class isn't very good so I am uber newb right now ![]() |
Author: | Hack.saw [ Tue May 09, 2006 7:00 pm ] |
Post subject: | |
oops, if c=>219 or <221 is supposed to be x > 219 and I guess you can't have > and < in same boolean |
Author: | Cervantes [ Tue May 09, 2006 7:32 pm ] |
Post subject: | |
If you place that if statement correctly (before updating the x and y positions based on velocity), you could set the velocity of the oval to 0. If you're not using a velocity, the easiest thing to do would be to reset the x or y coordinates to some known value (just outside where the wall is). You're using whatdotcolour, I take it? |
Author: | Hack.saw [ Tue May 09, 2006 8:06 pm ] | ||
Post subject: | |||
Nope have no clue what whatdotcolour is lol... so far I have
Never mind the second if x > 200 and y > 400 then x := x - 5 cause I was just screwing around and it dosn't work (atleast i don't think so). So I have it so that you can't pass the first green wall but that leaves it so you can only pass the next black wall at the same place. Is there anyway to stop using the first "if" when the oval passes the first wall? ![]() |
Author: | Clayton [ Tue May 09, 2006 8:46 pm ] |
Post subject: | |
you could make a boolean variable to check the balls position so you can check to see what area of the screen you need to check using your ifs. now, about that for loop that is looping through colors 1..200, wow, that slows it down so much, if you are using it like i think you are trying to (idk for sure) which is making the ball a different color for each time you go through the loop, the way you have it it doesnt quite work that way, if you want to have it do something like that you should have something like this [syntax="Turing & Pseudo"] var culor:int:=1 var counter:int:=0 loop draw ball (x,y,culor) check for collision change coordinates accordingly change culor number if culor= maxcolor then culor:=1 end if end loop [/syntax] apply that to your program ( if what i think is right...) |
Author: | Hack.saw [ Wed May 10, 2006 9:09 am ] |
Post subject: | |
wow... this game is running terribly slow on the school computers, at home it was so smooth i couldnt believe it. How do you check for collsions? I read the tutorial but I didn't really understand it. |
Author: | Hack.saw [ Wed May 10, 2006 9:29 am ] | ||
Post subject: | |||
The culor thing worked great and sped up the game so much i had to put in dealys ![]()
|
Author: | do_pete [ Wed May 10, 2006 11:43 am ] | ||||
Post subject: | |||||
You'll need something along the lines of:
or
|
Author: | Hack.saw [ Fri May 12, 2006 9:26 am ] |
Post subject: | |
... Well I used all the stuff from this thread in my adventure game and it worked perfectly, thanks guys ![]() ![]() ![]() ![]() |