24 posts
Posted 13 September 2012 - 03:34 AM
Hey, I'm trying to send the resuts of turtle.getItemCount() from the turtle to a computer
-- i usually have a print(turtle.getItemCode(1)) before i try to send it out like
if something == "this" then
print(turtle.getItemCode(1))
rednet.send(8, turtle.getItemCode(1))
end
-- the #of items in that slot will print but then i get an error saying something like :350: string expected
--i did try making slot1 = turtle.getItemCode(1) so,
print(slot1)
rednet.send(8, slot1)
--same error, also made 8 = id
print(slot1)
rednet.send(id, slot1)
-still no :P/>/>, just prints.
with that code I'm just trying to help you understand what is happening. That is not the full program, it is basically code I made up now based on the part of the program giving me errors and the only part that doesn't work.
Any help would be appreciated, I'm still trying to learn lua :)/>/> (if my explanation made no sense tell me)
55 posts
Location
Everywhere.
Posted 13 September 2012 - 03:37 AM
If your using
turtle.getItemCode(1)= slot1
Then you need to turn it around to
slot1 = turtle.getItemCode(1)
Hope it works :)/>/>
EDIT: fixed crap color codes…..
24 posts
Posted 13 September 2012 - 03:39 AM
If your using
turtle.getItemCode(1)= slot1
Then you need to turn it around to
slot1 = turtle.getItemCode(1)
Hope it works :)/>/>
EDIT: fixed crap color codes…..
sorry ill fix that on the thread i just checked my coding and it was ordered like that already
55 posts
Location
Everywhere.
Posted 13 September 2012 - 04:22 AM
Can you give us the exact code then? It would appear as if you have other parts…
Also, do you have a error code with a line number?
144 posts
Location
Wellington, New Zealand
Posted 13 September 2012 - 05:27 AM
What errors are you getting?
24 posts
Posted 13 September 2012 - 12:09 PM
What errors are you getting?
Can you give us the exact code then? It would appear as if you have other parts…
Also, do you have a error code with a line number?
I get the error - Rednet:350: String expected - clearly not a line in the coding, but if i remove that one line no problems so ill assume it is the -rednet.send(8, slot)
rednet.open("right")
while true do
--also tried adding -local slot - here
sender, message, distance = rednet.receive()
slot = turtle.getItemCount(1)
if message == "inv" then
print(slot)
rednet.send(8, slot)
end
end
still prints on the turtle screen… I always fail with rednet somehow.
318 posts
Location
Somewhere on the planet called earth
Posted 13 September 2012 - 04:00 PM
.getItemCount return a number, rednet.send needs a string. try to do slot = tonumber(turtle.getItemCount(1))
Anyways a good way to find stuff liek this is too open the rednet api file up. Copyed the function send below.
SendFunction (All credit goes too the maker of rednet api.
Spoiler
function send( nRecipient, sMessage, bWaitUntilPortOpen )
if nRecipient ~= nil and (type( nRecipient ) ~= "number" or nRecipient < 0) then
error( "positive number expected" )
end
if type( sMessage ) ~= "string" then
error( "string expected" ) --Line 350 witch errord
end
local function send()
local sSide = nil
if nRecipient ~= nil then
sSide = tRoutes[nRecipient]
end
-- Offer on the known route first
if sSide then
if tOpen[sSide] and not isPortBusy( sSide ) then
runRoutine( "send", sSide, nRecipient, sMessage )
return true
end
end
-- Else, broadcast on all ports
local nPorts = 0
for n,sSide in ipairs( redstone.getSides() ) do
if tOpen[sSide] and not isPortBusy( sSide ) then
runRoutine( "send", sSide, nRecipient, sMessage )
nPorts = nPorts + 1
end
end
return (nPorts > 0)
end
if bWaitUntilPortOpen then
while not send() do
os.pullEvent( "redstone" )
end
return true
else
return send()
end
end
24 posts
Posted 13 September 2012 - 07:40 PM
.getItemCount return a number, rednet.send needs a string. try to do slot = tonumber(turtle.getItemCount(1))
Anyways a good way to find stuff liek this is too open the rednet api file up. Copyed the function send below.
SendFunction (All credit goes too the maker of rednet api.
Spoiler
function send( nRecipient, sMessage, bWaitUntilPortOpen )
if nRecipient ~= nil and (type( nRecipient ) ~= "number" or nRecipient < 0) then
error( "positive number expected" )
end
if type( sMessage ) ~= "string" then
error( "string expected" ) --Line 350 witch errord
end
local function send()
local sSide = nil
if nRecipient ~= nil then
sSide = tRoutes[nRecipient]
end
-- Offer on the known route first
if sSide then
if tOpen[sSide] and not isPortBusy( sSide ) then
runRoutine( "send", sSide, nRecipient, sMessage )
return true
end
end
-- Else, broadcast on all ports
local nPorts = 0
for n,sSide in ipairs( redstone.getSides() ) do
if tOpen[sSide] and not isPortBusy( sSide ) then
runRoutine( "send", sSide, nRecipient, sMessage )
nPorts = nPorts + 1
end
end
return (nPorts > 0)
end
if bWaitUntilPortOpen then
while not send() do
os.pullEvent( "redstone" )
end
return true
else
return send()
end
end
when I add the tonumber thing it seems to make no difference :)/>/>. I don't know why this doesn't work in the first place.
1214 posts
Location
The Sammich Kingdom
Posted 14 September 2012 - 06:24 AM
.getItemCount return a number, rednet.send needs a string. try to do slot = tonumber(turtle.getItemCount(1))
Anyways a good way to find stuff liek this is too open the rednet api file up. Copyed the function send below.
SendFunction (All credit goes too the maker of rednet api.
Spoiler
function send( nRecipient, sMessage, bWaitUntilPortOpen )
if nRecipient ~= nil and (type( nRecipient ) ~= "number" or nRecipient < 0) then
error( "positive number expected" )
end
if type( sMessage ) ~= "string" then
error( "string expected" ) --Line 350 witch errord
end
local function send()
local sSide = nil
if nRecipient ~= nil then
sSide = tRoutes[nRecipient]
end
-- Offer on the known route first
if sSide then
if tOpen[sSide] and not isPortBusy( sSide ) then
runRoutine( "send", sSide, nRecipient, sMessage )
return true
end
end
-- Else, broadcast on all ports
local nPorts = 0
for n,sSide in ipairs( redstone.getSides() ) do
if tOpen[sSide] and not isPortBusy( sSide ) then
runRoutine( "send", sSide, nRecipient, sMessage )
nPorts = nPorts + 1
end
end
return (nPorts > 0)
end
if bWaitUntilPortOpen then
while not send() do
os.pullEvent( "redstone" )
end
return true
else
return send()
end
end
when I add the tonumber thing it seems to make no difference :)/>/>. I don't know why this doesn't work in the first place.
Correction it should be:
rednet.send(id, tostring(turtle.getItemCount(1))
24 posts
Posted 14 September 2012 - 08:38 PM
.getItemCount return a number, rednet.send needs a string. try to do slot = tonumber(turtle.getItemCount(1))
Anyways a good way to find stuff liek this is too open the rednet api file up. Copyed the function send below.
SendFunction (All credit goes too the maker of rednet api.
Spoiler
function send( nRecipient, sMessage, bWaitUntilPortOpen )
if nRecipient ~= nil and (type( nRecipient ) ~= "number" or nRecipient < 0) then
error( "positive number expected" )
end
if type( sMessage ) ~= "string" then
error( "string expected" ) --Line 350 witch errord
end
local function send()
local sSide = nil
if nRecipient ~= nil then
sSide = tRoutes[nRecipient]
end
-- Offer on the known route first
if sSide then
if tOpen[sSide] and not isPortBusy( sSide ) then
runRoutine( "send", sSide, nRecipient, sMessage )
return true
end
end
-- Else, broadcast on all ports
local nPorts = 0
for n,sSide in ipairs( redstone.getSides() ) do
if tOpen[sSide] and not isPortBusy( sSide ) then
runRoutine( "send", sSide, nRecipient, sMessage )
nPorts = nPorts + 1
end
end
return (nPorts > 0)
end
if bWaitUntilPortOpen then
while not send() do
os.pullEvent( "redstone" )
end
return true
else
return send()
end
end
when I add the tonumber thing it seems to make no difference :)/>/>. I don't know why this doesn't work in the first place.
Correction it should be:
rednet.send(id, tostring(turtle.getItemCount(1))
ty it worked