How do you run multiple procedure simultaneously? NEED HELP FAST PLOX!
Author |
Message |
chimerix
|
Posted: Mon Nov 23, 2009 6:54 pm Post subject: How do you run multiple procedure simultaneously? NEED HELP FAST PLOX! |
|
|
What is it you are trying to achieve?
I started turing only a few weeks ago, and am attempting to create a moderate game for a school project. This program is relatively simple to your intelligent minds, but i am having big issues. I am currently trying to run two procedures simultaneously but am having no success. All i get is one after the other. If you could help me solve this problem without me uploading my pictures (because i can't seem to get more than one file on here) it would be greatly appreciated
What is the problem you are having?
Can't run multiple procedures simultaneously.
Describe what you have tried to solve this problem
I have tried to put both procedures into one, but its not working.
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
The code is in the next thingy.
Turing: |
View.Set ("graphics:300;450,nobuttonbar")
var background : int := Pic.FileNew ("background2.bmp")
Pic.Draw (background, 0, 0, picCopy)
var y, x, movement : int
var keys : array char of boolean
const LEFT_ARROW : char := chr (203)
const RIGHT_ARROW : char := chr (205)
const KEY_SPACE : char := chr (32)
proc attacker
randint (x, 1, 300)
var pictureNumber : int := Pic.FileNew ("tank2.bmp")
for y : 1 .. 500
Pic.Draw (pictureNumber, x, (y * - 1) + 450, picCopy)
delay (5)
end for
end attacker
procedure defender
movement := 0
var blank : int := Pic.FileNew ("blank.bmp")
var tankpic : int := Pic.FileNew ("tank1.bmp")
var tankpic2 : int := Pic.FileNew ("tank2.bmp")
for y : 0 .. 10000000
Pic.Draw (tankpic, movement, 10, picCopy)
delay (50)
Input.KeyDown (keys )
if keys (LEFT_ARROW ) then
movement := movement - 10
Pic.Draw (blank, movement + 15, 10, picCopy)
if movement = - 10 then
movement := movement + 10
end if
end if
if keys (RIGHT_ARROW ) then
movement := movement + 10
Pic.Draw (blank, (movement - 15), 10, picCopy)
if movement = 290 then
movement := movement - 10
end if
end if
if keys (KEY_SPACE ) then
for z : 1 .. 500
drawfilloval (movement + 10, z, 3, 3, black)
Pic.Draw (tankpic, movement, 10, picCopy)
delay (1)
drawfilloval (movement + 10, z, 3, 3, 4)
end for
end if
end for
end defender
loop
attacker
defender
end loop
|
Please specify what version of Turing you are using
I am using turing 4.1.1 |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
Tony

|
Posted: Mon Nov 23, 2009 7:25 pm Post subject: Re: How do you run multiple procedure simultaneously? NEED HELP FAST PLOX! |
|
|
chimerix @ Mon Nov 23, 2009 6:54 pm wrote: I am currently trying to run two procedures simultaneously but am having no success. All i get is one after the other.
That's the way it's supposed to be done. Don't think of it in terms of "at the same time", think of it in steps, that follow... one after another.
You have the right idea here
code: |
loop
attacker
defender
end loop
|
Attacker takes a step, defender takes a step, then loop repeats. They both move "at the same time" in the context of that loop.
Your problem is that you have other loops and delays inside both of those procedures. Your goal is to remove those internal loops, and use just this one main loop to move your game forward. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
 |
chimerix
|
Posted: Mon Nov 23, 2009 7:43 pm Post subject: RE:How do you run multiple procedure simultaneously? NEED HELP FAST PLOX! |
|
|
So like no for statements right? |
|
|
|
|
 |
mirhagk
|
Posted: Mon Nov 23, 2009 7:52 pm Post subject: RE:How do you run multiple procedure simultaneously? NEED HELP FAST PLOX! |
|
|
yeah tony is right, you should never have to run two procedures at once. But if you really really feel want to you can change one of the procedures to something called a process like so:
code: |
process attacker
%yur code here
end attacker
fork attacker
%rest of code here
|
that will allow the first procedure to run in the background while the rest of your code runs.
(Ps put all your files into a .zip folder to upload them) |
|
|
|
|
 |
chimerix
|
Posted: Mon Nov 23, 2009 7:57 pm Post subject: RE:How do you run multiple procedure simultaneously? NEED HELP FAST PLOX! |
|
|
That really helped Mirhagk, except, the process only runs once before the defender procedure kicks in. Plus do you know where i could find some resources on process, i really need to learn on that. |
|
|
|
|
 |
andrew.
|
Posted: Mon Nov 23, 2009 8:00 pm Post subject: RE:How do you run multiple procedure simultaneously? NEED HELP FAST PLOX! |
|
|
Don't use processes ever, unless it's for background music. It's extremely unpredictable and will screw up if you use it like this. Do what Tony said, put them one after another. The program will execute so fast, that it will appear to be simultaneous.
Turing: | loop
procedure1
procedure2
end loop |
|
|
|
|
|
 |
chimerix
|
Posted: Mon Nov 23, 2009 8:05 pm Post subject: RE:How do you run multiple procedure simultaneously? NEED HELP FAST PLOX! |
|
|
Wait, so the for statements do count as loop structures right? Just making sure. |
|
|
|
|
 |
Tony

|
Posted: Mon Nov 23, 2009 8:06 pm Post subject: Re: RE:How do you run multiple procedure simultaneously? NEED HELP FAST PLOX! |
|
|
chimerix @ Mon Nov 23, 2009 7:57 pm wrote: i really need to learn on that.
No, you don't. Processes are broken in Turing. It's a complicated topic in Computer Science in general. mirhagk has no idea what he's suggesting. You will also run into other problems down the road (hint: View.Update will not work with processes and your animations will flicker enough to make the game unplayable). |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
 |
Sponsor Sponsor

|
|
 |
chimerix
|
Posted: Mon Nov 23, 2009 8:14 pm Post subject: RE:How do you run multiple procedure simultaneously? NEED HELP FAST PLOX! |
|
|
I need a bit more explanation as i am not fully grasping what exactly i should do to make the procedures run simultaneously. |
|
|
|
|
 |
Tony

|
Posted: Mon Nov 23, 2009 8:25 pm Post subject: RE:How do you run multiple procedure simultaneously? NEED HELP FAST PLOX! |
|
|
Procedures don't run simultaneously, you need to stop thinking of it in terms of that. Quantum computers run simultaneously. Distributed networks and multi-cores run simultaneously. You have only one CPU to work with, so your characters take turns performing actions.
If any character takes too long (delays, loop, etc) then the animation becomes unbalanced.
If everybody moves really quickly, then everything flows smoothly. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
 |
mirhagk
|
Posted: Mon Nov 23, 2009 9:19 pm Post subject: RE:How do you run multiple procedure simultaneously? NEED HELP FAST PLOX! |
|
|
sorry for my post, it may have seemed like I was actually promoting the use of processes. They are horrible to use, but his code was kinda messy and I figured it'd be quicker to clean it up like that.
Plus that's what he was asking for. But seriously chimerex don't use processes. Computers can only do one thing at a time. They switch back forth from the two things to make it appear to do mulitple things but it's really only do one at a time.
running two procedures at once is actually impossible (well unless you can create your own hardware) All processes do is switch back and forth between the two commands.
so basically just do what Tony said. If you need to you can split up your code into smaller procedures if you want.
lol kinda confusing post, to sum it up, you could use processes to run both at once, but DON'T!!!! |
|
|
|
|
 |
Euphoracle

|
Posted: Tue Nov 24, 2009 8:09 am Post subject: RE:How do you run multiple procedure simultaneously? NEED HELP FAST PLOX! |
|
|
Just sayin' but you actually were promoting processes. Any, just gonna direct you to a similar post a few weeks ago,
http://compsci.ca/v3/viewtopic.php?t=22517
Cheers. |
|
|
|
|
 |
|
|