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

Why doesnt this work?

Started by AstroMan2013, 28 May 2015 - 03:56 PM
AstroMan2013 #1
Posted 28 May 2015 - 05:56 PM
Pastebin wont work so I took a screenshot, why does my script not work?
LDDestroier #2
Posted 28 May 2015 - 06:17 PM
What do you want it to do, and what does it do instead? Then I can help you.
flaghacker #3
Posted 28 May 2015 - 06:22 PM
He's probably getting

9: '=' expected
.

You forgot the parentheses of mon.clear on line 9.

When you receive an error in the future, always check the lines arround where you got the error for mistakes.
LDDestroier #4
Posted 28 May 2015 - 06:23 PM
He's probably getting

9: '=' expected
.

You forgot the parentheses of mon.clear on line 9.

When you receive an error in the future, always check the lines arround where you got the error for mistakes.
Oh yeah, that's right.
Agent Silence #5
Posted 28 May 2015 - 06:52 PM
Someone should really clear up programs and ask a pro. People keep posting in programs.
Edited on 28 May 2015 - 04:53 PM
CrazedProgrammer #6
Posted 28 May 2015 - 07:00 PM
You wrote
rednet.recieve
instead of
rednet.receive
.
flaghacker #7
Posted 28 May 2015 - 07:01 PM
Someone should really clear up programs and ask a pro. People keep posting in programs.

And bugs, and commands…

I think the admins are doing a great job of moving topics to their correct forum. (all the posts with a minecart as icon are already moved) It's normal that it occasionally takes them a couple of houres to move them, but that's not really a problem.
Edited on 28 May 2015 - 05:03 PM
Cranium #8
Posted 28 May 2015 - 07:07 PM
Moved to Ask A Pro.
AstroMan2013 #9
Posted 28 May 2015 - 08:47 PM
I got an error for line 10 so lol. Anyway thanks for telling me about what i did wrong.

You wrote
rednet.recieve
instead of
rednet.receive
.
Thanks! lol i am bad at this
jaredallard #10
Posted 29 May 2015 - 03:59 AM
I'm going to go Stackoverflow style on this:


What went wrong?

You referred to a function, however, you did not call it.
You tried to call a function but it's value was nil (or better said as nothing)
(not an issue) but indentation.


What does any of this mean?

Well, simply they are small errors and I once had problems with this to. (if you don't believe me, I legitimately asked why my JSON wouldn't parse. Hint: it wasn't JSON)


Functions & Pointing to them

In reference to issue 1, that is technically not an error. Nor would lua report that as an error, but inorder to understand why that wouldn't work we have to discuss how a language interprets the actual "words".
It didn't call the function, why? Because simply it wasn't told to. In Lua, and other languages, the JIT compiler interprets the script in real time. When it reached


mon.clear

it simply returned the value of mon.clear, which was a function. Why? Because that's how you link to a section in memory, that's essentially a pointer to a location in memory of a function, however, unless you explicitly call () on that pointer it will never do anything. When you use () it tells the interpreter to execute, call, that value. This is why you get errors when you attempt to call a not function, it cannot interpret the value as code.

Trying to call a nil value.

Issue 2, this is a simple one. Much like the aforementioned, you attempted to call a function but this time when it tried to call it, it wasn't allocated thus it returned the value of nil. nil, is not correct lua code thus it cannot execute it.


Indentation

While this isn't a big issue, it does help. Indenting your code shows the relation to certain statements, i.e.


if false then
  -- This will never be called!
  print("Oh no, false was false and this still executed!!!!!")
END


Much better than than this:


if false then
-- This will never be called!
print("Oh no, false was false and this still executed!!!!!")
END

It gets even worse when you have a lot of if statements like this:


if false then
x()
y()
z = 1+1
if true then
doX()
y()
if false then
doU()
doIt()
end
end
end


In the end..

First off, welcome to the community and I hope you make some awesome stuff! Second, don't get frustrated by code going wrong or etc, that's the fun part! Nothing is better than fixing bugs and seeing your software work great. One day you will look back and laugh at your silly mistakes, but they are what make us better programmers. I highly recommend you take some time to read other peoples code so you can get a feel for the language and read up on the documentation of ComputerCraft itself.

Have an awesome day!
Edited on 29 May 2015 - 02:08 AM