Ruby/RGSSx questions that don't deserve their own thread

Bonkers

Get ready to be Wowed!
Restaff
Joined
May 26, 2013
Messages
2,941
Reaction score
2,897
First Language
English
Primarily Uses
RMMV
On the default save menu for ace, is there a simple script command I can insert that can make the character(s) step animation instead of just stand there in the window?
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,108
Reaction score
13,713
First Language
English
Primarily Uses
RMMV
No. You would need a script written to animate them.


Do a search - it's possible there's already been one written. The question seems vaguely familiar to me, but not recent.
 

IZUHU

Villager
Member
Joined
Dec 27, 2014
Messages
6
Reaction score
0
Primarily Uses
Ok so I was looking at a video and reading about the Hierarchy of Classes in Ruby. and apparently when classes have the same name and inheritance (disregarding the case of a module being present or not). The lowest class in the script would always take priority. For example,

class MyClass def initialize print "You are now in the initialize method" end def method_one msgbox_p("Hello There") endendclass MyClass def initialize #BLANK end def method_one msgbox_p("Hello There") endendmyclass = MyClass.newmyclass.method_oneThe initialize method in the first MyClass would not run unless I put it under the other MyClass

Why is that ?

I thought computers process things line by line in order unless however, the programmer explicitly states for the computer to jump somewhere else to call another piece of code. Can someone explain this to me ? Is this some kind of "it is what it is" type of thing, like "Why is water wet ?" lol
 
Last edited by a moderator:

Sarlecc

Veteran
Veteran
Joined
Sep 16, 2012
Messages
453
Reaction score
211
First Language
English
Primarily Uses
RMMV
The reason the code is not displaying the print line in the console is because you have overwritten the initialize method.
 
Last edited by a moderator:

IZUHU

Villager
Member
Joined
Dec 27, 2014
Messages
6
Reaction score
0
Primarily Uses
So basically even classes can be overwritten like non-constant variables by typing another class with the same name below them.

I think I got it now. Thank you! ( ◜◡◝)
 

Sarlecc

Veteran
Veteran
Joined
Sep 16, 2012
Messages
453
Reaction score
211
First Language
English
Primarily Uses
RMMV
Basically you can change anything in a class's methods by having a class with the same name below it (you can even add new methods to the class):

Code:
class Testing    def method_one       p "this is method one"    end    def method_two       p "this is method two"    endendclass Testing       # overwrites the entire method one       def method_one          p "goodbye"       end       # adds a new line of code to be executed in method two       alias sar_method_two  method_two       def method_two          sar_method_two          p "this is an added line to method two"       end       #method 3       def method_three          p "this is method 3"       endendt = Testing.newt.method_onet.method_twot.method_three
 
Last edited by a moderator:

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,108
Reaction score
13,713
First Language
English
Primarily Uses
RMMV
I don't think you quite have it IZUHU.


You can define classes in several script slots, and as long as the method names are not duplicated, your resulting class will have ALL the methods you have created - it will be a combination of everything you've done with that class.


The moment you use the same method name, the lowest one overwrites the earlier ones.


To get around this problem, you can alias your methods and call the aliased method from within the new one (as Sarlecc has done with method_two in the example above). That means your method will run what is in the higher script AND what is in the lower script.


This really belongs in Learning Ruby and RGSSx. If you have further questions, please start a new thread there for more detailed discussions and examples.
 

seita

Donn_M
Veteran
Joined
Feb 6, 2013
Messages
2,254
Reaction score
611
First Language
English
Primarily Uses
Not sure if this has already been answered on here, I can't find it.

Can anybody provide a quick way to remove an item from the array and move the rest of the items behind it forward?

For example:

array1 == [1, 3, 5, 9, 11]

remove 5

array1 == [1, 3, 9, 11] (the 5th entry would become nil)

