Posted 26 January 2013 - 11:55 AM
After spending the last hour trying to figure out the rednet api along with revision for upcoming exams, I think I've gotten to a certain level of stress where even the most simple fixes are oblivious to me… So, I thought I'd ask someone on here just what I'm doing wrong…
The code I'm trying to make will collect data from 8 other computers (either full, charging or none for redstone energy cells) and then send that data to a turtle to allow it to retrieve 'full' ones, and place empty ones where 'none' applies. It's giving the error: [string "test1"]:1: '=' expected. So I assume it's something to do with the numerous variables I define…
Also, is there a more efficient way to go about this? All I really know about programming is basic function use, that you can define and compare variables, and that there are if, while and for loops - all of which seem sufficient to create all the codes I've attempted so far, but to use a long, lengthy 'if' to take this data, and determine what to send to a turtle seems a little offputting… I'm sorry if I'm not articulating what I mean properly… I guess what I'm asking is if there's some way of writing one piece of code to apply to all the individual variables… Something like a function that isn't set to just 1 variable, but which I can can use to check C1v, and if neither full or none, check C2v, etc without writing "if… elseif… elseif…" etc for each individual variable.
It's late, so I'm sorry if what I'm asking isn't clear. I'll probably edit this post in the morn to declutter it.
Local C1, C2, C3, C4, C5, C6, C7, C8 = 96, 97, 99, 100, 101, 102, 103, 104
Local C1v, C2v, C3v, C4v, C5v, C6v, C7v, C8v
function netClose()
rednet.close("right")
end
function netOpen()
netClose()
rednet.open("right")
end
function getData()
local compID, value, distance = rednet.receive()
end
function assignData()
netOpen()
getData()
if compID == C1 then
C1v = value
print("Computer 1 reports: "..C1v)
elseif compID == C2 then
C2v = value
print("Computer 2 reports: "..C2v)
elseif compID == C3 then
C3v = value
print("Computer 3 reports: "..C3v)
elseif compID == C4 then
C4v = value
print("Computer 4 reports: "..C4v)
elseif compID == C5 then
C5v = value
print("Computer 5 reports: "..C5v)
elseif compID == C6 then
C6v = value
print("Computer 6 reports: "..C6v)
elseif compID == C7 then
C7v = value
print("Computer 7 reports: "..C7v)
elseif compID == C8 then
C8v = value
print("Computer 8 reports: "..C8v)
end
end
while true do assignData() end
The code I'm trying to make will collect data from 8 other computers (either full, charging or none for redstone energy cells) and then send that data to a turtle to allow it to retrieve 'full' ones, and place empty ones where 'none' applies. It's giving the error: [string "test1"]:1: '=' expected. So I assume it's something to do with the numerous variables I define…
Also, is there a more efficient way to go about this? All I really know about programming is basic function use, that you can define and compare variables, and that there are if, while and for loops - all of which seem sufficient to create all the codes I've attempted so far, but to use a long, lengthy 'if' to take this data, and determine what to send to a turtle seems a little offputting… I'm sorry if I'm not articulating what I mean properly… I guess what I'm asking is if there's some way of writing one piece of code to apply to all the individual variables… Something like a function that isn't set to just 1 variable, but which I can can use to check C1v, and if neither full or none, check C2v, etc without writing "if… elseif… elseif…" etc for each individual variable.
It's late, so I'm sorry if what I'm asking isn't clear. I'll probably edit this post in the morn to declutter it.