
-----------------------------------
amir20001
Mon Mar 30, 2009 5:20 pm

need help with processes
-----------------------------------
is there to make a processes return a value or effect a variable for example

[code]
var a :int
a:=0
process b
a:=5
end b
fork b
put a 
[/code]


would return a as 0 not 5

-----------------------------------
Tony
Mon Mar 30, 2009 6:53 pm

RE:need help with processes
-----------------------------------
The above does set a to 5. Sometimes. You should probably use a [tdoc]function[/tdoc] though.

-----------------------------------
Insectoid
Mon Mar 30, 2009 6:59 pm

RE:need help with processes
-----------------------------------
Processes execute code pseudo-simultaneously with the other code. So  'put A' happens before process B can modify A. Procedures are similar, but they do not run at the same time. They run like regular code, one after the other. Functions are like procedures, but they return a value.

Also, post #1000! I can use da VIP lounge now! You should feel special that I thought this thread worthy of my 1000'd post. Not really. Unless you want to.

-----------------------------------
DemonWasp
Mon Mar 30, 2009 8:04 pm

RE:need help with processes
-----------------------------------
Better question: WHY do you want a process to return a value? We can probably give you some other solution that's a bit more thread-safe.

-----------------------------------
amir20001
Mon Mar 30, 2009 9:18 pm

Re: need help with processes
-----------------------------------
i'm sure i'm going about this wrong but i have to make a game don't wanna bore you with details but its pretty much a series of quick time events this the part i have for getting the keys pressed 

[code]
var a: string
process chars
    if hasch then
   a:=getchar
        put a 
        Input.Flush
       
    end if
    end chars
loop
delay (10)
fork chars
end loop
[/code]

but i want to be able to compare the a value outside the process( if the key pressed is 'w' or something like that). the only way i can see this being done is by having this in the background constantly witch  is why i used a process. if you can tell me how this can be done or let me know of a more efficient way of doing this.
thanks in advance

-----------------------------------
DanielG
Mon Mar 30, 2009 9:42 pm

RE:need help with processes
-----------------------------------
just use a function in a loop, the loop should be repeating often enough and it won't give you the potential for errors due to it running simulatinously. The only thing you should use turing processes for is music.

-----------------------------------
amir20001
Mon Mar 30, 2009 9:52 pm

RE:need help with processes
-----------------------------------
ok thx just one more question what is the difference between functions and procedure

-----------------------------------
Tony
Mon Mar 30, 2009 10:20 pm

RE:need help with processes
-----------------------------------
a procedure is a function that does not return a value.

-----------------------------------
SNIPERDUDE
Tue Mar 31, 2009 11:19 am

RE:need help with processes
-----------------------------------
example:
% The procedure changes a global variable without returning a value
procedure test (stuff : int)
    a := stuff
end test

% The function returns a value, but runs in a similar way to the procedure
function test2 (stuff : int) : int %