[question][lua]
#1
Posted 06 June 2012 - 07:45 AM
I know it's possible to send an RS signal in and trigger an event, some text, or something similar, and I know it's possible to send an RS signal out too, to control doors or machines etc..
however, i'm wondering if I could use a pressure plate setup with RS signal input to control the cursor on screen (or even for example the snake game that comes with CC as standard)
I have an idea for a large project and want to find out if it's possible, and how to do it before I start work (as I don't want to get so far in and then realise it's not possible)
so, could I take an RS signal, and trigger a LEFTCURSOR event for example..
if so, what internal function would I use for it?
Thanks!
#2
Posted 06 June 2012 - 08:35 AM
#4
Posted 07 June 2012 - 08:13 AM
Is there any info on os.queueEvent anywhere? there's nothing on the wiki that I can see! :S
#5
Posted 07 June 2012 - 02:46 PM
Queue, then pull, and it should find your event. Good for stopping parallels, I guess. Not worked with that to any great extent.
#6
Posted 07 June 2012 - 03:06 PM
os.queueEvent("key", 123)
os.queueEvent("char", "A")
Obviously replace that with the real params for left or right arrows.
#7
Posted 05 July 2012 - 05:17 AM
here's what I have up to now...
local function game()
term.redirect(peripheral.wrap("right"))
os.run({}, "rom/programs/computer/worm")
end
local function pads()
if rs.testBundledInput("front", 16) then
os.queueEvent("key", 200)
elseif rs.testBundledInput("front", 1) then
os.queueEvent("key", 203)
elseif rs.testBundledInput("front", 2048) then
os.queueEvent("key", 205)
elseif rs.testBundledInput("front", 16384) then
os.queueEvent("key", 208)
end
os.pullEvent("key")
end
while true do
parallel.waitForAny(game, pads)
end
It starts the 'worm' game, but no input works from the bunbled inputs...
it's probably something totally silly that I have missed, but any help is appreciated...
#8
Posted 05 July 2012 - 05:35 AM
#9
Posted 05 July 2012 - 06:31 AM
(I have it set up with 4 pressure plates, when I step on YELLOW (number 16, for UP) it moves the option UP on screen, but as-soon as I step off the pressure plate, it moves back down, so it's not saving the events (or it's re-running the function all the time, and thus resetting it)
how can I get it to run worm only once, then run the 'pads' function over and over to check the inputs
#10
Posted 05 July 2012 - 06:36 AM
try a repeat just a guess as a little confused about your physical set up
repeat -- put code for controller here until a -- 1
#11
Posted 05 July 2012 - 06:41 AM
#12
Posted 05 July 2012 - 06:47 AM
so each tine I step on a key, it moves the cursor, but then on stepping off, it resets, as it's reloading the game...
I tried setting a variable to check if the game is running, and just skipping re-loading the game, however that stops the input from working...
**scratches head**
#13
Posted 05 July 2012 - 06:52 AM
I just added a repeat until like you suggested, but the 'until' condition will never be met....
i'll fix it later so a user has to press a button to end and exit the game which will then close it, but for now it works
#14
Posted 05 July 2012 - 07:02 AM
#15
Posted 05 July 2012 - 02:58 PM
This should work:
local function game()
term.redirect(peripheral.wrap("right"))
os.run({}, "rom/programs/computer/worm")
end
local function pads()
while true do
os.pullEvent("redstone") -- wait for redstone input
if rs.testBundledInput("front", 16) then
os.queueEvent("key", 200)
elseif rs.testBundledInput("front", 1) then
os.queueEvent("key", 203)
elseif rs.testBundledInput("front", 2048) then
os.queueEvent("key", 205)
elseif rs.testBundledInput("front", 16384) then
os.queueEvent("key", 208)
end
end
parallel.waitForAny(game, pads)
#16
Posted 05 July 2012 - 04:39 PM
repeat
until a -- 1
and why ur version is better it wont be as responsive surely as checking as often as the program does
MysticT, on 05 July 2012 - 02:58 PM, said:
This should work:
local function game()
term.redirect(peripheral.wrap("right"))
os.run({}, "rom/programs/computer/worm")
end
local function pads()
while true do
os.pullEvent("redstone") -- wait for redstone input
if rs.testBundledInput("front", 16) then
os.queueEvent("key", 200)
elseif rs.testBundledInput("front", 1) then
os.queueEvent("key", 203)
elseif rs.testBundledInput("front", 2048) then
os.queueEvent("key", 205)
elseif rs.testBundledInput("front", 16384) then
os.queueEvent("key", 208)
end
end
parallel.waitForAny(game, pads)
#17
Posted 05 July 2012 - 04:42 PM
MysticT, on 05 July 2012 - 02:58 PM, said:
This should work:
local function game()
term.redirect(peripheral.wrap("right"))
os.run({}, "rom/programs/computer/worm")
end
local function pads()
while true do
os.pullEvent("redstone") -- wait for redstone input
if rs.testBundledInput("front", 16) then
os.queueEvent("key", 200)
elseif rs.testBundledInput("front", 1) then
os.queueEvent("key", 203)
elseif rs.testBundledInput("front", 2048) then
os.queueEvent("key", 205)
elseif rs.testBundledInput("front", 16384) then
os.queueEvent("key", 208)
end
end
parallel.waitForAny(game, pads)
Yeah, after getting it fixed with repeat until last night, I had another look over it earlier and realised that a while true would have been better so actually made this change myself before reading your reply
#18
Posted 05 July 2012 - 04:47 PM
local function pad()
while true do
-- check all the inputs
sleep(0.5) -- you can change the time, so it checks more often
end
end
#19
Posted 05 July 2012 - 05:03 PM
just checking through a sleep like he did or this os.pull pullEvent()
#20
Posted 05 July 2012 - 05:14 PM
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











