Welcome Guest ( Log In | Register )

[ Big| Medium| Small] -



Post new topic Reply to topic  [ 312 posts ]  Go to page 1, 2, 3, 4, 5 ... 11  Next
    SephirothSpawn
  Wed Nov 28, 2007 7:53 am
Support/RGSS Bitch
User avatar
Retired Staff


Location: Kansas City, Mo
Everyone wants to learn to script, but no one really knows where to start. In my honest opinion, the best place to learn is just by reading the default scripts. I learned to script with the japanese RMXP, so I didn't have English comments at my disposal, so everyone of the new generation has that upperhand. Anyways, what I think the best thing to do to learn to script is read the default scripts, and understand each line.

So what I am offering here is support for anyone trying to learn to script. If there is a line of code you don't understand, ask me here. If there is something you want to know, like where in the script editor does something happen, ask here.
  • Ask about a certain line of code : What it means, does, etc.
  • Ask where the coding is for a certain function
PLEASE DO NOT ASK SOMETHING OTHER THAN EXISTING CODE, OR WHERE IN THE DEFAULT SCRIPTS TO FIND A CERTAIN BLOCK OF CODE. Your post will be deleted.

This is a Trial and Error topic. Hopefully, it can lead to more a use full FAQ for beginners.

_________________
I want to review your script!
I am always looking for scripts to look over and offer my advice on people's coding. If you want your script reviewed and to further develop your scripting skills, just put a [Review] tag in your topic. I will always post in any scripting topic marked [Review] offering whatever advice I can give.

Image


Top Top
Profile      
 

    The Sea King
  Thu Nov 29, 2007 6:33 am
Member

ok...so could we start with something easy?


Top Top
Profile      
 

    SephirothSpawn
  Thu Nov 29, 2007 7:21 am
Support/RGSS Bitch
User avatar
Retired Staff


Location: Kansas City, Mo
Ok. Let me give you an example of what to ask here:

Example Question A


Actual Help Request Thread


Example where question

_________________
I want to review your script!
I am always looking for scripts to look over and offer my advice on people's coding. If you want your script reviewed and to further develop your scripting skills, just put a [Review] tag in your topic. I will always post in any scripting topic marked [Review] offering whatever advice I can give.

Image


Last edited by SephirothSpawn on Thu Nov 29, 2007 7:43 am, edited 1 time in total.

Top Top
Profile      
 

    The Sea King
  Thu Nov 29, 2007 4:27 pm
Member

Question.
Do we have to start everything by:
def ....

and then end it?


Top Top
Profile      
 

    SephirothSpawn
  Thu Nov 29, 2007 11:36 pm
Support/RGSS Bitch
User avatar
Retired Staff


Location: Kansas City, Mo
The Sea King wrote:
Question.
Do we have to start everything by:
def ....

and then end it?


Ok. In Ruby, we have quite a few keywords, that all mean something. The keyword def declares a method (A function, query or attribute of an Object). Its structured in the following manner:
[php]
def your_method_name
# your code here
end[/php]

You must have an end to end your methods. Certain keywords require the end keyword. This is why tabbing is so important: So you can keep the right number of end's.
[php]
def your_method_name
if some_boolean
case something
when x
unless z > 0
do_something
else
do_something_else
end
when y
do_something_different
end
else
do_something_crazy
end
end[/php]

This is an example of how you should tab your programming.

_________________
I want to review your script!
I am always looking for scripts to look over and offer my advice on people's coding. If you want your script reviewed and to further develop your scripting skills, just put a [Review] tag in your topic. I will always post in any scripting topic marked [Review] offering whatever advice I can give.

Image


Top Top
Profile      
 

    Sailerius
  Tue Dec 04, 2007 1:04 am
Golden Sorcerer
User avatar
Sponsor

Where are values such as an actor's level and exp stored? Basically, what I'm trying to do is create another value (skills like in D&D) which can be read in message boxes.

_________________


Top Top
Profile      
 

    SephirothSpawn
  Tue Dec 04, 2007 3:27 am
Support/RGSS Bitch
User avatar
Retired Staff


Location: Kansas City, Mo
Sailerius wrote:
Where are values such as an actor's level and exp stored? Basically, what I'm trying to do is create another value (skills like in D&D) which can be read in message boxes.


The quick answer:
Expand to see the code.


Actor data is stored in a "wrapper hash/array class", $game_actors. Now, each object in this class is a Game_Actor object. Each Game_Actor class has the two instances, @level, and @exp, both are readable.

So, here's the important parts.

Game_Actors:
Expand to see the code.


So, everytime you access $game_actors#[], it either creates an actor and adds to the @data array as a new actor (at it's initial state), or returns the Game_Actor object in the @data array.

