howto.PythonRedefine 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. Python Redefine FAQ
  2. Q: So, what is Ctrl-C-Ctrl-V?
  3. A: Since Python is an interpreted language, you can redefine code on the
  4. fly. Let’s say you have a class method that creates and plays a sword slash
  5. interval, carefully timing an animation, a particle effect, and a sound
  6. effect. If you could tweak the timing and properties of this interval in
  7. your code and magically hit a hotkey to see the change immediately in-game,
  8. it would cut your iteration time from a 5 minute restart down to 1
  9. second. ctrl-c-ctrl-v is that magic hotkey. Of course it works on arbitrary
  10. Python classes, not just intervals. If you are show-coding in Emacs, you
  11. really should try it -- it can save you lots of time!
  12. Q: How do I use it?
  13. A: In your Emacs buffer within your class definition, make a change to a
  14. function and hit control-c-control-v. This will redefine the function, and
  15. in fact the entire class and thus all objects that are defined by that
  16. class. Some feedback will be printed out at the Python prompt.
  17. Q: Does it only work in Emacs?
  18. A: Yes, unfortunately it only works from inside Emacs right now, but it can
  19. probably be adapted to any scriptable editor. Most of the code is in
  20. Python, not in emacs (lisp). Ask if you are curious about getting this
  21. working in your favorite editor.
  22. Q: Can I redefine code on the client and the AI?
  23. A: If you are using multi-python Emacs buffers, it will actually redefine
  24. this class on the AI, Uberdog, and client simultaneously. Otherwise, you
  25. must control-c-control-v from the Emacs where you are running the process
  26. you want the class redefined in. Note, if the class does not exist on the
  27. AI or client, it will safely ignore.
  28. Q: What about systems that store function callbacks?
  29. A: The common systems that store function callbacks are properly searched
  30. and replaced when you control-c-control-v. This includes the TaskManager,
  31. FunctionIntervals (new), ClassicFSMs, the Messenger, and DistributedObject
  32. dc updates. If you are storing a function pointer in your own code ad hoc,
  33. the Finder will not currently replace that; though I could imagine a brute
  34. force way to find those too.