I'm starting scripting ^^

Started by element, September 11, 2010, 05:06:26 am

Previous topic - Next topic

element

Hi all,

Today, I'd like to start trying to script.
Cuz I'm making a game that'll have a lot of scripts that still need to be made.
I read some articles online how to script RGSS, I might need to re-read them cuz I don't really know how to start.
That's why I ask you all how u started scripting RGSS, or started scripting at all.
RGSS/Ruby would be my first scripting language I learn.

I took a goal for me, I'd like to script something that takes track of eneamy levels so that they can be placed later on in a hud. The hud is something to make after this one.

So, what I like to make:
A system that will give something like: Eneamy[ID]'s level == ['45']
Just so I can dislpay the level later on in the Hud, apart from the name.
I think this would be an easy part of code and a good start.

What I ask to you guys:
How did you start scripting? What tutorials did you follow? What did u do next?
And afterwards, how would I need to start making this script?

Thanks In advance for your helps ^^

Blizzard

I started messing around with others' simple scripts. I did edits and watched what happened, what changed in the original workflow of a script. That way I figured out which part did what and quite quickly (later on the same day I actually started) I was able to put together a simple script myself. It was a credits script that would show picture after picture. (Later I upgraded that script to the Picture Movie Scene from Tons.)
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

element

That's a good Idea. I'll start checking out some scripts.

stripe103

That is how I started as well. Though I haven't got as good.
The first thing I ever did with scripting was editing Zeriabs QuestBook.
It turned out quite good as an AchievementsBook. I'm quite happy with it.

Aqua

O.o Why is this in News/Suggestions/Feedback?

littleK123

heelo im new to rpg maker xp i have a friend name joey101 on rpg rpg revoultion
i got rpg maker xp downloaded and i asked him if he can help me out he said hes busy so i should go here and he told me to look for the:
Blizz-ABS but i cant find it can some one help me thank you

Blizzard

http://www.chaos-project.com/index.php?option=com_scriptdatabase&view=scriptdatabase&Itemid=29

Please try searching harder the next time and making use of the search function in the forum (there's a button in the top menu).
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Calintz

Well Element I'm pulling for you man!!
I too will give scripting another chance.

element

I hope we get there  :)
Any other scripters wanna post how they started?
It would help me a lot.

winkio

I had a small programming background, so I just applied that knowledge to RGSS.  I guess reading over Blizz-ABS, understanding it, and then making small modifications to it were the first things I did, two years ago.

Ryex

well I started like most every one else said, by reading a script i wanted to edit and trying to under stand it. eventually I decided that I would learn more by making my own so I made the "collapsed" menu (eventually I edited it to be the "collapsing" menu). I also read several ruby tutorials as i was a complete beginner when it came to programing.
the thing about tuts: they can teach you all the syntax in the world, but not a single one of them teaches the jump from knowing syntax to knowing how to apply it. this is where the large learning curve comes in. knowing how to make all those words do what you want is never taught, only what the words mean is.

good luck.
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

Calintz

@Ryexander:
That is the leap I never crossed. Well put.

Ryex

the only way I know of to cross it is to make something and then make something else, getting more complex each time.
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

Calintz

Make something ... then make something else huh?
Well ... I don't even know how to make a CMS. I mean ... I can add additional features and shit, but as far as adding original items like sprite animations of things that would actually make a CMS cool ... nope.

Ryex

thats where I started. :P
I also asked a lot of questions when i went to build something beyond my ability. this place is very friendly to budding scripters
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

element

Becouse probably i'm only going to make graphical scripts and stuff, i'm going to try to dislpay a picture, and dislplay text in it. Should be easy hm?

Blizzard

Put the gold window on the map for training. Through that process you should learn how scenes and windows are organized.

Gah, I still need to make my guide "How to learn scripting in X steps".
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Ryex

if some one ever makes a guide that allows people to make that leap between knowledge and application I will be very happy.
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

element

September 12, 2010, 05:25:18 am #18 Last Edit: September 12, 2010, 06:06:50 am by element
I second what ryex said  :D


EDIT : Ok so I tried to write something that shows a picture on the map.
Most simple thing there is I think. I wrote a, probably shitty, piece of code :
##################################################
#                                                #
#              Text on picture test              #
#                                                #
##################################################

class Text_test
 
  ##############################
  #   Draw Text and picture    #
  ##############################
  def initialize
  Bitmap.new(189-Down01)
  Bitmap.new(50, 50)
  dispose
  end
end


How do I call this on the map? How do I make it appear on the map?
What am I doing wrong? What needs to be added?

Please be easy on me cuz I don't really already know what i'm doing.

Ryex

September 12, 2010, 04:26:11 pm #19 Last Edit: September 12, 2010, 05:09:04 pm by Ryexander
well to call it on the map you would edit scene maps main method but as is your code won't work. Bitmaps alone aren't drawn to the screen you need to create a sprite and attach the bitmap to it btw the Bitmap.new(50, 50) create an empty bitmap and won't do anything and the Bitmap.new(189-Down01) won't work because first off it take a string and second the path to the image is wrong
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

element

yeah, i tougth it would make no sense.
Ill start reading some more code tomorrow.

Calintz

Alright, since this is an active thread I'll ask this question here.
What is the importance of knowing real RUBY programming as opposed to RGSS?

@ALL RGSS Scripters on CP:
Would you personally advise learning as much about the father language as possible before beginning with RGSS, or do you believe that connection is unimportant? Do you feel personally that people would be wasting time with RUBY? Is RGSS easy enough to pick up on without a proper understanding of RUBY?

Blizzard

RGSS is not really a language. RGSS is a system that can be used with Ruby. The way the scripts are organized in RMXP is just an internal way of arranging them. When you learn RMXP's Ruby and RGSS, you are learning Ruby anyway. Of course, it will be easier to work with RMXP's scripts if you already know Ruby, but you will still have to figure out how RGSS works.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Ryex

don't bother learning ruby specific programing first in order to use RGSS you need to know its structure and once you have learned RGSS you have learned Ruby
it is the same language RGSS just hase some extra built in classes that are game specific.
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

Calintz

Well alright then.
Thank you guys. I have spent an hour or so just looking at default scripts.

Things are still a blur to me. I get pieces here and there. This is gonna take me forever, and I really don't think I'll get to the point where I can build scripts from the ground up. I think I'll be able to edit at best, Lol.

Blizzard

September 13, 2010, 02:25:06 am #25 Last Edit: September 13, 2010, 02:26:51 am by Blizzard
Right, I said a bunch of things, but actually didn't give a direct answer.
Pretty much what Ryex said. Don't bother with Ruby, go straight for RGSS. You will learn Ruby with RGSS faster that you would be if you first learned some Ruby and then had to learn RGSS again.

Yeah, the default scripts are quite big. Best you take just one of the simpler scripts and try to understand a bit what is going on. Then try to add edits and see what happens. If you understood things right and the changes you made were what you wanted, the right thing should happen and you will figure out something in the scripts. Then you can go from there and keep experimenting.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Calintz

That worked for me in the past, and it seems to be working now. Like, I have made some simple edits to the title screen, and some simple edits to the default menu system and like you said ... the edits are what I want and so pieces of the puzzle are beginning to fall into place, but will this method really take me to the top?

A constant help for me has been the Help Text file in the editor believe it or not.

Ryex

yes it will take you to the top, and yes the help file is awesome. I'm still using it, and will likely keep using it. its not like a person can completely memorize an entire code base.
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

Calintz

September 13, 2010, 02:39:40 am #28 Last Edit: September 13, 2010, 02:40:58 am by Calintz
*points to Blizzard* (with both hands muthaf*****) LMFAO.

At any rate this is good news. Thank you Ryexander.
Continuing to look at default scripts I've realized that the scripts use two main thingy majigs. def initialize and def main.
Am I correct in assuming that def initialize is used when establishes an item's properties, and that def main is used for the declaration of processing of those items?

Blizzard

Exactly. "initialize" is called when you create a new object, a new instance of a class.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

ForeverZer0

Quote from: Ryexander on September 12, 2010, 04:26:11 pm
well to call it on the map you would edit scene maps main method but as is your code won't work. Bitmaps alone aren't drawn to the screen you need to create a sprite and attach the bitmap to it btw the Bitmap.new(50, 50) create an empty bitmap and won't do anything and the Bitmap.new(189-Down01) won't work because first off it take a string and second the path to the image is wrong


You need something like this:

class Test_test

  def initialize
    @sprite = Sprite.new # Sprites display the bitmaps
    @sprite.bitmap = Bitmap.new("FILENAME") # Sets a bitmap to the sprite
    @sprite.x, @sprite.y = X, Y # Sets the location, in pixels, of the sprite on the screen
  end

  # Now the sprite will not update without calling an update method and the game will
  # crash if the sprite is not disposed and called again, but I hope this can at least
  # point you in the right direction.
end
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Ryex

ya def initialize is an inbuilt ruby method that is called when .new is called in order to create the object and "initialize" object data

