passing parameters to running program with read()
#1
Posted 24 July 2019 - 07:29 AM
The program is a simple button toggled door contriller and imo holding Ctrl-T is not a very elegant solution.
I currently don't have access to my pc so no code , but what i do have is the jist of it:
Declare variables
While not ex do
Write button
os.pullEvent("mouse_click")
Function exit()
If read == "exit" then
ex = true
end
If ex then break
End
As you can see by this pseudo code it is very simple, but the issue I'm having is that i can't read and detect mouse clicks at the same time. I have indeed tried coroutines and parallels but the former allways errors and the latter naver runs both.
Either way I'm willing to rewrite the read command so long as it works, and i can not stress this enough, it is extremely necessary for my intentions to be able to read while pulling events.
P.S. does anyone have the sauce for the read command? I have probed Dan's code like an Ayy in his LMAO and this tomf**kerry has me all tomf**kered out, and as anyone who works with code can tell you; getting pushed down the interdimentional soulstairs of code is exhausting!
Great thanks in advance,
-qwerty
#2
Posted 24 July 2019 - 07:43 AM
qwerty, on 24 July 2019 - 07:29 AM, said:
Edited by SquidDev, 24 July 2019 - 07:43 AM.
#3
Posted 24 July 2019 - 08:36 AM
My apologies!
P.S. how would i go about re writing read to act like write rather than print and let me pull other events in the background?
#4
Posted 24 July 2019 - 01:11 PM
Edited by Dog, 24 July 2019 - 01:12 PM.
#5
Posted 24 July 2019 - 02:51 PM
https://pastebin.com/Yer4nb4c
Man all i wanted is a text input field while pulling mouse_click events, and now look where we all are.
My greatest apologies and regards,
-qwerty
#6
Posted 24 July 2019 - 03:59 PM
With regards,
-qwerty
Edited by qwerty, 24 July 2019 - 04:02 PM.
#7
Posted 24 July 2019 - 04:02 PM
local function mouseInput() while true do --# start an infinite loop local _, button, x, y = os.pullEvent("mouse_click") if x == 2 and y == 2 then sOut = not out end rs.setOutput("bottom", sOut) end end local function exitInput() while true do --# start an infinite loop term.setCursorPos(1, h - 2) term.clearLine() term.setCursorPos(1, h - 1) term.write("Type exit() to exit") term.setCursorPos(1, h) if read() == "exit()" then break end --# break the loop when exit() is entered end end parallel.waitForAny(mouseInput, exitInput)
Edited by Dog, 24 July 2019 - 04:07 PM.
#8
Posted 24 July 2019 - 04:08 PM
But i digress, without your help i may still be as confused as ever. Thank you for your help and keep up the good work!
With regards,
-qwerty
#9
Posted 25 July 2019 - 01:46 AM
That said, thank you for your contribution to my cause.
Further help apreciated but not necessary.
With regards,
-qwerty
Edited by qwerty, 25 July 2019 - 02:17 AM.
#10
Posted 25 July 2019 - 03:30 PM
#11
Posted 25 July 2019 - 04:48 PM
term.clear() term.setCursorPos(1,1) local oldBgC = term.getBackgroundColor() local BgC = colors.red local sOut = false local w,h = term.getSize() --defining button color local out = rs.getOutput("bottom") if out then BgC = colors.green else BgC = colors.red end --button "write" term.setCursorPos(1,1) term.clearLine() term.setCursorPos(2,2) term.setBackgroundColor(BgC) term.write(" ") term.setBackgroundColor(oldBgC) --button "handeler" local function btev() while true do local event, mb, x, y = os.pullEvent("mouse_click") if x == 2 and y == 2 then sOut = not out end rs.setOutput("bottom",sOut) end end --exit "handeler" local function exit() while true do term.setCursorPos(1,h-2) term.clearLine() term.setCursorPos(1,h-1) term.write('type "exit()" to exit') term.setCursorPos(1,h) if read() == "exit()" then break end end end parallel.waitForAny(btev, exit)
expectations: button yealds untill exit yelds then code stops
vs,
reality: button yealds once then waits for exit to yeald
thats as simple as i can explain it, but if you wish not to reply i'mfine with that.
With regards,
-qwerty.
#12
Posted 25 July 2019 - 06:32 PM
In regard to the button not changing the output more than once - that's because you only ever set 'out' once in the code and never set it again - and you base 'sOut' on 'out' - so neither value changes. I'd recommend making a simple change to your code, like so...
Change this...
sOut = not out
to this...
rs.setOutput("bottom", not rs.getOutput("bottom"))
and remove...
rs.setOutput("bottom", not sOut)
#13
Posted 25 July 2019 - 08:49 PM
I'm sorry for your hassles and forever in your debt.
Thank you for your help.
With regards and utmost gratitude,
-qwerty
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users