OK, I feel like a complete moron for even asking this, especially having tinkered with JavaScript and TorqueScript before coming to Lua…
Basically, I’ve never fully understood the use of “return” at the end of a function. Seems like the most novice question, but it’s time that I understand it fully.
So in the following sample snippet:
local function killOneEnemy ( enemyCount )
local newEnemyCount = enemyCount - 1
return newEnemyCount
end
This “returns” the updated enemy count, correct? But returns it to where/what? To another function that called this “killOneEnemy” function? Where does the returned value get sent to? What happens to it? How can I use it?
And then consider a basic “return” with no value:
return
What purpose does this serve? Return nothing? Does it “end” the function, like a flow break?
Finally,
return true
This does what? Returns “true”? What is true , an arbitrary boolean? How does the language interpret/use this? Why does adding “return true” to the end of a function in Corona effectively “stop” other functions, i.e. when you have a button, it processes only that button and prevents any actions in groups/layers below it?
Argh, this should be so simple, but for some reason I’ve never fully understood the “return” code, not in Javascript, TorqueScript, nor Corona. I understand how to pass variables to functions, but I’m not really sure how to retrieve them and use them.
Any help is appreciated, I’m sure somebody can clarify it for me easily…
Brent
[import]uid: 9747 topic_id: 2821 reply_id: 302821[/import]