Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Need help with running multiple procedures at the same time
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Raditude




PostPosted: Thu Jun 10, 2010 8:27 am   Post subject: Need help with running multiple procedures at the same time

What is it you are trying to achieve?
Trying to be able to run more then 2 procedures at a time- Basically i have 4 buttons and i want to be able to run the left/right light turn signal at the same time as a headlight or breaklight.


What is the problem you are having?
Im just not sure how to run more then 2 procedures. I just need an idea on how to run more then 2 lights at the same time. Also, if anybody could tell me how to "toggle" a button, so that i could click a button to turn on, and click it again to turn off, thatd be great.
I've attached the picture for the dash as an attachement

Describe what you have tried to solve this problem
tried calling up different procedures for different buttons, but its just too messy.


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)


Turing:




import GUI
setscreen ("graphics:640;480")

var vipeback : int := Pic.FileNew ("viper2dash.bmp")
Pic.Draw (vipeback, maxx div 650, maxy div 650, 0)

Draw.FillOval (265, 370, 10, 10, white)
%Right Turn light
Draw.FillOval (25, 370, 10, 10, white)
%Brakelights
Draw.FillOval (325, 337 , 10 , 10 , white)
% Backlights are red
% Turn signals are Yellow
% Headlights are orange

% The delay is done to produce a realistic "Blinker" effect
% The "Blinker" runs through 5 times
procedure lefturn
    locate (1, 1)
    put "Left Turn Light ON"
    for i : 1 .. 5
   
   Draw.FillOval (265, 370, 10, 10, yellow)
        parallelput (8)
        delay (300)
        Draw.FillOval (265, 370, 10, 10, white)
        parallelput (0)
        delay (300)
    end for
end lefturn

procedure righturn
    locate (1, 1)
    put "Right Turn Light ON"
    for i : 1 .. 5
        Draw.FillOval (25, 370, 10, 10, yellow)
        parallelput (4)
        delay (300)
        Draw.FillOval (25, 370, 10, 10, white)
        parallelput (0)
        delay (300)
    end for
end righturn

procedure breaklight
    locate (1, 1)
    put "Breaklights are on"
    Draw.FillOval (325, 337 , 10 , 10 , red)
    parallelput (2)
end breaklight

procedure headlight
    locate (1, 1)
    put "Headlights are on"
    parallelput (1)
end headlight

var button1 : int := GUI.CreateButton (25, 25, -10, "", lefturn)
var button2 : int := GUI.CreateButton (25, 50, -10, "", righturn)
var button3 : int := GUI.CreateButton (150, 25, -10, "", breaklight)
var button4 : int := GUI.CreateButton (150, 50, -10, "", headlight)


loop
    exit when GUI.ProcessEvent
end loop






Please specify what version of Turing you are using
4.1.1 alpha



viper2dash.bmp
 Description:
The background for my program
 Filesize:  900.05 KB
 Viewed:  61 Time(s)

viper2dash.bmp


Sponsor
Sponsor
Sponsor
sponsor
Kharybdis




PostPosted: Thu Jun 10, 2010 8:43 am   Post subject: Re: Need help with running multiple procedures at the same time

Its possible if you use the fork command in Turing. However, i wouldn't do it this way because it also makes your program unstable. I'd just redo the whole program so you have one 'main' loop, where everything is done.

ex.

Turing:
proc Main
loop

CheckEvents (see if any button is clicked)

//Check if left light is on boolean
//Check if right light is on boolean
//Check if headlight is on boolean
//Check if breaklight is on boolean

DrawAllTheLights //draw a light if "left right is on" is set to true

end proc


Your whole problem (including how to 'toggle' a button) can be solved by using boolean statements with the buttons. Set each button to 'false' (a.k.a. not turned on). When they're turned on, keep drawing them until a condition happens where they have to turn off.
Cezna




PostPosted: Thu Jun 10, 2010 12:00 pm   Post subject: RE:Need help with running multiple procedures at the same time

You could use processes, but I would highly recommend always trying to avoid processes like the plague unless you are left with no alternatives.

You might just have to have the two procedures combined as one.

As for the button, are you using widgets?
If so, just have it's action change after it is clicked once, or just design the buttons from scratch.

If you want, I have a button module I designed that I can post for you to look at.
Raditude




PostPosted: Thu Jun 10, 2010 3:34 pm   Post subject: Re: RE:Need help with running multiple procedures at the same time

Cezna @ Thu Jun 10, 2010 12:00 pm wrote:
...

If you want, I have a button module I designed that I can post for you to look at.


Could i have a look at that? i think it would help me greatly. Thanks for the help (both of you)
Cezna




PostPosted: Thu Jun 10, 2010 5:08 pm   Post subject: Re: Need help with running multiple procedures at the same time

Alright here's my module.
There's the module and the program to run it.

If you need help understanding any of it, just let me know.

Fell free to use it unmodified, but I recommend you make your own button, as the best way to learn is usually to do it yourself.



Run CircleButton.t
 Description:
This is the program that runs it.

Download
 Filename:  Run CircleButton.t
 Filesize:  190 Bytes
 Downloaded:  98 Time(s)


CircleButton.tu
 Description:
This is the module.

Download
 Filename:  CircleButton.tu
 Filesize:  1.51 KB
 Downloaded:  79 Time(s)

Raditude




PostPosted: Thu Jun 10, 2010 6:11 pm   Post subject: Re: Need help with running multiple procedures at the same time

Cezna @ Thu Jun 10, 2010 5:08 pm wrote:
....

Fell free to use it unmodified, but I recommend you make your own button, as the best way to learn is usually to do it yourself.


Thanks! I'm gonna try to make my own, but if i have anymore questions ill ask you.
Raditude




PostPosted: Thu Jun 10, 2010 6:20 pm   Post subject: Re: Need help with running multiple procedures at the same time

Uh, question, how do i incorporate the module into the program? Is that a newb question? sorry about that, I've skipped over alot of steps while learning turing.
Cezna




PostPosted: Thu Jun 10, 2010 7:54 pm   Post subject: RE:Need help with running multiple procedures at the same time

No, it's not a noob question.

Just use the same method I used in the run program.

Import the unit at the top of your program, and then all you have t do is use the procedure.

You will have to look at the module itself to see what all of the parameters are that are used in the procedure call.
Sponsor
Sponsor
Sponsor
sponsor
InfectedWar




PostPosted: Thu Jun 10, 2010 8:14 pm   Post subject: RE:Need help with running multiple procedures at the same time

You don't need to make more than one procedure run at the same time, you just need to combine all your procedures into one procedure and run it there.

Using processes are not a good way to solve your problem, really you should only use processes when your dealing with music or your program is running in different time frames. So it's not recommended to use processes because they are a pain to plan out and to make sure they work properly.
Cezna




PostPosted: Fri Jun 11, 2010 5:18 am   Post subject: RE:Need help with running multiple procedures at the same time

That and they will never run predictably, as this is a problem with Turing.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 10 Posts ]
Jump to:   


Style:  
Search: