Jump to content




Non defined string as argument


  • You cannot reply to this topic
9 replies to this topic

#1 pipa

  • Members
  • 17 posts

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 by pipa, 22 January 2014 - 01:34 PM.


#2 Bab

  • Members
  • 61 posts

Posted 22 January 2014 - 01:51 PM

AFAIK, not unless x actually contains "x".

#3 pipa

  • Members
  • 17 posts

Posted 22 January 2014 - 01:55 PM

Already kinda feared this, guess i have to do it differently then. Thanks for the help :).

#4 CometWolf

  • Members
  • 1,283 posts

Posted 22 January 2014 - 02:29 PM

Tell us why you need this, im sure there's a good way to Solve it.

#5 Henness

  • Members
  • 189 posts

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)


#6 pipa

  • Members
  • 17 posts

Posted 22 January 2014 - 03:55 PM

View PostCometWolf, on 22 January 2014 - 02:29 PM, said:

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.

View PostHenness, on 22 January 2014 - 03:15 PM, said:

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 :)

#7 CometWolf

  • Members
  • 1,283 posts

Posted 22 January 2014 - 04:08 PM

im so lost right now, why not just use m"x"?

#8 pipa

  • Members
  • 17 posts

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 """".

#9 CometWolf

  • Members
  • 1,283 posts

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

#10 pipa

  • Members
  • 17 posts

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.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users