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

vars not being passed as part of a string to a function?

Started by CreeperGoBoom, 17 December 2019 - 04:28 AM
CreeperGoBoom #1
Posted 17 December 2019 - 05:28 AM
ok so say i have this:


local foo="foo"
local bar="bar"

function printString(string) --this is only an example as one of my functions has this same concept.
  print(string)
end

print(foo," ",bar)
printString("foo ",bar)
printString(foo," ",bar)

This is the result i get:

foo bar
foo
 

Note how line 3 of output was empty and line 2 was not printed fully.

Can anyone tell me why is this?
Edited on 17 December 2019 - 04:30 AM
Lupus590 #2
Posted 17 December 2019 - 08:26 AM
Your printString function only takes one argument so the other get discarded. There is a way to get variable args using the … Keyword/operator (that should be enough information for you to Google)

As for why your local variables are not getting used, does anywhere in your actual code set them to nil and are they in scope when printString is called?

You might want to post your full actual code
Edited on 17 December 2019 - 07:27 AM
CreeperGoBoom #3
Posted 17 December 2019 - 08:43 AM
hahahaha so NOW it works…

figures…

.. didnt work previously. heh

I literally must have been missing a few "."s

thankyou :)/>
Edited on 17 December 2019 - 07:51 AM