This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
H4X0RZ's profile picture

How can I use the parallel API in my case?

Started by H4X0RZ, 21 April 2013 - 04:40 AM
H4X0RZ #1
Posted 21 April 2013 - 06:40 AM
Hello comunity,

I work on an OS, but when I want to create an account then It show me the terminal :(/>/>
here is a sniped with the parallel

function button_press()
  local Event, Button, sX, sY =
os.pullEvent("mouse_click")
    for i = 1, #buttons, 1 do
      if sX >= buttons[i][1] and sX <= buttons[i][2] and sY >= buttons[i][3] and sY <= buttons[i][4] then
        button = i
      end
    end
  end 
function writing()
  term.setCursorPos(20,6)
  term.setBackgroundColor(colors.gray)
  username = read()
  term.setCursorPos(20,8)
  password = read("*")
  term.setCursorPos(20,10)
  email = read() --to be sure that one person/email has on account
end
parallel.waitForAny(witing, button_press)

I hope you can help me ^_^/>/>

thanks for reading
-Freack100-
remiX #2
Posted 21 April 2013 - 06:47 AM
Have the button press within the infinite loop.
Is it that when you click the spot it has set now in the if statement, it will cancel?

function button_press()
  while true do
    local Event, Button, sX, sY = os.pullEvent("mouse_click")
    for i = 1, #buttons, 1 do
      if sX >= buttons[i][1] and sX <= buttons[i][2] and sY >= buttons[i][3] and sY <= buttons[i][4] then
        return -- or break...
      end
    end
  end
end

Then it will cause the parallel.waitForAny to return.
At the moment, pulling any event will cause that function to return
Spongy141 #3
Posted 21 April 2013 - 06:47 AM
You need "os.pullEvent("mouse_click")" on the same line as "local Event, Button, sX, sY ="
H4X0RZ #4
Posted 21 April 2013 - 06:54 AM
Have the button press within the infinite loop.
Is it that when you click the spot it has set now in the if statement, it will cancel?

function button_press()
  while true do
    local Event, Button, sX, sY = os.pullEvent("mouse_click")
    for i = 1, #buttons, 1 do
      if sX >= buttons[i][1] and sX <= buttons[i][2] and sY >= buttons[i][3] and sY <= buttons[i][4] then
        return -- or break...
      end
    end
  end
end

Then it will cause the parallel.waitForAny to return.
At the moment, pulling any event will cause that function to return
Yes it cancels ^_^/>
SuicidalSTDz #5
Posted 21 April 2013 - 06:56 AM
You need "os.pullEvent("mouse_click")" on the same line as "local Event, Button, sX, sY ="
Nope, you can have it on the next line. It is a preference.
H4X0RZ #6
Posted 21 April 2013 - 07:39 AM
I have tested it with the infinite loop, now it complety doesn't work ;(
remiX #7
Posted 21 April 2013 - 08:09 AM
I have tested it with the infinite loop, now it complety doesn't work ;(

Well, what happens?
H4X0RZ #8
Posted 21 April 2013 - 08:18 AM
I have tested it with the infinite loop, now it complety doesn't work ;(

Well, what happens?

I can't press the buttons :(/>
remiX #9
Posted 21 April 2013 - 09:22 AM
Going to need to see more code then… because the code currently posted looks fine.
SuicidalSTDz #10
Posted 21 April 2013 - 09:35 AM
Most likely a variable not being defined properly (buttons would be my guess from the looks of it)

Of course, it could be anything above or below the snippet.
H4X0RZ #11
Posted 21 April 2013 - 10:37 AM
Most likely a variable not being defined properly (buttons would be my guess from the looks of it)

Of course, it could be anything above or below the snippet.
buttons is a table in the head of my code.
It contains two tables. In each of them are "(minX, maxX, minY, maxY, Name)"

Off-topic
I love tables :D/>
H4X0RZ #12
Posted 21 April 2013 - 10:44 AM
Going to need to see more code then… because the code currently posted looks fine.
Ok,
I will post the whole code tomorrow (just creating script)^_^/>/>/>

why just creating script?
cuz I have one program for each function of.my OS (for example "login, register, CP, config"). In my opinion it's cleaner ;D
remiX #13
Posted 21 April 2013 - 11:04 AM
Oh okay, cool :)/>
Will help you then :P/>
H4X0RZ #14
Posted 21 April 2013 - 11:22 AM
Oh okay, cool :)/>/>
Will help you then :P/>/>
Thx a lot!

BTW, Is i safe when this single programs comunicate with arguments like:
Login script:

shell.run("register", ID, API_path, "login_screen") -- login_screen is the mode in them you create the account, the other one is "CP"

and the register program:

local tArgs = {...}
ID = tostring(tArgs[1])
API_path = tostring([2])
mode = tostring([3])
-snip-
--here come the thing with the buttons 
-snip-
if button == 2 then
    if mode == "CP" then --to go back to the CP
        shell.run("CP", ID, API_path)
    elseif mode == "login_screen" then
        shell.run("login", ID, API_path)
    end
end
=D
remiX #15
Posted 21 April 2013 - 12:57 PM
Yeah, but ID and API_path need to be variables, obviously.

Wheres the button variable defined in the register program? – Nevermind, within the snipped part.
SuicidalSTDz #16
Posted 21 April 2013 - 01:00 PM
Most likely a variable not being defined properly (buttons would be my guess from the looks of it)

Of course, it could be anything above or below the snippet.
buttons is a table in the head of my code.
It contains two tables. In each of them are "(minX, maxX, minY, maxY, Name)"
I meant button – However, remiX just pointed out that it is defined in the snippet, which I poorly read..
remiX #17
Posted 21 April 2013 - 01:47 PM
Most likely a variable not being defined properly (buttons would be my guess from the looks of it)

Of course, it could be anything above or below the snippet.
buttons is a table in the head of my code.
It contains two tables. In each of them are "(minX, maxX, minY, maxY, Name)"
I meant button – However, remiX just pointed out that it is defined in the snippet, which I poorly read..

I would guess that's where he would define it. I might be wrong :P/>
H4X0RZ #18
Posted 21 April 2013 - 01:54 PM
What explicit variable do you mean?
H4X0RZ #19
Posted 22 April 2013 - 01:03 AM
I played with my coden and, ehm…. It works :D/>
Thanks to all of you ^_^/>