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

Rikifive

Bringer of Happiness
Veteran
Joined
Jun 21, 2015
Messages
1,441
Reaction score
680
First Language
Polish
Primarily Uses
Other
@timer = @timer == 10 ? 0 : @timer + 1Aww.. that was so obvious, why I cannot think that way in first place, thank you.

I really need to focus more.

@thing = @timer / 2 if @timer % 2 == 0Yup, thank you.

About % operator - I have read about this, but never tried using this and forgot about that.  :p

I took a look on that note again and if I'm not mistaking it works like this?

49 % 5 = 4, because 49 : 5 = 9 and there's '4' left - right?

I feel so stupid now.

But at least, I think that was my first question, that really didn't needed its own thread. ( ͡° ͜ʖ ͡°)
 
Last edited by a moderator:

KockaAdmiralac

Cube-shaped garbage can
Veteran
Joined
Jun 15, 2015
Messages
569
Reaction score
153
First Language
Serbian
Primarily Uses
N/A
Yeah, you got it.

% operator has some other uses, like extracting digits from a number.

Code:
number = 123456first_digit = (number / 100000) % 10second_digit = (number / 10000) % 10# And so on...
This could be useful if you are still in the process of learning...
 

Rikifive

Bringer of Happiness
Veteran
Joined
Jun 21, 2015
Messages
1,441
Reaction score
680
First Language
Polish
Primarily Uses
Other
That's clever! Now I know how some things were made.

One question though - what about floating points?

For example the first_digit is 1.23456 % 10 which gives '0' and 1.23456 left over.

How does that count?

Let's take for example other number 1.88888 % 10 which gives '0' and 1.88888 left over.

It's just 1.88888 (forgets about the rest) or raises that to ~2 (does basic maths) ?
 
Last edited by a moderator:

KockaAdmiralac

Cube-shaped garbage can
Veteran
Joined
Jun 15, 2015
Messages
569
Reaction score
153
First Language
Serbian
Primarily Uses
N/A
It does the same thing :

puts 1.88888 % 1 # => 0.88888puts 1.2345 % 10 # => 1.2345# Because digits after the point are not in the same system as those before them, you can't use those things :puts 1.2345 % 0.1 # => 0.0345<and some more random digits here># You can instead use :a = 0your_number = 1.2345while your_number % 10 != 0  your_number *= 10  a += 1endlast_digit = your_number % 10 # And it should be 5# And if your want to turn your number back to normal :your_number /= 10 ** aAt least I think so...
 
Last edited by a moderator:

Rikifive

Bringer of Happiness
Veteran
Joined
Jun 21, 2015
Messages
1,441
Reaction score
680
First Language
Polish
Primarily Uses
Other
Mhm, but in general:

number = 188888first_digit = (number / 100000) % 10 # gives 1? not 2? (because 1.88888 ~ 2)# it doesn't add 1 when it's 0.5 or above?# - it does take only '1' and forgets about floating points ~ turns into an integer without rounding?right?
 

Sixth

Veteran
Veteran
Joined
Jul 4, 2014
Messages
2,162
Reaction score
823
First Language
Hungarian
Primarily Uses
RMVXA
You can't use the % operation with any floating point numbers.


Also 188888/100000 = 1, because it ignores any decimals unless you turn the 188888 to a floating point number (188888.0).


But as soon as you do that, the % operation will not work, because there is no left-overs if you work with floating point numbers.


The % operation is intended to work with integers only and should only be used with integers.
 

KockaAdmiralac

Cube-shaped garbage can
Veteran
Joined
Jun 15, 2015
Messages
569
Reaction score
153
First Language
Serbian
Primarily Uses
N/A
Don't forget this is Ruby, not Maths.

puts 123 / 100 # => 1, because none of them is a floating pointputs 123.0 / 100 # => 1.23, because the first is floating pointputs 123 / 100.0 # => 1.23, because the second is the floating pointThis is in programming called implicit (I think) conversions.

In Ruby this is not so easy to understand, because you don't define your variables and their types, they are defined automatically for you, but in some other languages, like C/C++/Java/C# you would have something like this :

int a = 100; // int defines the variable as integer, and the max value of an integer is somewhere about 10^9float b = 100.0f; // This is a floating point, and I think max range is 10^308. You must add 'f' at the end, because there is also another floating point type// called 'double', and it's like the double range of the float (quite obvious)char c = 1; // This is a character type. You might be asking why is character a 1 and not '1', and that's because '1' refers to character '1', and 1 refers to '☺'// (Enter ALT+1 to type this character), but that's not the point, the range is 2^8char d = 2;int e = 10;// So let's do some things.cout<<c; // cout<< is the same as puts, and this will output ☺cout<<c+a; // 101, because char is the type with smaller range and it's automatically convertedcout<<a; // 100cout<<a+b; // 200.0, another conversion.cout<<a+e; // 110, no conversion, they are both the same typecout<<c+d; // '♥' (or ALT+3), no conversion.Note that character

