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

Non defined string as argument

Started by pipa, 22 January 2014 - 12:33 PM
pipa #1
Posted 22 January 2014 - 01:33 PM
Hello ,

was wondering if and how the code below could work, without having to change the m(x) to m("x"). Had a look around, but couldn't find anything.


function m(a)
if a == "x"  then
print("Thanks")
end
end
m(x)
Edited on 22 January 2014 - 12:34 PM
Bab #2
Posted 22 January 2014 - 01:51 PM
AFAIK, not unless x actually contains "x".
pipa #3
Posted 22 January 2014 - 01:55 PM
Already kinda feared this, guess i have to do it differently then. Thanks for the help :)/>.
CometWolf #4
Posted 22 January 2014 - 02:29 PM
Tell us why you need this, im sure there's a good way to Solve it.
Henness #5
Posted 22 January 2014 - 03:15 PM
As stated by Bab this would be what your describing.


function m(a)
 if a == "x"  then
  print("Thanks")
 end
end
local x = "x"
m(x)
pipa #6
Posted 22 January 2014 - 03:55 PM
Tell us why you need this, im sure there's a good way to Solve it.

Basicly a way to put in waypoints for turtles. It would be easier to make it work with a interface and also look a lot neater.

As stated by Bab this would be what your describing.


function m(a)
if a == "x"  then
  print("Thanks")
end
end
local x = "x"
m(x)

Cheers that works thanks a lot :)/>
CometWolf #7
Posted 22 January 2014 - 04:08 PM
im so lost right now, why not just use m"x"?
pipa #8
Posted 22 January 2014 - 04:43 PM
I want it to be possible to add the waypoints via a computercraft computer. I ll tell it what axis, length and what movement type (move,dig,suck,etc).
It's a lot easier and prettier to do it without """".
CometWolf #9
Posted 22 January 2014 - 05:03 PM
this seems just plain silly to me, if you're making a user interface, chances are the data they input will be a string already. If it's an API, people would have to call apiname.x to get the string, rather than just "x". But it's your code i guess, so here's how i would do it, cause i love tables!

m = {
  ["x"] = function()
    print"Thanks"
  end
}

m.x() would then print thanks
pipa #10
Posted 22 January 2014 - 05:10 PM
Probably is silly lol. At the moment i only put them in a as a simple list and figured how i could enter it using a sort of terminal.
Not done though. Thanks for the input might give it a try as it does look much simpler.