def main is only uses in scene classes.

a scene class is a class that process a scene and is something you set the $scene object too

it you look at the main script you will notice that that it loops indefinitely and calls $scene.main
a def main method contains another loop that dose updating
first it calls Input.update to update input information form the system and make it available to in game processing
then it calls the scene update method which updates displayed windows, and then it calls Graphics.update which refreshes what is drawn on the screen.
then you will notice that in the loop in the main method there is a condition
if $sceen != self
  break
this means that if $scene has chanced to something that is not the same object that the loop is running it breaks the loop.
you will notice that after the loop there is objects disposed. this makes sure the all the sprites drawn in that scene are disposed so that they don't carry over and stay when the next scene is called.
at this point the code jumps back to the main loop again and calls $scene.main again. so the main method of the new scene is called.

are you starting to understand the flow now?
understanding program flow is key to understanding RGSS
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

Calintz

September 13, 2010, 01:15:39 pm #32 Last Edit: September 13, 2010, 01:18:44 pm by Calintz
That is the answer I was looking for Blizzard. Thank you!
Knowing that def initialize is called when I create a new class will be a much more logical way for me to remember its purpose than simply saying it's used to define the characteristics of a class (even though that's what it's for).

@Ryexander:
This conversation between Blizzard and me was a perfect example of that gap we talked about. I understood that "def initialize" held the base characteristics of a new class by looking at default code, but now knowing that it absolutely needs to be called and defined and when I need to do that helped me cross that gap of application. Now I know how and when to apply that syntax. If that's the case with 'def initialize' ...

@Scripters:
Then the same goes for 'def main' right? If you create a new class then "def main" NEEDS to be defined somewhere after def initialize, right? Because 'def initialize' sets up the new class, but something has to tell those properties what to do? That is what 'def main' is for, right? Well...maybe "def main" doesn't technically tell that class what to do, but it tells all the attributes defined in the new class' 'def initialize' method how to properly process the way you want without failing, right!? That's the purpose of 'def main'?

Then, you take it one step further by creating a new scene.
Calling new scenes is how you actually tell that new class what to do, right appear on screen?

Edit:
@Ryexander:
yea. I really do believe I'm understanding this a bit now. This order...it will always be the same for all new classes and scenes, etc...? Like, it doesn't matter if I'm making a time and climate system that doesn't use graphical enhancements as opposed to a CMS. The process of writing the code needs to be the same, right?

element

Ok I learned Reall ymuch more now.
So now I'll try to make a class that stops the bgm.
Nothing more than that.
I learned that
$Class_name
is used to call a class and
$Class_name.Thing_in_class
is used to call
def Thing_in_class

True?

Also can someone explain me how scripts are built up? and explain some more things like the previous explaination of def initialize, cuz that helped me alot  :D

Blizzard

Pretty much, yeah.

@Calintz: def main is a slightly different concept. Scenes define main as a sort of entry and exit for a main update loop. Other classes don't need a main. In fact, initialize isn't needed either. If it's not defined, it will not be called. So if you have a utility class with no attributes, there is no need to define initialize.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Calintz

September 13, 2010, 02:26:56 pm #35 Last Edit: September 13, 2010, 02:29:11 pm by Calintz
@Blizzard:
I think I understand that concept. By default you are on the map. This is a scene in itself. It contains all of the information needed to play the game, and only updates that information accordingly. Viewing your menu however, has a completely different set of requirements and information of its own, therefore you need to make a transition through those scenes. It's that transition from updating one set of information to a whole new set that requires the 'def main' to be used?

This is why windows don't have a 'def main' right? Their information is established through the 'def initialize' process. That process builds the window itself and its update information, but no actual change from one update to another is required. This is why windows don't have 'def main' in the code, but scenes do? The scenes(which is where 'def main' is used, because of the transition) simply pulls that information by calling it's class. (Scene_Menu.new)

Is that right?

element

Anybody can help me with wat i'm doin wrong.

##################################################
#                                                #
#              stop the bgm test                 #
#                                                #
##################################################

module MUSIC
  def initialize
    @Stopthemusic = false
  end
  class Stop_music
    def music_stop
   
      if @Stopthemusic == true
        $game_system.bgm_stop
      end
    end
  end
end


I'm calling the stop the bgm in an event with : MUSIC.@Stopthemusic = true

It gives me a syntax error that leads me to game_temp first line

Ryex

ya that would fail... for one. @Stopthemusic isn't public, and ya there is just a lot wrong with that.

