Loading ...
Sorry, an error occurred while loading the content.

165793Function from string?

Expand Messages
  • A. P. Damien
    Nov 5, 2013
      I'm writing a game. Well, actually I guess it's more of a game engine. I
      want the game logic to be in a script. The script will take the form of
      a series of rooms, each of which can contain:

      . doors to other rooms
      . characters the player can interact with
      . things the player can pick up and use

      Any of these can have conditions on them. The condition can be expressed as:
      . Player must have (thing) in his inventory
      . Player must have at least X points
      . Player must have at least $Y money
      . Call function "f"

      That last seems to be a problem. I would like to be able to take a
      function name I've read from the script and call the corresponding
      function. Or, alternatively, the script can contain the name of a class
      which must contain a method named (for example) conditionTest.

      But I haven't figured out a way to convert a string to either a Function
      or a Class. Is there a way of doing this? If I were working in
      Javascript, I'd just call "eval", but that seems to be forbidden in AS3,

      Can I do this? Or do I have to put all the functions I might want to
      call this way in an array, and look them up that way? Or what?
    • Show all 16 messages in this topic