Hello everyone,
I've been trying to make a simple treefarm program and for that i want a computer to run a program that lets the treefarm run but stops the program when i press enter.
So it's just quitting a loop on a key press. I've already tried with parallels, but i don't seem to be able to get it right. Maybe because i use os.pullEventRaw in one of the loops.
Anyways, I woud find it very helpful if someone could help me, as it is something i would like to use more often in my programs.
thanks! :)/>/>
You'll probably want to take a look at the parallel API, specifically the command parallel.waitForAny
This command lets you give it multiple functions that (more or less) run at the same time. waitForAny will exit when at least one of those functions returns/exits.
One function should contain a "while true do" loop that never exits, and contain your main code.
The second function will watch for key events.
If you don't care which key is pressed, that second function can just poll for a key event, and it will return once something is pressed.
Otherwise it can be a while loop watching key events, which only does a break if the correct key is pressed, causing it to exit.
I can post verified code later today once I get home if desired.