☺ is not 0, it is ☺
Simple enough? :)
 
Last edited by a moderator:

Sixth

Veteran
Veteran
Joined
Jul 4, 2014
Messages
2,162
Reaction score
823
First Language
Hungarian
Primarily Uses
RMVXA
That's the reason why I like Ruby way more than other languages.


I mean, yeah, I know that 12 is an integer and that 7.86 is a floating point number, writing the type of the variable before the variable every single time is just too tedious for my taste. >.>


I wonder why the other languages don't have that automated...
 

Rikifive

Bringer of Happiness
Veteran
Joined
Jun 21, 2015
Messages
1,441
Reaction score
680
First Language
Polish
Primarily Uses
Other
You can't use the % operation with any floating point numbers.

Also 188888/100000 = 1, because it ignores any decimals unless you turn the 188888 to a floating point number (188888.0).

But as soon as you do that, the % operation will not work, because there is no left-overs if you work with floating point numbers.

The % operation is intended to work with integers only and should only be used with integers.
That explains everything, thank you.

Don't forget this is Ruby, not Maths.

puts 123 / 100 # => 1, because none of them is a floating pointputs 123.0 / 100 # => 1.23, because the first is floating pointputs 123 / 100.0 # => 1.23, because the second is the floating pointThis is in programming called implicit (I think) conversions.

In Ruby this is not so easy to understand, because you don't define your variables and their types, they are defined automatically for you, but in some other languages, like C/C++/Java/C# you would have something like this :

int a = 100; // int defines the variable as integer, and the max value of an integer is somewhere about 10^9float b = 100.0f; // This is a floating point, and I think max range is 10^308. You must add 'f' at the end, because there is also another floating point type// called 'double', and it's like the double range of the float (quite obvious)char c = 1; // This is a character type. You might be asking why is character a 1 and not '1', and that's because '1' refers to character '1', and 1 refers to '☺'// (Enter ALT+1 to type this character), but that's not the point, the range is 2^8char d = 2;int e = 10;// So let's do some things.cout<<c; // cout<< is the same as puts, and this will output ☺cout<<c+a; // 101, because char is the type with smaller range and it's automatically convertedcout<<a; // 100cout<<a+b; // 200.0, another conversion.cout<<a+e; // 110, no conversion, they are both the same typecout<<c+d; // '♥' (or ALT+3), no conversion.Note that character

☺is not 0, it is ☺
Simple enough? :)
I have kinda Mathematician mind so that's why these questions were in my mind.

These first examples are enough, I'll leave the magic in examples below for now. ( ͡° ͜ʖ ͡°)

