• Beginner mistake probably involving functions.
    1 replies, posted
Okay. So since I am learning Lua, and coding in general, I decided to try to make a simple script that uses pre-determined to follow a checklist, and then have everything assemble together with concatenation in a final sentence. Here is my code: [code] age = 19 photoid = 1 function youAge(whatsAge) end function photoPossess(whatsPhoto) end function myWord(whatsWord) end if age == 20 then youAge("You are 20 ") else youAge("You are not 20 ") end if photoid == 1 then photoPossess("you can buy alcohol.") else photoPossess ("you can not buy alcohol.") end if age == 20 and photoid == 1 then myWord("and ") else myWord("but ") end function alcoholics() Msg(whatsAge..whatsWord..whatsPhoto) --Here is where console is saying the wrench is stuck. end alcoholics() [/code] The error in Gmod is claiming this. [code][lua\alcoholics.lua:33] attempt to concatenate global 'whatsWord' (a nil value) [/code] Now, I think I must have messed something up with the functions in the if/then statements, because the console looks like it is saying to me in console that whatsWord is a function instead of an argument like I assigned earlier in the code. whatsWord being the argument belonging to the function myWord() ( myWord(whatsWord) ). If you can tell me what the problem is, and why it is happening, that would be greatly appreciated. Also, if you have any ideas on how to optimize the code, that would help too. Thanks for reading!
You never defined whatsWord, whatsAge, and whatsPhoto. You cannot call a argument of a function, only the function. The argument passed into a function is dynamic either way.
Sorry, you need to Log In to post a reply to this thread.