Jump to content




Obvious Question :S (Paralell API)


  • You cannot reply to this topic
5 replies to this topic

#1 LucasUK

  • Members
  • 64 posts

Posted 13 August 2012 - 06:39 PM

Here's my code so far, I want to be able to use (at the moment print to test but also other things) either the message typed in, or the message received as a variable basically. (assigned to a)

Currently it returns either 1 (Received message) or 2 (Input message). The send or receive bit work fine!!

Please guide me!


function initialise (vRednetSide, vElevatorSide)
rednet.open (vRednetSide)
redstone.setOutput(vElevatorSide, false)
end
function Listen ()
senderId, message, distance = rednet.receive()
print (message)
return message
end

function selectFloor ()
write ("Enter floor: ")
vFloor = read()
rednet.broadcast(vFloor)
return vFloor
end

initialise ("back", "bottom")
a = parallel.waitForAny (Listen, selectFloor)
print (a)


#2 ardera

  • Members
  • 503 posts
  • LocationGermany

Posted 13 August 2012 - 07:01 PM

If i understood (<-- don't know if this irregular verb is right) right: you want to get the return of the functions given to parallel.waitForAny ? then here is my solution:
ret=""
function initialise (vRednetSide, vElevatorSide)
rednet.open (vRednetSide)
redstone.setOutput(vElevatorSide, false)
end
function Listen ()
senderId, message, distance = rednet.receive()
print (message)
ret=message
return
end

function selectFloor ()
write ("Enter floor: ")
vFloor = read()
rednet.broadcast(vFloor)
ret=vFloor
return
end

initialise ("back", "bottom")
a = parallel.waitForAny (Listen, selectFloor)
print (a)
-- return of functions is variable ret


#3 LucasUK

  • Members
  • 64 posts

Posted 13 August 2012 - 07:06 PM

Works a charm thanks!, any way of doing this as an object without creating a global variable?

No rush as above solution is good workaround :P/>

#4 ardera

  • Members
  • 503 posts
  • LocationGermany

Posted 13 August 2012 - 07:19 PM

only replace ' ret="" ' with ' local ret="" ' :P/>

#5 LucasUK

  • Members
  • 64 posts

Posted 14 August 2012 - 04:54 PM

I mean can I read the return values of the functions directly? Rather than create a variable and have the function edit this.

This means I can code functions independently of these variables.

#6 bjornir90

  • Members
  • 378 posts
  • LocationFrance

Posted 28 November 2012 - 09:11 AM

View PostLucasUK, on 14 August 2012 - 04:54 PM, said:

I mean can I read the return values of the functions directly? Rather than create a variable and have the function edit this.

This means I can code functions independently of these variables.
I'm very sorry for the very old thread deterring but I want to get an answer to that same question and don't want to create a new topic because I think I have already made alot.





3 user(s) are reading this topic

0 members, 3 guests, 0 anonymous users