My ruby discoveries - Printable Version +- Save-Point (https://www.save-point.org) +-- Forum: Archives (https://www.save-point.org/forum-105.html) +--- Forum: Creation Asylum Archives (https://www.save-point.org/forum-90.html) +---- Forum: Scripts & Code Snippets (https://www.save-point.org/forum-92.html) +----- Forum: RPG Maker XP Code (https://www.save-point.org/forum-93.html) +----- Thread: My ruby discoveries (/thread-6918.html) |
My ruby discoveries - Aoshiwik - 11-23-2004 This is a locked, single-post thread from Creation Asylum. Archived here to prevent its loss. No support is given. If you are the owner of the thread, please contact administration. I have been learning ruby and here are some of my discoveries. rmpx uses ruby version 1.8.1, I found out by checking the RUBY_VERSION global constant. The ruby 1.8.1 download is worthwhile if you write scripts. It comes with better documentation, samples, and a code editor that has syntax checking . I think it is a good idea to write scripts and save them as a .rb file, and then load them into rmxp like so. Code: require 'Scripts\EightDirectionalMovement.rb' Then document the public interface (methods, attributes, or constants the user should know about) separate from the code. This way, the implementation details in the .rb remains a black box. search directories for scripts are added like this. Code: $: << Dir.getwd # $: is a global array. Each string specifies a directory to be searched for Ruby scripts. For example, this code is in my project, in a script file just above Main. I add some directories, then load the scripts I want. If you want to load scripts used by events you may have to load them in a rmxp script near the top of the list, I dont know, I have not yet worked with events much. Notice the ' ' strings, they are different then the " " strings, single quotes done use all the \ codes. Code: $: << Dir.getwd I have the two .rb files loaded by the code examples as a .zip attachment to this post. Reflection Some new features require the modification of the original rmxp scripts, for example Postality's 8 direction script needs to replace code in the Game_Player class. Reflection can examine aspects of the program from within the program itself. Using reflection it is possible to get 8 direction movement without touching the original Game_Player code. All you have to do is load a script file like the first code example, or past the new script in an empty rmxp script file and your done. This code block is for those of you interested in seeing how my first implementation of 8directionalMovement with reflection works. Code: class Game_Player # Here we name our class Game_Player so it mixes in with the original Game_Player class. rmxp_scripts.zip (Size: 1.54 KB / Downloads: 1) |