Jump to content




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


2 replies to this topic

#1 CreeperGoBoom

  • Members
  • 91 posts

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 by CreeperGoBoom, 17 December 2019 - 05:30 AM.


#2 Lupus590

  • Members
  • 2,029 posts
  • LocationUK

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 by Lupus590, 17 December 2019 - 08:27 AM.


#3 CreeperGoBoom

  • Members
  • 91 posts

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 by CreeperGoBoom, 17 December 2019 - 08:51 AM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users