passing parameters to running program with...
qwerty 24 Jul 2019
As the title implies I'm having trouble passing certain parameters to a running program.
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
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
SquidDev 24 Jul 2019
Can you post what you tried with the parallel API? There's definitely no situation where it should only run one of them.
The source can be found here. That said, it's a bit of a behemoth of a function, so not sure how useful it'll be here.
Edited by SquidDev, 24 July 2019 - 07:43 AM.
qwerty, on 24 July 2019 - 07:29 AM, said:
P.S. does anyone have the sauce for the read command?
Edited by SquidDev, 24 July 2019 - 07:43 AM.
qwerty 24 Jul 2019
Well not that it only ran one, rather it simply yealded the firs and errored after the srcond if it wasn't "exit".
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?
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?
Dog 24 Jul 2019
I think you're over-complicating a relatively simple problem. As SquidDev requested, please post the code you tried with the parallel API - there are reasons why it didn't work for you, but we can't suggest a fix until we see exactly what you tried.
Edited by Dog, 24 July 2019 - 01:12 PM.
Edited by Dog, 24 July 2019 - 01:12 PM.
qwerty 24 Jul 2019
As per request here's the pastebin code, well documented and as informing as possable.
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
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
qwerty 24 Jul 2019
Dis regard this, thought the previous didn't post.
With regards,
-qwerty
Edited by qwerty, 24 July 2019 - 04:02 PM.
With regards,
-qwerty
Edited by qwerty, 24 July 2019 - 04:02 PM.
Dog 24 Jul 2019
I don't see where you tried to use the parallel API, but it's relatively simple to implement with what you've got. First, you need to encapsulate your input routines in functions then use the parallel API to execute both input routines. Something like this...
Edited by Dog, 24 July 2019 - 04:07 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.
qwerty 24 Jul 2019
Thank you kind sir! I am genuinely ashamed i hadn't even atempted to turn them both into functions...
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
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
qwerty 25 Jul 2019
Well yo jave helped me greatly, but unfortunately in my instance it still is ineffective as it does not Allow me to activate the button while reading.
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.
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.
qwerty 25 Jul 2019
well if you insist...
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.
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.
Dog 25 Jul 2019
OK, right now the code will exit if you type exit(), but will continue to run and allow you to click the button as often as you like without exiting. How is that different than what you want?
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...
to this...
and remove...
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)
qwerty 25 Jul 2019
My nogin's been jogin all day long and i hadn't even considered that...
I'm sorry for your hassles and forever in your debt.
Thank you for your help.
With regards and utmost gratitude,
-qwerty
I'm sorry for your hassles and forever in your debt.
Thank you for your help.
With regards and utmost gratitude,
-qwerty