Then in Game_Actor, you can see:
Expand to see the code.


Here, you can see that the level and exp are readable in Game_Actor objects.

So, to get our actor data, we use:
Expand to see the code.


From there, we just need to read our level and exp.
Expand to see the code.





So, you are wanting to have this shown in Messages? Just use:
Expand to see the code.


Then just use the \v command.

_________________
I want to review your script!
I am always looking for scripts to look over and offer my advice on people's coding. If you want your script reviewed and to further develop your scripting skills, just put a [Review] tag in your topic. I will always post in any scripting topic marked [Review] offering whatever advice I can give.

Image


Top Top
Profile      
 

    Sailerius
  Tue Dec 04, 2007 4:28 am
Golden Sorcerer
User avatar
Sponsor

Thank you for the speedy and most informative reply. :) That answers my question.

_________________


Top Top
Profile      
 

    kyonides
  Tue Dec 04, 2007 5:03 am
Member

where are the slide in windows methods stored in the sdk version 2.3?

Slide in windows = windows that aren't just shown on screen at once but are moved from beyond the borders of the screen to a specific point on the screen like x = 100, y = 0.


Top Top
Profile      
 

    SephirothSpawn
  Tue Dec 04, 2007 5:20 am
Support/RGSS Bitch
User avatar
Retired Staff


Location: Kansas City, Mo
That's Trickster's Movable Module, in the MACL 2.1. Not really what this thread is for, but I am a nice guy. I won't get into details, but will tell you how to use it:

If you use the MACL 2.1+, for any window/sprite, call out:
Expand to see the code.

_________________
I want to review your script!
I am always looking for scripts to look over and offer my advice on people's coding. If you want your script reviewed and to further develop your scripting skills, just put a [Review] tag in your topic. I will always post in any scripting topic marked [Review] offering whatever advice I can give.

Image


Top Top
Profile      
 

    Tassadar
  Wed Dec 05, 2007 4:52 pm
User avatar
Member


Location: Netherlands
Where is the opacity for an event stored? That's a question that has been bothering me for some time, but didn't think of asking :D

_________________
Image

http://tassadaradun.deviantart.com/


Top Top
Profile      
 

    SephirothSpawn
  Wed Dec 05, 2007 5:03 pm
Support/RGSS Bitch
User avatar
Retired Staff


Location: Kansas City, Mo
Quote:
Where is the opacity for an event stored? That's a question that has been bothering me for some time, but didn't think of asking


Game_Character holds all the data the events. In Game_Character, there is an instance call @opacity. Sprite_Character reads this instance, and sets the sprite's opacity according to this value.

So if you wanted to change it, add this in Game_Character 1
Expand to see the code.



Then just use:
Expand to see the code.


Sorry for not going in-depth on this explanation. I just woke up and can barely open my eyes. XD

_________________
I want to review your script!
I am always looking for scripts to look over and offer my advice on people's coding. If you want your script reviewed and to further develop your scripting skills, just put a [Review] tag in your topic. I will always post in any scripting topic marked [Review] offering whatever advice I can give.

Image


Top Top
Profile      
 

    Tassadar
  Wed Dec 05, 2007 7:15 pm
User avatar
Member


Location: Netherlands
Great, I get the idea now. But another question arises, this time about loops.

Here is how I've set up the loop:

Expand to see the code.


The idea was to make the loop reduce the opacity with 10 each frame, but instead it instantly reduces it to 0. That wasn't how I had planned it. event_index is the event ID that will be changed.

Could you tell me what's wrong with it, and how to fix it?

Thanks

_________________
Image

http://tassadaradun.deviantart.com/


Last edited by Tassadar on Wed Dec 05, 2007 8:26 pm, edited 1 time in total.

Top Top
Profile      
 

    SephirothSpawn
  Thu Dec 06, 2007 3:24 am
Support/RGSS Bitch
User avatar
Retired Staff


Location: Kansas City, Mo
The thing is, it never breaks.

Your main problem is: if @n = 25

In boolean-expressions, you need to have the == operator.
Expand to see the code.


That's how I would do it.

_________________
I want to review your script!
I am always looking for scripts to look over and offer my advice on people's coding. If you want your script reviewed and to further develop your scripting skills, just put a [Review] tag in your topic. I will always post in any scripting topic marked [Review] offering whatever advice I can give.

Image


Top Top
Profile      
 

    Leonardo
  Fri Dec 07, 2007 1:14 am
Member

If I may, I'd like to ask a... "void-question".
It's just something the Translated RMXP Help File didn't explained very clearly for me:

What's the real function of the return?


Top Top
Profile      
 

    SephirothSpawn
  Fri Dec 07, 2007 1:22 am
