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

Help with the Modem API

Started by Astrophylite, 17 July 2015 - 04:59 PM
Astrophylite #1
Posted 17 July 2015 - 06:59 PM
Hi,

I was wondering if anyone could help me with this code.
I was trying to make a remote unlock but I only want it working from a certain distance.
I tried to put "if senderDistance == 3 then" but it just kept opening and closing and I was way over 5 blocks away..

Code: http://pastebin.com/AWNeVpPp

Thanks in advance,
ZiR
Lupus590 #2
Posted 17 July 2015 - 07:08 PM
Could you give us a line number to work with? Where do you need this distance check?
Edited on 17 July 2015 - 05:09 PM
jerimo #3
Posted 17 July 2015 - 07:22 PM
Line 25 you are declaring a function inside a while loop, meaning that it will be declared every time that loop runs, if it runs at all never attempted such a thing personally
Also you are locking/unlocking the door if there is a player event, without checking anything then pulling a new event and seeing if its a modem event, without checking the distance at all.

Not your exact problem but imagine what would happen if you had a modem message followed by a player message. Your code would take the modem message see its not a player event and take the player event see its not a modem message and discard it.
To solve this simply change your if in line 51 to an elseif
Astrophylite #4
Posted 18 July 2015 - 11:57 AM
Thank you both for your responses. I am just about to split the two scripts into separate programs to debug it :)/>

I will let you know the outcome if I need anymore help !