ok first off modules are completely different than class in terms of what they are user for. think of a module as a static namespace that can't be instanced.
in other words MUSIC.new would raise a NoMethod error. so no def initialize for modules.
modules can contain methods and classes but in order to call a modules method out side the module they have to be defined as
def self.methodname
this format allows a method to be called with out the class (or module) being instanced
def method name can only be called by a method inside the module

take this for example

##################################################
#                                                #
#              stop the bgm test                 #
#                                                #
##################################################

module Music
  class Stop_music
    def self.music_stop
      stop_music_internal
    end
    def stop_music_internal
      $game_system.bgm_stop
    end
  end
  def self.music_stop
    stop_music_internal
  end
  def stop_music_internal
    Stop_music.music_stop
  end
end


Module and Class names MUST be capitalized other wise they are not constants and they can't be called correctly
method names by convention are not capitalized, there is no reason two and it confuses people, also i think it might have some side effects I don't know about.


Music.music_stop  #> stops the music
Music::Stop_music.music_stop  #> stops the music
Music.stop_music_internal  #> NoMethod Error
Music.Stop_music.stop_music_internal  #>  NoMethod Error
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

Blizzard

@Calintz: Yes, you got it. Windows usually have a refresh method that updates the display. That method should only be called when the information has changed because calling it every frame would heavily increase CPU load and it would start to lag. Windows also have an update method that updates other additional information such as user input to move the cursor around (or even constantly checking whether the displayed data has changed so it can be refreshed).

When calling a new scene, you need to use "$scene = Scene_X.new" When the current update loop ends, the current scene will exit and the new scene will be started.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Calintz

September 13, 2010, 04:29:42 pm #39 Last Edit: September 13, 2010, 04:46:15 pm by Calintz
@Element:
We're getting there bud. A step at a time.

@Blizzard:
I've noticed the use of the refresh method in the Gold window, Steps window, and the Playtime window, and so that was my initial thought: The refresh method is used because that information is always changing during gameplay. The Playtime clock even runs during Menu processing.

Actually, because the Playtime clock is always running isn't that why there is an additional 'Frame Update' method in the standard Playtime script? It looks like the code is saying "if the frame count divided by the frame rate changes by the second, then refresh. Either that, or if the frame count divided by the frame rate is no longer equal to the current playtime, then refresh. This is what my brain interprets from that line. Does the '/' even mean divided by in that line, or am I missing something?

Ryex

it says
if the frame rate / the total frame count does not equal the value we have stored for total seconds then refresh
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

Calintz

September 13, 2010, 06:55:18 pm #41 Last Edit: September 13, 2010, 06:56:49 pm by Calintz
Okay ... That makes sense. I've noticed that  !=  is often used to determine whether or not something is changing. So it makes sense that this means it's asking whether or not what you have stored is equal to another value or not. If it isn't, then that itself denotes the change I mentioned. Hence the  !=  .

But still ... what is the purpose of this symbol in the code.  '/'
Is "if the frame rate / the total frame count does not equal the value we have stored for total seconds then refresh"
Equal to assuming this "if the frame rate divided by the total frame count does not equal the value we have stored for total seconds then refresh"

Ryex

ya
/ = divide
* = multiply
** = to the power of
% = divide and return the remainder
+ = add
- = subtract
+= = increment by
-= = deincrement by
*= = return stored value multiplied by
/= = return stored value divided by
there is also
|
&
|=
&=and i think there is a
%=
but i can't really explain those

I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

Calintz

Very nice. Then it looks like I'm on track.
Now a quick question. Can you display a message window through a script call?

Like, not using p "blablabla"
but actually displaying a message window and specify what goes in it?

Ryex

well no, not really. but you can display an internal window.
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

Calintz

Not what I wanted. Thank you!
Another quick one. How do you enable a disabled item? Like scripts check if save is disabled or not because you can change that with events. But if you've added a custom option to the menu and you disable it? How do you enable it again?

Ryex

take a look at the command window's disable item method.
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

Calintz

I can't get anything to work, Lol.

Ryex

remember try to understand the flow of the program
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

Calintz

Well that isn't the problem here.
I'm putting things in the proper place, and using the proper code, but I think in order to succeed I have to go further than I can right now with edits into other scripts. I don't want to ruin anything, so I'll wait for that. It won't stop me from completed this task. It was just an aesthetic. I'll try again in the near future.

Blizzard

You get the number of seconds by dividing the number of frames with the frame rate. So it's saying "If the number of seconds played has changed, refresh".
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Zeriab

