Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Find the virtual assistant peripheral
- local chat = peripheral.find("warpdriveVirtualAssistant")
- -- Define chat name
- chat.name("[name")
- -- Open rednet on the modem's side (change "left" to your modem's side)
- rednet.open("top")
- print("Waiting for chat command to broadcast coordinates...")
- while true do
- sleep(0.08)
- -- Pull the last command from the virtual assistant
- local state, CMD = chat.pullLastCommand()
- if state then
- local cmdText = string.lower(CMD or "")
- -- Attempt to match and extract the coordinates
- local x_value, y_value, z_value = cmdText:match(".*x:(%-?%d+),%s*y:(%-?%d+),%s*z:(%-?%d+)")
- if x_value and y_value and z_value then
- local x = tonumber(x_value)
- local y = tonumber(y_value)
- local z = tonumber(z_value)
- print("Broadcasting coordinates: x:" .. x .. ", y:" .. y .. ", z:" .. z)
- -- Package the coordinates into a table (you can also send a formatted string)
- local data = { x = x, y = y, z = z }
- -- Broadcast the coordinates using a custom protocol ("coordBroadcast")
- rednet.broadcast(data, "coordBroadcast")
- else
- -- Optionally, print a one-time error (or suppress further errors if needed)
- print("No valid coordinates found in command: " .. cmdText)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement