link a button to an object?
Monkey Forums/Monkey Programming/link a button to an object?
| ||
If I had 3 different classes, dog,horse,cat and then I had 3 buttons on screen with the same name as the classes, Could I get monkey to create a new dog when I press the 'dog' button without explicitly programming it? i.e. without having to type if button_pushed.name='dog' local d:dog=new dog() endif could this be done with generics or interfaces? |
| ||
No, but there's a guy selling a reflection solution. Oh wait... |
| ||
You could do some kind of mapped templating... |
| ||
thanks samah,nice little example where does template:dog come from? |
| ||
Since there's no way of getting the "class" from a string (at runtime), you'll need to make an instance of any type of class that you think might be needed and put it in a map. As long as that class has an instance method to create a new object, you can do it that way. Simpler example: |