PDA

View Full Version : function from a string ?



Macsy
May 31st, 2007, 04:28 AM
Hi.
Im making a RPG game, like Final Fantasy / Zelda type.

A players attacktypes is in an array:
like :

attacks = [melee,ice,fire]

Then when a for loop and some programming the player can choose witch skill to use.

Any good idea on how to tell what function to run?

Like:

1. attack[0] is choosen.
2. the attack function is called . How?

Macsy
May 31st, 2007, 05:39 AM
I solved it, sorry...

var myFuncString:String = "myFunc"
MyFunc = function (mess){
trace(mess)
}
_root[myFuncString]('snopp')

seimon
May 31st, 2007, 06:36 PM
var myFuncString:String = "myFunc" // Error, here it will be MyFunc
MyFunc = function (mess){
trace(mess)
}
_root[myFuncString]('snopp')

// You can also do it by eval(myFuncString)('snopp')