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

Please help its annoying me!

Started by Falco, 23 December 2012 - 08:10 PM
Falco #1
Posted 23 December 2012 - 09:10 PM
Okay first off thanks for looking at my post, okay I'm trying to avoid the "LONG" turtle commands for my programs so I decided to create functions insted, example:

function digforward()
turtle.dig
turtle.forward
turtle.digUp
end

Now I'm new to ComputerCraft and I cant understand why this wouldn't work…?

Heres my full code thats in my file currently and im getting the error: '=' expected on line 6.

Spoiler

-- Written by Falco.

-- ******* basic moving functions ******* --
function forward()
	turtle.forward
end

function turnleft()
	turtle.turnLeft
end

function turnright()
	turtle.turnRight
end

function digforward()
	turtle.dig
	turtle.forward
	turtle.digUp
end
-- ******* end of basic moving functions ******* --

digforward()
Goof #2
Posted 23 December 2012 - 09:27 PM
All apis, requirres two () parantheses after the function.it tells you, that it think turtle.dig is a variable, but there is no variable in it..

Just remember the parantheses in the end of all your turtle commands.
Falco #3
Posted 23 December 2012 - 09:29 PM
All apis, requirres two () parantheses after the function.it tells you, that it think turtle.dig is a variable, but there is no variable in it..

Just remember the parantheses in the end of all your turtle commands.

I can't belive i missed those… DERP delete this post if needed its a waste of time and thank you very much my good sir :)/>
Falco #4
Posted 23 December 2012 - 09:31 PM
WAIT!!!! im stil getting an error on line 6….. the "=" is expected…
remiX #5
Posted 23 December 2012 - 10:23 PM
WAIT!!!! im stil getting an error on line 6….. the "=" is expected…

Did you add the () to the end of each turtle command?
De Tronazox #6
Posted 23 December 2012 - 10:35 PM
Use () at the end:



function digforward()
turtle.dig()
turtle
.forward()
turtle
.digUp()
end
De Tronazox #7
Posted 23 December 2012 - 10:36 PM
The whole code done:



-- Written by Falco.

-- ******* basic moving functions ******* --
function forward()
        turtle.forward()
end

function turnleft()
        turtle.turnLeft()
end

function turnright()
        turtle.turnRight()
end

function digforward()
        turtle.dig()
        turtle.forward()
        turtle.digUp()
end
-- ******* end of basic moving functions ******* --

digforward()
Falco #8
Posted 23 December 2012 - 11:55 PM
Thanks for the help guys i relised what the problem was i was saving it to the wrong file so changes i was making wasnt changing when i ran it on the PC HERP A DERP DERP!
jag #9
Posted 24 December 2012 - 12:42 AM
All apis, requirres two () parantheses after the function.it tells you, that it think turtle.dig is a variable, but there is no variable in it..

Just remember the parantheses in the end of all your turtle commands.

If I'm not incorrect about this, then isn't almost everything a form of a variable?
For example

-- Tables
local myTable = {
  somthing = "nothing",
  someone = "noone",
}
local newTable = myTable

-- Variables
local myVariable = "foo"
local newVariable = myVariable

-- Functions
local function myFunc()
  print("good")
  print("morning")
  print("mr cucumber")
end
local newFunc = myFunc

-- A nice combination, tables + functions
local moves = {
  up = turtle.up
  down = turtle.down
  left = turtle.turnLeft
  right = turtle.turnRight
}

-- Playing though the table
for id,value in pairs(moves) do
  moves[id]()
end

In the example of tables + functions, you could maybe figure out that this is the same way the (for example turtle) functions are grouped.
Goof #10
Posted 24 December 2012 - 01:24 AM
yes it is, but in the way the OP did it it is not… because he didnt make any variable to that turtle command… he just forgot to make the two parantheses at the end ()

:)/>
Zambonie #11
Posted 24 December 2012 - 06:12 AM
I poroly could tell you the answer,but my computer wont let me open the spoiler!
ChunLing #12
Posted 24 December 2012 - 07:12 PM
Or rather, Lua always expects you to do something with a variable. The default assumption is that you are going to assign it a value (from another variable, a function, or an operation). But you can also call them if they contain functions, which is what was intended in this case.
KaoS #13
Posted 24 December 2012 - 07:22 PM
I poroly could tell you the answer,but my computer wont let me open the spoiler!

what browser are you using? it probably doesn't support the script used to open the spoiler

EDIT: they are using javascript and of course CSS. if your browser doesn't support those then I really don't know where you got that from
ChunLing #14
Posted 24 December 2012 - 08:00 PM
Well, most browsers allow for those to be disabled.
KaoS #15
Posted 24 December 2012 - 08:01 PM
haha derp. so true