Computer Science Canada How to simultaneously run two procedures without process |
Author: | hnchmc [ Sun Jan 24, 2016 1:19 pm ] | ||
Post subject: | How to simultaneously run two procedures without process | ||
What is it you are trying to achieve? I am trying to run two procedures simultaneously without the use of processes. Any help is greatly appreciated. What is the problem you are having? As I have read, processes are to be avoided at all costs. I am currently in the final stages of making a small Pacman game and have ran into a small speed bump with the ghosts. Up to this point, I have been using processes to fork the ghost movement. However, when a ghost is moving any direction (for this example it will be right), and reaches an intersection and randomly chooses to continue right, he picks up speed (doubling his X- Axis increment). This does not happen when he, for example, is moving right then decides to go up. If I am in fact making sense of what I have read, it is the randomness of processes that is causing this. Therefore, I turned to this forum for help with running two procedures at a time (The ghost and the rest of the game). Long story short, if the ghost continues moving the way he was previously, he picks up speed. Else, it works like it should. Describe what you have tried to solve this problem Well, I have turned to my teacher for help on this matter. She could not figure out why the process was breaking the game. I asked two senior programmers, they too could not help. Finally, I have spent two days scouring the internet for a solution and yielded no direct solution. Post any relevant code (You may choose to attach the file instead of posting the code if it is too long) Sorry if it's a little long...
Please specify what version of Turing you are using Version 4.1 (To work with the school's version) |
Author: | Insectoid [ Sun Jan 24, 2016 5:54 pm ] | ||||
Post subject: | RE:How to simultaneously run two procedures without process | ||||
The reason processes are to be avoided is because they run simultaneously (sort of). I explain why here. Trying to make procedures run simultaneously will only cause all of the same problems. You need to completely restructure your program so that you don't need to run anything simultaneously. Right now, your code is organized so each procedure has its own loop where it does its own thing over and over and over again. You need to re-arrange it so that your procedures have no loops, and only do their thing once, and call all of the procedures in one big loop. Right now your code looks like this:
It should look more like this:
Now we only have one loop in the entire program and have eliminated processes completely. |
Author: | hnchmc [ Sun Jan 24, 2016 7:21 pm ] |
Post subject: | RE:How to simultaneously run two procedures without process |
Ok, thank you very much! I was fuzzy on what had made a process so buggy. Now to finish the game! |