P is for Practical | |
PerlMonks |
Re: Daft text adventure projectby jeroenes (Priest) |
on May 29, 2001 at 16:53 UTC ( [id://83908]=note: print w/replies, xml ) | Need Help?? |
I like this kind of ambitions very much :-).
For the 'back' feature: You need a whole new interface for that, whether you implement it in object-oriented perl or just in function-perl. You'll have to rewrite every instance of changing a variable to use code that remembers that chance. So instead of saying $foo++ you would say something like increment( $foo, $undo_stack). Because of inheritance, this is somewhat easier to mix in some OOP code than into non-OOP code, but your that really depends on how you have written/will write the code. Anyhow, you have to put into an extra layer between your normal code and the change of variables. I would use a undo-stack of a certain size (depending on the amount of resources you want to use). You can only undo the action that has been pushed onto the stack the last. When the stack exceeds its predefined size, you 'freeze' the first action of that stack into the vars. Many GUI-OO libs have a predefined undo-class. However, you need to write your own methods/ childs to define undo-actions for your own code... Hope this helps,
Jeroen
In Section
Seekers of Perl Wisdom
|
|