Thank you for explaining things. I guess I can gladly say - TIL. (=
 

KockaAdmiralac

Cube-shaped garbage can
Veteran
Joined
Jun 15, 2015
Messages
569
Reaction score
153
First Language
Serbian
Primarily Uses
N/A
I wonder why the other languages don't have that automated...
Because 'other' languages are way, way, WAY faster than Ruby, Python, PHP, JS, or any other scripting languages.

Also, Ruby is INTERPRETING those things, and other languages like C/C++/C#/Java are COMPILING them.

The difference is that Ruby interpreter must read the script and then turn those lines into something processor-understandable on runtime, and compilable languages are COMPILING it, that means their programs are already turned into something (in this case Assembly) processor-understandable.

Ruby is dynamically allocating variables every time, so that's why some things are easier to achieve with Ruby, but if you want to come down to some lower (and faster) level, C++ is the language you are searching for.

Although I really hate this code :

...#define _PTR_LD(x) ((unsigned char *)(&(x)->ld))   typedef struct {    double x;  } _CRT_DOUBLE;   typedef struct {    float f;  } _CRT_FLOAT; #pragma push_macro("long")#undef long   typedef struct {    long double x;  } _LONGDOUBLE; #pragma pop_macro("long") #pragma pack(4)  typedef struct {    unsigned char ld12[12];  } _LDBL12;#pragma pack()#endif ...Yeah, that's C, unfortunately
Also, some lower-level languages allow you to see how some algorithms can be of use, like, I have NEVER seen any scripter on these forums that used Quadtree for 2D collision detection...

And let's not forget that usually C/C++ programmers pretty fast learn other languages, but Ruby/Python/JS/PHP programmers are still fighting with this problem...
 
Last edited by a moderator:

ShinGamix

DS Style 4Ever!
Veteran
Joined
Mar 18, 2012
Messages
3,905
Reaction score
451
First Language
April Fools
Primarily Uses
N/A
In the battle system when it says "@Party Member Attacks" where in the scripts would I adjust that screen location?? I using some YEA and Symphony also. Wouldnt it be in the core ace battle scripts though?

 

KockaAdmiralac

Cube-shaped garbage can
Veteran
Joined
Jun 15, 2015
Messages
569
Reaction score
153
First Language
Serbian
Primarily Uses
N/A
It should be in Window_BattleLog -> initialize and find the call to superclass method, like this :

super(0, 0, window_width, window_height)Those parameters mean x and y coordinate, and width and height of the window.If you want to change position, change those 4 numbers as you wish.

At least I think so.
 
Last edited by a moderator:

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,682
Reaction score
3,003
First Language
Tagalog
Primarily Uses
RMVXA
Yeah, change the first two parameters to modify the positioning of the battle log window
 
Joined
Jun 11, 2015
Messages
18
Reaction score
1
First Language
English
Primarily Uses
Is there a tutorial anywhere on how to script a sprite to show up in battle, or generally how to use the sprite scripts? Looking at the default VXAce scripts and having trouble figuring out how to use them in general- the help file isn't making things clearer for me, and I think a good tutorial would be useful :| Mostly looking for how to make a sprite appear and then disappear during battle and I think I can work from there.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,107
Reaction score
13,713
First Language
English
Primarily Uses
RMMV
no, there isn't. It's assumed if you're playing with the scripts, you are somewhat able to read and understand them.


Check out the Learning Ruby and RGSSx subforum. Apart from that, you either have to just look through things, or ask specific questions (not in this thread).
 

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,682
Reaction score
3,003
First Language
Tagalog
Primarily Uses
RMVXA
You'd want to look at these script things if you wanna learn how to do that

:making sprite objects

:drawing bitmaps on the sprites

:flow of a scene especially battle scene

:making counters

:showing animations
 
Joined
Jun 11, 2015
Messages
18
Reaction score
1
First Language
English
Primarily Uses
I was hoping someone would have a link to one, similar to the Silp Into Ruby series that goes over the Game_X scripts. I'm definitely able to read and understand most of the scripts, but I'm having trouble deciphering how certain ones work given that they're referencing several different sections of the script editor at once.
 

You'd want to look at these script things if you wanna learn how to do that

:making sprite objects
:drawing bitmaps on the sprites
:flow of a scene especially battle scene
:making counters
:showing animations
Is that in the general help file, or just something to search around for? Either way, thanks for getting me started.

Edit: Got it working now, thanks Adiktuzmiko! Took a while to figure out how to get a filename in but it's working, and I think I can finagle the rest from the help file :)
 
Last edited by a moderator:

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,682
Reaction score
3,003
First Language
Tagalog
Primarily Uses
RMVXA
I've learned how to make sprite objects and draw bitmaps in them on the help file... As fpr animations and flow, I studied the actual scripts
 

KockaAdmiralac

Cube-shaped garbage can
Veteran
Joined
Jun 15, 2015
Messages
569
Reaction score
153
First Language
Serbian
Primarily Uses
N/A
Well, this is more "learning" related, but you should know :

1) Bitmap

Bitmap is simply an image.

It's the base display class, and every image you see (except the map, that's Tilemap) it's a Bitmap in the base. There are two wrapper classes for it : Sprite and Window

2) Sprite

Sprite is a simple Bitmap, but with more features, because it has it's X and Y coordinates, opacity and so on.

You can see sprites as :

- Events (on map)

- Battlers (in battle)

And lots of other things...

3) Window

Window is a Bitmap with windowskin.

It prety much acts like a Sprite, and it's used in lots of places, in item scene, in equipment scene...

So, if you want to change the picture of a Sprite, you change it's Bitmap.

Inspect those three classes in the help file (F1 or F11 -> Help) and you should get the point.

Sprites were also very hard for me to learn, especially how to show animations on them.

Correct me if I'm wrong.
 

Sixth

Veteran
Veteran
Joined
Jul 4, 2014
Messages
2,162
Reaction score
823
First Language
Hungarian
Primarily Uses
RMVXA
The window is actually:


"Created internally from multiple sprites."


According to the help files, and according to a full window class rewrite I have seen.


Also, bitmaps are not necessarily images (as in pictures - jpg, png, etc).


I would rather call them the drawing table of sprites.


You can create an empty bitmap without an image associated, that is why I call them like that.


As far as I know, bitmaps alone can not be displayed, they must be assigned to a sprite (be it drawing them on a window or assigning them for a sprite directly).


The tilemap itself is a collection of sprites too. I suppose that is why it is so slow, hell of a lot sprites with hell of a lot bitmaps.


At least that is what I think I learned from all the sources I read. I might got something wrong thou, that's always in the list of possibilities, so I await corrections as well. :D
 

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

Latest Threads

Latest Posts

Latest Profile Posts

This is relevant so much I can't even!
Frostorm wrote on Featherbrain's profile.
Hey, so what species are your raptors? Any of these?
... so here's my main characters running around inside "Headspace", a place people use as a safe place away from anxious/panic related thinking.
Stream will be live shortly! I will be doing some music tonight! Feel free to drop by!
Made transition effects for going inside or outside using zoom, pixi filter, and a shutter effect

Forum statistics

Threads
105,998
Messages
1,018,218
Members
137,777
Latest member
Bripah
Top