If I have a class named ‘team’ and a public member function of that class as below, why can I not pass a string to it as a parameter? The string is always received in the function as ‘nil’. (However, passing in numbers works fine!!? :S)
Because you declared the function with : msg is the second parameter to the function, not the first (which is self). The error is given because “Red Team” is the self variable inside of setName and not msg. Because : was not an original part of the language and merely syntax sugar to make things easier to read, it’s very easy to trick (both for good and bad), allowing you to pass fake ‘self’ values into any function by simply using the . and adding a different first parameter.
You can either pass team1 into the function, call it with a :, or declare it with a . (if you don’t need the self parameter). [import]uid: 134101 topic_id: 29920 reply_id: 119939[/import]
Because you declared the function with : msg is the second parameter to the function, not the first (which is self). The error is given because “Red Team” is the self variable inside of setName and not msg. Because : was not an original part of the language and merely syntax sugar to make things easier to read, it’s very easy to trick (both for good and bad), allowing you to pass fake ‘self’ values into any function by simply using the . and adding a different first parameter.
You can either pass team1 into the function, call it with a :, or declare it with a . (if you don’t need the self parameter). [import]uid: 134101 topic_id: 29920 reply_id: 119939[/import]