edit: found this, not completely sure how it works (I don't need to return the element)

http://stackoverflow.com/questions/13737768/delete-an-element-from-an-array-based-on-a-condition-block-and-return-that-eleme
 
Last edited by a moderator:

Sixth

Veteran
Veteran
Joined
Jul 4, 2014
Messages
2,162
Reaction score
823
First Language
Hungarian
Primarily Uses
RMVXA
You want it to become nil or remove it altogether?


If you want it to become nil, you can use something like this:

array1[pos] = nilReplace 'pos' with the position you want to set to nil in the array.
This would make your array look like this:


array1 == [1,3,nil,9,11]


You can also remove it completely doing this:

array1.delete_at(pos)This would make your array look like this:
array1 == [1,3,9,11]


But you example is confusing. You are not removing the "5th eelement", you are removing the 3rd one, which got the value of 5. That's an entirely different thing and needs a different method.


Also, there is no nil value in your example array after the operation, so the comment in the brackets makes it even more confusing.


If you want to remove something from an array depending on the value of the things in the array, you can do this:

array1.delete(val)Replace 'val' with the value you want to delete from the array.
This will also remove every element equal to value, not just one. There is a workaround for this thou if you want to remove only one element with the same value at once not all of them.


The array would look like this after:


array1 == [1,3,9,11]


You don't need to use the returned deleted element, your array will be changed like described above, so you can carry on with whatever you want to do with the array.
 

Venka

Veteran
Veteran
Joined
Jun 20, 2012
Messages
945
Reaction score
365
First Language
English
Primarily Uses
you can try it this way if you know the value you want to remove from the array:

array1 = [1, 3, 5, 9, 11] # If setting the array it only takes one = (the double equal compares the two sides)array1.delete(5)or this way if you don't know the value, but you know the position it holds in the array:

array1 = [1, 3, 5, 9, 11]array1.delete_at(2)2 is the 3rd spot in the array since arrays always start their counter at 0

edit: adding in a link for some more info on the arrays here. This site has tons of great info for coding and easier to understand examples (compared to other coding sites).
 
Last edited by a moderator:

Solistra

Veteran
Veteran
Joined
Aug 15, 2012
Messages
593
Reaction score
247
Primarily Uses
For use on a case-by-case basis:

Code:
# Remove all `5` elements.a = [1, 3, 5, 9, 11, 5]a.delete(5) # => [1, 3, 9, 11]# Remove only the first `5` element.a = [1, 3, 5, 9, 11, 5](i = a.index(5)) && a.tap { a.delete_at(i) } # => [1, 3, 9, 11, 5]
Considering how useful the functionality is, you could also define a method to do this for you. Personally, I'd recommend creating a new module and extending it into instances of arrays as-needed, like so:

Code:
# Note that we're defining the method in its own module; this is mostly so that# we don't pollute the actual `Array` class and instead extend the module into# the `Array` instances that will need to make use of it.# # Obviously, you could also define this method in the general `Array` class and# have it globally available -- it's just a bit more polite not to do so unless# necessary.module ArrayExtensions  # Removes only the first given element from the array, shifting all other  # elements. Returns the modified array.  def delete_first(element)    delete_at(index(element)) if include?(element)    self  endenda = [1, 3, 5, 9, 11, 5].extend(ArrayExtensions)a.delete_first(5) # => [1, 3, 9, 11, 5]
 
Last edited by a moderator:

Sixth

Veteran
Veteran
Joined
Jul 4, 2014
Messages
2,162
Reaction score
823
First Language
Hungarian
Primarily Uses
RMVXA
I forgot to ask my question before...


Is there any documentation on the hidden class "Window"?


I want to see the whole class with all the methods in it and how they operates exactly, but no matter how I try to search for it, I end up with dead links and other posts asking about the same thing.


There must be a way to see that class, because I have seen some custom scripts modifying it. I guess the author of those scripts found the documentation on it or he/she was born with the knowledge, right? :D


Anyone got any working link for it, pretty please? *-*
 

Another Fen

Veteran
Veteran
Joined
Jan 23, 2013
Messages
565
Reaction score
276
First Language
German
Primarily Uses
You can refer to the makers manual. You'll find it by pressing 'F1' or looking at 'Help' -> 'Contents' while on the map editor view.
 
 
Last edited by a moderator:

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,108
Reaction score
13,713
First Language
English
Primarily Uses
RMMV
@Sixth, try this:

Code:
p Window.public_methods
 

Sixth

Veteran
Veteran
Joined
Jul 4, 2014
Messages
2,162
Reaction score
823
First Language
Hungarian
Primarily Uses
RMVXA
Unfortunately, the help files do not include the whole class, only it's methods.


While that call returns the name of the methods, it still won't show me the whole definition of those methods. I want to be able to see the whole class as is, just like I can see any other in the editor.


I found it for RPG Maker XP, which was helpful, to say the least, but it seems that it is different from VX Ace, because some methods return NoMethod errors, which means it is either completely different or got a different name.


Anyway, with looking at the hidden Window class in RPG Maker XP, I managed to create what I want, so it is not so important anymore, but it would still be useful to see the full class for VXAce.


I found a dead link posted by Tsukihime on a forum to it. I can only hope that Tsuki or someone else saved that documentation for themselves, and that they can share it here.
 

Another Fen

Veteran
Veteran
Joined
Jan 23, 2013
Messages
565
Reaction score
276
First Language
German
Primarily Uses
Some of the hidden classes are closed source and not even written in ruby, so you are only provided the methods. You can still make a lot of changes to them by using alias.

*however, not sure if I got you correctly*
 
Last edited by a moderator:

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,108
Reaction score
13,713
First Language
English
Primarily Uses
RMMV
The only way (that I am aware) you will get the whole definition of the classes is by reverse engineering the engine, which breaks the EULA. The best you can get is the names of the methods and instance variables.


Where did you get the definition for the XP classes? Got a link? Can you PM it to me?
 

Solistra

Veteran
Veteran
Joined
Aug 15, 2012
Messages
593
Reaction score
247
Primarily Uses
Where did you get the definition for the XP classes? Got a link? Can you PM it to me?
The hidden classes have been written and rewritten many times over in Ruby -- considering the original code is actually written in C++, the most anyone has done is effectively recreate the hidden classes in pure Ruby, which is really not hard to do if you know the public methods, their return values, and the side effects that they cause.


Basically, I highly doubt that Sixth found the original C++ source for Window -- what they've seen is an approximation which has the same interface as the original class.
 

Sixth

Veteran
Veteran
Joined
Jul 4, 2014
Messages
2,162
Reaction score
823
First Language
Hungarian
Primarily Uses
RMVXA
Where did you get the definition for the XP classes? Got a link? Can you PM it to me?
I just searched for "rgss3 window hidden class" on google and the 3rd link lead me to it.
But I can send the link, no prob!


Solistra is right, it is not the original Window class source, it is a rewrite according to the author.


Regardless, the only thing I needed to see was the cursor's blinking mechanics, and that was in there. I needed the exact same details for the opacity change and when to reverse it (add or remove opacity), so that I could recreate exactly the same effect with custom images. Doing this with play-testing the game hundreds of time and watching that damned cursor blinking for hours was not in my plans in this life-time, so I decided to search for the data instead. And well, it was much quicker this way. :D


My whole menu system will be made from images, including sub-menus, so I needed to disable the default cursor and it's effects and recreate the effects on each selectable windows for each type of cursor (they got different shapes, sizes and positions). And to my surprise, it is working perfectly fine! :)


I still don't understand why would Enterbrain hide certain classes completely, while providing some, supposedly hidden classes in the same time... I mean, we got all of the RPG classes shown in the help files, but they won't show us classes like Window, Graphics, etc. >.>


Ohh, well, gotta live with what we have, right?
 

Meridianbot

Veteran
Veteran
Joined
Jan 9, 2013
Messages
84
Reaction score
14
First Language
German
Primarily Uses
Hi, I am looking for an option to get the name of variables and switches during runtime, is their a way?

And what I would like to get aswell ist hierachy of the maps.

Hope someone is able to help me.

regards Bot

ps: for the rpg-maker ace
 
Last edited by a moderator:

Users Who Are Viewing This Thread (Users: 0, Guests: 5)

Latest Threads

Latest Profile Posts

Day 9 of giveaways! 8 prizes today :D
He mad, but he cute :kaopride:

Our latest feature is an interview with... me?!

People4_2 (Capelet off and on) added!

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.

Forum statistics

Threads
106,040
Messages
1,018,476
Members
137,824
Latest member
dobratemporal
Top