Macro XP/VX

Easy Macro
Version:1.1.0.3
By: Lionel

Introduction
Hello, This Macro Script Helps You With Rewriting Code
The Macro Is A Set Of Common Commands You Would use,
Like Constantly Using a long number(5.54545449998731973218456264) In your Code.
This Makes Script writing easier
Instructions
Paste the Script In The Script Editor Above Main , Then Edit The Commands Where #Type Message Here and #Put objects in here are.
Then Use The Commands That It Shows In Your Own Script To Make Scripting Easier
Screenshots
Its Impossible To Take A Screen Shot
Features
Macro Objects
Macro Message
Macro Block
Macro Cache
Script
Macro Spoiler
  1.  
  2. #==============================================================
  3. #Easy Macro 1.3
  4. #By Lionel
  5. #==============================================================
  6. #To Use A Macro object, Use Macro.ob(Command Number)
  7. #To Use A Macro message, Use Macro.msg(Message Number)
  8. module System
  9.   class Macro
  10.       #Add Username Here!
  11.       User=""
  12.       if User=""
  13.         print 'Exerption:BAD DATA(Please rant about this to the owner,(Type:NO NAME!)"
  14.      #------------------------------------------------------------
  15.      #Macro/Object (MO)
  16.      #------------------------------------------------------------
  17.      def self.ob(num)
  18.         if num==1
  19.            return mcrarr=[]#Put objects in here
  20.         elsif num==2
  21.            return mcrhsh={}#Put objects in here
  22.         elsif num==3
  23.            return mcrsng=''#Put objects in here
  24.         else
  25.            print 'Exerption:BAD DATA(Please rant about this to'+User+",(Type:Out of bounds args)"
  26.         end
  27.      end
  28.      #------------------------------------------------------------
  29.      #Macro/Message (MM)
  30.      #------------------------------------------------------------
  31.      def self.msg(msg)
  32.         if msg==1
  33.            print ''#Type Message Here
  34.         elsif msg==2
  35.            print ''#Type Message Here
  36.         elsif msg==3
  37.            print ''#Type Message Here
  38.        else
  39.          print 'Exerption:BAD DATA(Please rant about this to'+User+",(Type:Out of bounds args)"
  40.         end
  41.      end
  42.      #-------------------------------------------------------------
  43.      #Macro/Block (MB)
  44.      #-------------------------------------------------------------
  45.      def self.bck1
  46.         #Put A Heavily Used Block Here
  47.      end
  48.      def self.bck2
  49.         #Put A Heavily Used Block Here
  50.      end
  51.      def self.bck3
  52.         #Put A Heavily Used Block Here
  53.      end
  54.      #--------------------------------------------------------------
  55.      #Macro/Cache (MC)
  56.      #--------------------------------------------------------------
  57.      def self.Che
  58.         $Cache=[]
  59.         def Che.del
  60.            $Cache=nil
  61.         end
  62.         def Che.clr
  63.            if $Cache==[]
  64.               print 'Exerption:BAD DATA(Please rant about this to'+User+",(Type:Object Empty)"
  65.            else
  66.               $Cache=[]
  67.            end
  68.         end
  69.       end
  70.    end
  71.  end
  72. end
  73.  
  74.  
Expand to see the code.

How to use
  1.  
  2. include System
  3. Macro.#Add something here!
  4.  
Expand to see the code.

Compatibility
This Script Works In XP And VX
Credits and Thanks
I Don't Require Credit (But It's ok!)
Author's Notes
If Your Making A Script With This, Post The Macro You Used.
I don't understand how to use your script.
PI.new is longer than
  1. include Math
  2. Pi
Expand to see the code.

And about the print messages you can also use Constants...

berka
I Don't Know What You Mean About The Constants But This Is How It Works,
Your Making A Script In XP/VX and You Use A Array,Hash,string, or message In Many Classes.
You Put The Frequently Used Array,Hash,string, or message in the slot
Slots
  1. $mcrarr=[]#Put array objects in here
  2. $mcrhsh={}#Put hash objects in here
  3. $mcrsng=''#Put Text in here
  4. print ''#Type Message Here
  5. print ''#Type Message Here
  6. print ''#Type Message Here
  7.  
Expand to see the code.

Then Call The Function In The Code

Funtions
  1. Macro.ob(num)#num Is The Object Number
  2. Macro.msg(msg)#msg Is The Message Number
  3.  
Expand to see the code.

Here's A Edited Macro
  1. #==============================================================
  2. #Easy Macro
  3. #By Lionel
  4. #==============================================================
  5. #To Use A Macro object, Use Macro.ob(Command Number)
  6. #To Use A Macro message, Use Macro.msg(Message Number)
  7. begin
  8.   Macro=self
  9.   #------------------------------------------------------------
  10.   #Macro/Object (MO)
  11.   #------------------------------------------------------------
  12.   def Macro.ob(num)
  13.      if num==1
  14.         $mcrarr=['Berka Rules','Go RMXP.org!']#Put objects in here
  15.      elsif num==2
  16.         $mcrhsh={Zeraib=>'Friend'}#Put objects in here
  17.      elsif num==3
  18.         $mcrsng='Regi And Near Are Nice'#Put objects in here
  19.      else
  20.         print 'Macro Error'
  21.      end
  22.   end
  23.   #------------------------------------------------------------
  24.   #Macro/Message (MM)
  25.   #------------------------------------------------------------
  26.   def Macro.msg(msg)
  27.      if msg==1
  28.         print 'Error in Pizza'#Type Message Here
  29.      elsif msg==2
  30.         print 'This Is Macro 1.0'#Type Message Here
  31.      elsif msg==3
  32.         print 'The Great Red Fox Jumped Over The Lazy Dog'#Type Message Here
  33.      end
  34.   end
  35. end
Expand to see the code.

To Call Object 3 Do This
  1. Macro.ob(3)
Expand to see the code.

To Call Message 3 Do This
  1. Macro.msg(3)
Expand to see the code.
So let me get this right, say, for example....

I make an array which I will be using multiple times, I can write it into Macro.obj as object 1, and have like;

Array = [1, 2, 3, 4, 5...]

So everytime I want to call this array, I just use;

Macro.obj(1)

Am I right in thinking this ? Cause if so, that could become pretty handy for the large scale scripters, I mean, I'm still in the process of learning most of the scripting functions etc, but this seems like it could be really handy.
Yes You Are
And Thank You
Well, that's not really a tool script, it's more likely an advice on how to script things, and I must say that doing "Macro.ob(id)" is not much useful as it hasn't a intuitive name. But that's just my personal opinion, keep scripting
Also, I noticed an error in:
  1.    if $Cache=[]
  2.       print 'Macro/Cache Error'
Expand to see the code.

It should be $Cache==[] or $Cache.empty?.
pretty useless script except for the learning process of conditional statement...

as Berka said, you can do that with constants, it's much simpler, and flexible as well...
if i got an object I use a lot
i create a constant in the main scope or maybe a special module storing all of my constants...none the less, those constant are accessible from everywhere without being global variables ( brr global = bad )

A constant holding an object doesn't mean the object can't change its state, it means the constant can't change the reference to the object it's holding.
~~~~~~~~~~~~~~~~~~~~
Content_Deleted
~~~~~~~~~~~~~~~~~~~~
It should be noted that constants in Ruby are not really constants.

Why do you create the extra methods for nil?
You can do stuff like nil.ob(2) and nil.msg(1).

Why do you set both Macro and Che to nil?

Why have you decided that you must use nil.che before you can use the $Cache?

*hugs*
Zeriab, why are speaking of nil? self isn't nil by default, it's "main" , an instance of the object class.
( i suggest you do : p self, self.class in irb or in the script editor )

About constants, they are constant to the reference of the value they hold, but ruby is also too nice with the user by only sending a warning when a constant's reference is changed.

Let's say, i got a constant "my fruit" which has "a value" of "an apple",
after some time my apple rot, and my apple's state has changed, but my fruit is still that same apple.
Because self is nil in RMXP at the start of the script editor. (Strange, I know)
In RMVX you are right about it being main, I hadn't checked VX before.
aah and I hadn't checked in XP lol! :haha:
Development has continued!
:huh:

  1. module System
  2.   class Macro
  3.     begin
Expand to see the code.


Why begin? And why is Macro a class? And why is Macro a class with the System module?

------------------------------

  1.         if num==1
  2.            return mcrarr=[]#Put objects in here
  3.         elsif num==2
  4.            return mcrhsh={}#Put objects in here
  5.         elsif num==3
  6.            return mcrsng=''#Put objects in here
  7.         else
  8.            print 'Exerption:BAD DATA(Please rant about this to'+User+",(Type:Out of bounds args)"
  9.         end
Expand to see the code.


Read about case statements.
  1.  
  2. case object
  3. when 1
  4.   # do something
  5. when 2
  6.   # do something
Expand to see the code.


And why would you assign returned values to local variables?
return mcrarr=[]

You can more effectively just return the array

------------------------------------

  1. #       def self.msg(msg)
  2. #         if msg==1
  3. #            print ''#Type Message Here
  4. #         elsif msg==2
  5. #            print ''#Type Message Here
  6. #         elsif msg==3
  7. #            print ''#Type Message Here
  8. #        else
  9. #          pprint 'Exerption:BAD DATA(Please rant about this to'+User+",(Type:Out of bounds args)"
  10. #         end
  11. #      end
Expand to see the code.


pprint is a syntax error.
and how often is
- System::Macro.msg(n)
going to be any easier than
- p 'message'

It would just be easier to throw together (I guess) a hash constant with id and strings instead:
  1.  
  2. module Whatever
  3.   Msg = {
  4.     1 => 'some string',
  5.     2 => 'some string',
  6.     #...
  7.   }
Expand to see the code.


And then just p Whatever::Msg, as with here, you aren't calling a function and returning an object after passing through an expression. You are just return an object defined in a constant.

-------------------------------------

  1.      def self.Che
  2.         $Cache=[]
  3.         def Che.del
  4.            $Cache=nil
  5.         end
  6.         def Che.clr
  7.            if $Cache==[]
  8.               print 'Exerption:BAD DATA(Please rant about this to'+User+",(Type:Object Empty)"
  9.            else
  10.               $Cache=[]
  11.            end
  12.         end
  13.       end
Expand to see the code.


defining a global variable within a method, then defining 2 methods within a method? :huh: Why print that annoying message if your $Cache is an empty array? Why not just stop method processing?

---------------------------------

You would never need to "include System" unless you wanted your "Macro" class included within a class or module (redundant). At very best, you would include module methods within a class (mixins).

-----------------------------

I understand what you are going for, however, this is more of a "concept" that people could include in their projects to perform various often called functions and stuff, but would always be better suited for a specific module (IE: creating a method to check something such as distance between points, in the Math module).
This Project will be merged with the Easy Development Kit Tablet (EDK:Tablet)

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=65084