Jump to content
Zen Blood

-Looking for Scripting Terms and Definitions!-

Recommended Posts

Good day/evening, everyone.


 


So recently, I finally mustard up the patience to learn how to make scripts from scratch. It's nice to feel like soon I won't have to rely on everyone to make me/help me with scripts anymore! :D 


However, I'm not a very math-y person, so scripting doesn't seem like it'll be too kind to me.


 


One of the things I need right now is someone to shine some light on the terms used in a script (Ex: .new)


 


I've been watching many tutorials on making scripts, but a lot of people tend to just tell you what code they type in--Not why they type that specific code in.  <_<  I just can't learn that way, and probably a lot of people could say the same.


 


So, if anyone has the time, please explain (or link to a tutorial) to me what these scripting terms do and when you would use them:


 


.new


Marshal 


Marshal.dump


Marshal.load


return


$imported


.nil (or is it .nil?)


self


activate


@


if (most likely self-explanatory, but what do I know?)


 


These should really help me get find some ground with Ruby and be able to start scripting things other than picture-less windows with text in them. I could probably look up all these terms separately, but...It's nice to have everything on one page and explained by the same person (or people with like-minds) ^^;


 


Also, if anyone could tell me how to close a custom Scene/Window with the ESC button, that would be great!


(I can't find anything about that anywhere, it's crazy...)


 


Thank you so much for your time!


Share this post


Link to post
Share on other sites

.new

Just initialized the class that you put it on.

Ex: @characters = My_Characters.new
Assuming My_Characters is actually a class, this would put it inside the variable @characters

 

Marshal /Marshal.dump/Marshal.load

I honestly don't really know, never looked into them much.  But I think Marshal is a module that deals with reading and writing into a file.  Marshal.dump() writes into a file and Marshal.load() opens the files.  I don't recall what the parameters are for them.

 

Return

Commonly used at the end of a method in different scripting languages, but ruby does it automatically.  You can also think of it as the actual meaning "Go back", so whenever a method goes to the return, it stops there and goes back to where ever called it.  Returns are useful in methods that you only want it to process if something is true or false. Ex:

def something?
  return false if !@something
  p "variable something was not false so method test ran."
  return true
end


@something = true
p something?p is used to print to the console, can also use puts and print

 

$imported

Think this is just something rgss scripters made.  It's a global variable that's used as a hash, which can help with compatibility with other scripters scripts.  You'll usually see something like "$imported['ScriptName'] = true" or something inside a script.  You can also use it to make it so a script can only work if another script exists like:

if $imported["ScriptThatIsNeededToRun"]
 -Your script here-
else
 -some error msg-
end

.nil?

Just tests if that object is nil. if it is, it returns true, if it's not it returns false. ex:

@test2 = "a String"

p @test.nil?   # returns true
p @test2.nil?  # returns false because @test2 was made above

self

It refers to the current class it's in.  Not really sure how to better explain this.

 

activate

Think it's primary used for selectable windows.  If they are active that means you can move the cursor around and select options, but if it's deactive then you can't.  Which is useful when you have 2+ selectable windows since you don't want them to all be running at the same time.

 

@

an instance variable, again, not sure how to better explain this.

 

if

if (statement)
 # some code to run if the top statement was true
elsif (statement)
 # some code to run if the elsif statement was true AND the top if statement was false
else
 # some code to run if everything else was false/nothing else ran
end

There's also ternary operator, which is like a shorthand if / else statement that's commonly used:

# ternary = (statement) ? (when it's true) : (when it's false)
@somevariable = 1 > 2 ? "1 is greater then 2" : "1 is less then 2"
# this would set @somevariable to "1 is less then 2"

A quick Scene

 

 