Support/RGSS Bitch
User avatar
Retired Staff


Location: Kansas City, Mo
Quote:
If I may, I'd like to ask a... "void-question".
It's just something the Translated RMXP Help File didn't explained very clearly for me:

What's the real function of the return?



Return does a few things.

In query methods in object classes, return returns a value when a method is called. Like so:
Expand to see the code.


We sometime use it to stop a block of code as well.
Expand to see the code.


When they gold value in $game_party is the same as the @gold instance in that class, the method is returned, and nothing after the return is executed.

_________________
I want to review your script!
I am always looking for scripts to look over and offer my advice on people's coding. If you want your script reviewed and to further develop your scripting skills, just put a [Review] tag in your topic. I will always post in any scripting topic marked [Review] offering whatever advice I can give.

Image


Last edited by SephirothSpawn on Fri Dec 07, 2007 3:39 am, edited 1 time in total.

Top Top
Profile      
 

    kyonides
  Fri Dec 07, 2007 3:29 am
Member

return? mmm... it seems to let you get a result. When I use it as part of a def method inside an Interpreter class, it allows me to get a result, in this case it changes an expression I selected with a script call that lets me start a specific process defined in certain script(s). Does it have any other function?

This is something that confuses me a lot.
what is the difference between alias_method and just alias? How could anyone use them properly?
Expand to see the code.


Top Top
Profile      
 

    SephirothSpawn
  Fri Dec 07, 2007 3:48 am
Support/RGSS Bitch
User avatar
Retired Staff


Location: Kansas City, Mo
Like I said, return returns a value, or ends a block (or big block, like a method call).

Quote:
what is the difference between alias_method and just alias? How could anyone use them properly?


Nothing, sorta.

alias is embedded into Ruby library. It's a hidden method we can never really get access to. However, alias_method is a method in the Module class. It probably looks just like this:
Expand to see the code.


However, I use it in all my scripts because I program with and for the SDK. The SDK has a log_alias method, that logs aliases. So we in the SDK, aliased the alias method, to call this SDK.log_alias method whenever the alias_method method was called. So instead of:
Expand to see the code.

We just use the alias_method like you see above. We log aliases in the SDK to check for script conflicts, in the event a script over-writes a method. It took me a while, but I got it to work if you overwrote a method that was essential to another script, an error was raised.

Another reason is stack errors. Thanks to the wonderful F12, stack errors happen a lot in aliases, so once again, in the SDK, we used the alias_method to check and prevent stack errors.

_________________
I want to review your script!
I am always looking for scripts to look over and offer my advice on people's coding. If you want your script reviewed and to further develop your scripting skills, just put a [Review] tag in your topic. I will always post in any scripting topic marked [Review] offering whatever advice I can give.

Image


Top Top
Profile      
 

    kyonides
  Fri Dec 07, 2007 3:59 am
Member

so you're trying to avoid any of those stack too deep error messages... Interesting. Thanks, Seph.


Top Top
Profile      
 

    Leonardo
  Wed Dec 12, 2007 12:18 pm
Member

Quote:
We sometime use it to stop a block of code as well.
Expand to see the code.


When they gold value in $game_party is the same as the @gold instance in that class, the method is returned, and nothing after the return is executed.

Eah.. That was my doubt. :D
I was concerned especially about the alone returns.

So this, basically means:
"If the variable gold is equal to the party gold, stop the things here. If it is not, make the variable gold be the same as party gold.", right?

Thanks, thing I got it. :3


Top Top
Profile      
 

    Zeriab
  Thu Dec 13, 2007 12:06 am
Hugging Lion
User avatar
Sponsor

Expand to see the code.


Every method returns and object when called or nil.
nil can be considered as the empty return or that nothing is return.

The difference between return and return nil is on the conceptual level.
Usually you use return nil when a value is expected from the method and return when a value is not expected.

To give you an idea of every method call returns an object or nil can be illustrated by the p method:
Expand to see the code.


Try it out ^^

*hugs*
- Zeriab

_________________
Image
Image
Image
Image
Image


Top Top
Profile      
 

    Charlie Fleed
  Thu Dec 13, 2007 11:11 pm
Survivor of Planet Fleed
User avatar
Member


Location: Italy
Where do I find the exact definition of the objects created in the database and loaded in Scene_Title?
Expand to see the code.


many of them I have already figured out by their use, but is there some documentation about them? $data_actors for example...
thanks

_________________
Image Image Image Image Image Image


Last edited by Charlie Fleed on Thu Dec 13, 2007 11:14 pm, edited 1 time in total.

Top Top
Profile      
 

    SephirothSpawn
  Fri Dec 14, 2007 1:35 am
