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

Needs an '=' symbol somewhere...

Started by ksbd, 26 January 2013 - 10:55 AM
ksbd #1
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…


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.
Kingdaro #2
Posted 26 January 2013 - 11:57 AM
At the top, "Local" should be lowercase.
Grim Reaper #3
Posted 26 January 2013 - 11:57 AM
'Local' is not a keyword in lua. However, 'local' is.

When you type:

Local x = 5
The interpreter thinks you're trying to assign a value to the identifier Local, but 'x' isn't a valid operator that can be invoked on 'Local'.

However, when you type:

local x = 5
The interpreter understands that you're using 'local' as an access specifier so you don't overwrite a value that is stored in a variable with the same level at a higher level in the current scope.
ksbd #4
Posted 26 January 2013 - 12:07 PM
Y'know, I must have deleted and retyped that line a dozen times, and each and every time I used an upper-case L.
I feel so stupid now. My excuse is that the English student in me kept interfearing. ;)/>

Thanks guys. Rage quit averted.