September 14, 2010, 03:37:29 am #51 Last Edit: September 14, 2010, 03:44:41 am by Zeriab
Quote from: Ryexander on September 13, 2010, 03:26:55 pm
ya that would fail... for one. @Stopthemusic isn't public, and ya there is just a lot wrong with that.

ok first off modules are completely different than class in terms of what they are user for. think of a module as a static namespace that can't be instanced.
in other words MUSIC.new would raise a NoMethod error. so no def initialize for modules.
modules can contain methods and classes but in order to call a modules method out side the module they have to be defined as
def self.methodname
this format allows a method to be called with out the class (or module) being instanced
def method name can only be called by a method inside the module

take this for example

##################################################
#                                                #
#              stop the bgm test                 #
#                                                #
##################################################

module Music
  class Stop_music
    def self.music_stop
      stop_music_internal
    end
    def stop_music_internal
      $game_system.bgm_stop
    end
  end
  def self.music_stop
    stop_music_internal
  end
  def stop_music_internal
    Stop_music.music_stop
  end
end


Module and Class names MUST be capitalized other wise they are not constants and they can't be called correctly
method names by convention are not capitalized, there is no reason two and it confuses people, also i think it might have some side effects I don't know about.


Music.music_stop  #> stops the music
Music::Stop_music.music_stop  #> stops the music
Music.stop_music_internal  #> NoMethod Error
Music.Stop_music.stop_music_internal  #>  NoMethod Error



I am sorry, but what you write here is not right.
It'll probably be like this:

Music.music_stop  #> NameError
Music::Stop_music.music_stop  #> NameError
Music.stop_music_internal  #> NoMethod Error
Music.Stop_music.stop_music_internal  #>  NoMethod Error


The problem is one of scope. You cannot call instance methods without having a reference to the instance.
You do not have a local variable defined by stop_music_internal and no method by that name either, so you'll probably get a NameError.
You can create an instance of the Stop_music class and call stop_music_internal on that:
      instance = Stop_music.new
      instance.stop_music_internal



Here are some tutorials which you guys have not have seen:
RGSS Graphics for Noobs - Part 1, Tired of being 'the weakest link'?
RGSS Graphics for Noobs - Part 2, Are you gonna eat that?

Links to part 3 and 4 in the next post


*hugs*


Ryex

Woh zeriab. I can testify to that the results I gave, as I have done similar things myself if a method belonging to a module is defined as def self.name then module.name will call that function
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

Zeriab

You misunderstand what the error is. Here is an example which illustrates the problem:

module Foo
  def self.bar
    my_instance_method
  end
  def my_instance_method
    p 'self.bar will not call this'
  end
end

Foo.bar


*hugs*

ForeverZer0

Quote from: Zeriab on September 14, 2010, 08:23:07 am
You misunderstand what the error is. Here is an example which illustrates the problem:

module Foo
  def self.bar
    my_instance_method
  end
  def my_instance_method
    p 'self.bar will not call this'
  end
end

Foo.bar


*hugs*


I think he needs to learn the basics before he leanrs how to use the Singleton principle.  ;)
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Ryex

I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

Zeriab

September 14, 2010, 12:52:12 pm #57 Last Edit: September 14, 2010, 12:54:10 pm by Zeriab
*pats*

@ForeverZer0:
Where do you see that pattern used (or an attempt at applying it) ?_?

Ryex

wow I just researched what a singleton was and realized that I've been doing similar things in my last two big projects! lol :P
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

ForeverZer0

I don't see why you would use that. All that is doing is calling a method that does nothing more than call another. Why not just call the second one to start with? Could that possibly work to call an instance method of the class, but use the Singleton method?
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Blizzard

I didn't really read much of the last posts, but I just wanted to say that I don't like the concept of singleton so much. The concept of a static class (that ultimately behaves the same as a singleton, it is also a module in Ruby) looks a lot cleaner and better organized to me.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Ryex

@Zer0
I mostly did that to give them a picture of how methods inside modules work, personally I'd never do such a thing.
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

Calintz

@Blizzard:
Thank you for further demonstrating the purpose of that line. Now it makes perfect sense, Lol.

Edit:
Thanks to Blizzard and Ryexander. I have been growing little by little as a scripter.

Blizzard

The hardest part is to start off. Once you get things rolling, it's a lot easier to continue on your own.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Calintz

Thank you for the encouragement. I have been working on a DEMO for ojp and Game_Guy's Quest Log system, but as soon as I finish it I will get back to scripting. Thanks to you guys though I have base knowledge and I know that anytime I open the script editor...remember the flow of the language. That is the most important part. If you don't recognize the flow you'll probably start putting code into weird places!!  :naughty: