Event functions are global variable requiring bastards. I have a variable called myNum (=55). This is sent to a function as a parameter called mN (seems myNum and mN should be the same exact thing; one is the ‘global variable’ presumably and the other is a parameter OF this same thing). But when I subtract 1 from mN every frame, it has no affect on myNum. I want operations performed on mN to affect myNum.
var myNum = 55
stage.addEventListener(Event.ENTER_FRAME, onEnter)
function onEnter(e){
doThis(myNum)
}
function doThis(mN){
mN -= 1
trace(mN + ' ' + myNum)
}
//traces '54 55'... '54 55'... '54 55'... repeatedly, but clearly I am SUBTRACTING 1 each time
This forum is always so helpful, thanks.
That was a simplified example though. my actual function took 5 parameters, not just 1. So my guess is that a function can only return ONE variable, in which case I guessed it should be one ARRAY composed of those 5. But that doesn’t work. (this is just the same ‘return’ thing posted above but with more parameters, and an array returned OF those parameters. The array does not affect the original array like I want it to though).
Re: kookaburra- That makes sense, however the purpose of the function was to encapsulate. Like maybe I have a hundred different variables and I want to be able to call doThis with ANY of them… kinda like
variable1 = '55’
variable2 = '100’
doThis(variable1) // returns 54
doThis(variable2) // returns 99
That function is not reusable if its hard coded to always use a specific global variable.
(if any of this makes sense)