Support/RGSS Bitch
User avatar
Retired Staff


Location: Kansas City, Mo
The editor itself saves the objects whenever you save your project to the rxdata files. It automatically dumps all the objects you set in the database editor into your rxdata files, as well as all the map data files from the map editor.

If you check the help file, under RPGXP-DataStructure, you can see all these classes instances. Basically, all the Data_Objects are a simple:
Expand to see the code.


To be honest, there isn't even an initialize method (well, there is, but we can't see or, or modify it).

They are basically just simple instance-holding objects. Whatever you set in the database is what is held in these instances for each object.

All else fails, just use:
Expand to see the code.


That will show you all the instance methods, granted, some will be from the higher level classes in there as well.

_________________
I want to review your script!
I am always looking for scripts to look over and offer my advice on people's coding. If you want your script reviewed and to further develop your scripting skills, just put a [Review] tag in your topic. I will always post in any scripting topic marked [Review] offering whatever advice I can give.

Image


Top Top
Profile      
 

    Zeriab
  Fri Dec 14, 2007 8:31 am
Hugging Lion
User avatar
Sponsor

There is an initialize method. If you look at the Data_Objects in the help-file you can see their initialize method. You can also change it.
It doesn't really serve much purpose unless you intend to create new Data_Object since the initialize method is by default not called on any of the data objects.

_________________
Image
Image
Image
Image
Image


Top Top
Profile      
 

    The Good King
  Mon Dec 17, 2007 1:22 am
Member

nevermind :)


Last edited by The Good King on Mon Dec 17, 2007 6:08 am, edited 1 time in total.

Top Top
Profile      
 

    Leonardo
  Sat Dec 22, 2007 5:48 am
Member

Ahh.. Things are getting bad. Looks like all I try to make ends with an error. :(

Okay, let me try to ask here...
I am trying to fix a incomplete script made I asked OS. But also modifing the way it works. Whatever... Giving details of what I want to do won't help now.


I just want to know what's wrong with these lines:
Content Hidden

The game crashes even before it initialize, pointing an error on the line "target = sprite.new".

Oh, as my knowledge on scripts is really taaaaaad, let I explain what I think I'm doing there. :P
I'm trying to make these lines mean:
If @jump_image is true
create an image(target)
else case
  delete the image(target)


If posting the full script at the moment helps, here it is:
Content Hidden


Last edited by Leonardo on Sat Dec 22, 2007 5:51 am, edited 1 time in total.

Top Top
Profile      
 

    XDarknessBoyX
  Sun Dec 23, 2007 11:54 am
Member

what does $ stand for?
and wat # stand for?


Top Top
Profile      
 

    khmp
  Mon Dec 24, 2007 3:14 am
The glass is helpful.
User avatar
Sponsor


Location: Haddonfield, NJ
XDarknessBoyX wrote:
what does $ stand for?
and wat # stand for?


$ is the prefix to a Ruby global variable. Global variables can be accessed from anywhere within the program.
# is the precursor to a Ruby comment. A comment is a piece of code that is effectively skipped by the compiler. It's used to help the one reading the code better understand what the code is trying to accomplish.

Expand to see the code.


I have a question about RGSS though. If I have a sprite and I initialize it's bitmap. Does calling sprite.dispose also dispose of the bitmap contained within the sprite. Or do I still have to call sprite.bitmap.dispose then sprite.dispose?

_________________


Last edited by khmp on Mon Dec 24, 2007 3:17 am, edited 1 time in total.

Top Top
Profile      
 

    Zeriab
  Mon Dec 24, 2007 2:35 pm
Hugging Lion
User avatar
Sponsor

It is relatively simple to find out khmp. Simply do something like this:
Expand to see the code.


That code will answer your question and the answer is that sprite.dispose does not dispose its bitmap.
This is useful if you want several sprites to have the same bitmap.

_________________
Image
Image
Image
Image
Image


Top Top
Profile      
 

    khmp
  Mon Dec 24, 2007 7:44 pm
The glass is helpful.
User avatar
Sponsor


Location: Haddonfield, NJ
Thanks Zeriab, I tried making a test like that checking for nil status. I guess they weren't being set to nil after disposal. :)

_________________


Top Top
Profile      
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 312 posts ]  Go to page 1, 2, 3, 4, 5 ... 11  Next


Who is online

Users browsing this forum: No users and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

We are an independent, not-for-profit game making community.
Homepage
Board Index
About Us
Downloadable Games
Free Browser Games
Games in Development
RPG Maker Support
Game Maker Support
Construct 2 Support
HBGames the eZine
Advanced RPG Maker
Site Announcements
Powered by phpBB © phpBB Group