class Our_Scene < Scene_Base
  #--------------------------------------------------------------------------
  # * Start Processing
  #--------------------------------------------------------------------------
  def start
    super           # Calls the parents method for start
    create_window   # Calls the method we made below
  end
  #--------------------------------------------------------------------------
  # * Create Window
  #--------------------------------------------------------------------------
  def create_window
    @window = Window_Base.new(0, 0, 200, 200)
    # Creates a new window initialized to (0, 0, 200, 200)
    # If you look at Window_Base initialize you'll see it like:
    # initialize(x, y, width, height)
  end
  #--------------------------------------------------------------------------
  # * Update
  #--------------------------------------------------------------------------
  def update
    super      # Calls the parents method for update
    if Input.trigger?(:  # If cancle was pushed
      return_scene    # Go back to previous scene, this method is from the parent
    end
  end
end 

To call a scene in vxa you usually use "SceneManager.call(SceneName)" so in this case it would be "SceneManager.call(Our_Scene)" without quotation marks.

Now you normally wouldn't do Window_Base.new(parameters), because you would normally make your own window instead and just use that instead so like

@window = Test_Window.new

 

 

Edited by Quasi
  • Like 1

Share this post


Link to post
Share on other sites

.new

Create the object from the class. Class is just a blueprint, and when you call .new, you just create the object based on the class. At least that is the analogy

 

Marshal

I rarely use marshal actually. I guess, Quasi have explained it well...

 

Return

commonly used to returning the value after some operations. IRL example, it could be printer. You put the documents as an argument / parameter, and after some process, the return value is printed document.

 

In another case, return can be used to break down the method. If you don't want to run entire method, just put return in the middle of the method.

 

$imported

A standard global hash that used for RPG Maker scripters. It's commonly used to register the script and tell that certain script is exist on the project.

Why it's important? It can be used to make compatibility patch among various script. Like... if this script is exist, then do this, else, do that.

 

.nil?

Just check if the variable is nil.

Why is this important?

Some operation might return a nilClass, an object that doesn't have anything. Then you should check the variable if it's nil or not. So you can make an exception to avoid error "undefined method for nilClass" or such.

 

self

Refers to itself. Usually to access its object's properties and methods. It's pretty hard to explain. But here is the case where do you need to use self

class Something
  
  def text
    return 'Text from class'
  end

  def print(text)
    puts text
    puts self.text
  end

end

a = Something.new
a.print('Text from parameter')

activate

it's Window_Selectable stuff to activate the window. When the window is activated, you can move the cursor. If two windows are activated at same time, you can move both cursor.

 

@

Instance variables that can only accessed on the class where it existed. It's to handle class attribute, like HP for actor. Yes, Actor has HP and it saved in instance variable using @hp. Another object doesn't have @hp because it's only can be accessed on actor.

 

If

Basically just same as conditional branch in event editor

 

Making scene is pretty complex for beginner, or at least I failed many times back then. Try to understand default script at first, how they works, and you might understand later.

  • Like 1

Share this post


Link to post
Share on other sites

Try reading this. It has cartoon foxes!

 

Also: Related to anything with a period: Anything that uses a period like x.y means to use method y on object x. Methods are basically a list of things you can do with an object, and objects are things that you can work with. This even includes .new which tells a class to make a new object (or instance) using that class. Really a lot of scripting is telling objects to do things in different ways or overwriting how an object does something through it's class. I think it might be easier to understand that way sometimes.

 

Also Also: if you want info about Marshal, look here, but it isn't really that useful for most people.

Edited by KilloZapit
  • Like 2

Share this post


Link to post
Share on other sites

...

 

 

...

 

 

...

 

Thank you, everyone, for your responses! Having these terms explained to me really helped a lot :)

 

Thank you for sending me that cartoon, KilloZapit. I don't think I ever would've found it by myself,  :P  and it's very entertaining.

Share this post


Link to post
Share on other sites

Good luck! *sprinkles some fairy dust on you* I hope you manage to get your head around scripting and the Ruby language it uses... I kinda think it's neato!

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.

  • Recently Browsing   0 members

    No registered users viewing this page.

×
Top ArrowTop Arrow Highlighted