Reputation: 49
This is Lua code. I want to send XXPos, YYPos, ZZPos. But In unity3d, It receive XXPos only.
socket = require("socket")
print(socket._VERSION)
function dataListener:post( t )
local XPos = ship.rb:getPosition():x()
local YPos = ship.rb:getPosition():y()
local ZPos = ship.rb:getPosition():z()
local XXPos = math.floor( XPos * 1000 + 0.5 ) / 1000
local YYPos = math.floor( YPos * 1000 + 0.5 ) / 1000
local ZZPos = math.floor( ZPos * 1000 + 0.5 ) / 1000
udp=socket.udp();
udp:setpeername("127.0.0.1",8051)
udp:send(XXPos, " ", YYPos, " ", ZZPos);
end
When I change Lua code like this,
--udp:send(XXPos, " ", YYPos, " ", ZZPos)
udp:send(string.format("%d; %d; %d",XXPos,YYPos,ZZPos))
The data is received correctly. But this result has 1 digit like 3; 5; 2.
How do I change this Lua code?
Upvotes: 0
Views: 304
Reputation: 125245
udp:send(string.format("%d; %d; %d",XXPos,YYPos,ZZPos))
should be udp:send(string.format("%f; %f; %f",XXPos,YYPos,ZZPos))
Notice the %f
. That means float.
Upvotes: 1