RGSS scripting dissections and explinations
#21
(09-07-2017, 06:26 AM)DerVVulfman Wrote: +=  Now that's a shortcut.   Instead of saying  a = a + 1, you say a += 1.   So each time we see a value of 'a', we add 1 to it.

-=  Another shortcut.  Just like above, this one subtracts from the value in question.

<  is a 'comparison' operator.  It means 'lesser than', and is used in checks like if a < b.   If the value of a is 15 and the value of b is 4, then it would be like if 15 is less than 3... Obviously not!  That test would FAIL.

And yeah, it is also used for the whole inheritance thing.  Laughing Pacman here does double duty.

>  is another 'comparison' operator.  It means 'greater than', and is used in checks like if a > b.   So again, if the value of a is 15 and the value of b is 4, then it would be like if 15 is greater than 3... NOW it works!  So that IF... block of code will run!

<= and >= respectively mean 'less than or equal to' and 'greater than or equal to'  Remember the test of if a < b?  If a was set to 5 and b was set to 5, then it would be if 5 was less than 5.... and again, FAIL.   But if we did if a <= b, it would work because it was not if a was less than OR EQUAL TO!!!

Equal signs!!!   What is different between = and   == ?   Well, the first replaces the contents of a variable and one does a comparison test.

a = 4 ....  this replaces the contents of variable 'a' with the value of '4'

if a == 4 .... this tests if the contents of variable 'a' equals '4'

Oh, the MODULO symbol!!!   It means the 'remainder'

%... otherwise the percentage symbol, it is used in programming to get the REMAINDER value of a division.  Like... um...  
If you divide 9 by 3, your value is 3, right?   There's no remainder.  It's clean and has nothing fractional.  But if you divide 9 by 2, you get 4 1/2 (or 4.5)  

NOW unless you tell the program that you are dealing with numbers with decimal values (we call them floats), you're only going to end up with whole numbers.  So an INTEGER version of 9 divided by 2 would actually equal 4!     That's where modulo comes in... it gets the remainder (or leftover part).  So the  9 % 2 would be '1'     It can handle dividing 8 by 2, and has a leftover 1 remaining.

EDIT:  Was I typing so long??????  Shocked

OHHHHHH so = equals will convert the 1st thing into the 2nd thing?! while == will see if they're the same!

ok so % is still a tad confusing? its like the smart way to divide?

yeah you type for a LOOONG time lol!

division is done with "/" right?

what does "\" do then?

or != I see that one pop up a few times
[Image: SP1-Writer.png]
[Image: 55e3faa432d9efb86b8f19a6f25c0126-dawz35x.png]

new logo for Yesteryear created by Lunarberry!
Reply }
#22
As == means 'equal to', the != means 'NOT equal to'

The % just gets the leftover remainder. Integers are WHOLE numbers only, and if you divide 13/5, the system will typically produce only 2, not 2.6. When dealing with whole numbers, 13/5 gets a value of 2, with a remainder of '3' (which you will NOT see). And if you run 13%2, you ONLY get the remainder of '3', and nothing else. The % symbol only gets the remainder of the division.

I guess to get ALL of the math for 13/5, you would need to calculate 13/5 (to get 2) and 13%5 (to get the remainder '3').

.... % also has another function for string manipulation (ie changing the way your text is displayed)... but that's a bit more complex.

You won't find '\' in anything really other than string data manipulation in the Message system, or in directory/folder paths, so I don't think you need to worry about it as yet. It's not math nor comparison based.
Up is down, left is right and sideways is straight ahead. - Cord "Circle of Iron", 1978 (written by Bruce Lee and James Coburn... really...)

[Image: QrnbKlx.jpg]
[Image: sGz1ErF.png]    [Image: liM4ikn.png]    [Image: fdzKgZA.png]    [Image: sj0H81z.png]
[Image: QL7oRau.png]    [Image: uSqjY09.png]    [Image: GAA3qE9.png]    [Image: 2Hmnx1G.png]    [Image: BwtNdKw.png%5B]
  Above are clickable links
Reply }
#23
DerVVulfman Wrote:I guess to get ALL of the math for 13/5, you would need to calculate 13/5 (to get 2) and 13%5 (to get the remainder '3').
Or get a very specific result by dividing 13/5.0 #=> 2.6
If the last number is a float (a number with decimals), then you get the exact result at once, no need for remainders then. This situation would be useful if you want to calculate stuff like percents, but not that useful if you want to calculate in game item prices because nobody would expect decimals there.

Item ID 1 is a Potion, it's price is set to 50, adding 15% of taxes (yeah, expensive indeed) would make it cost 57.5 but you don't want that because... well, the party has gold pieces only, no silver coins, no copper coins, so you prefer to round it as much as to avoid decimals completely. In that case you would not just do this...

50*1.15

but...

(50*1.15).round

57.5 then becomes 57! round alters the previous algorhythm or calculation surrounded by parenthesis by removing all decimals.

Why did I multiply the price by 1.15? Because 1 represents 100% and 0.15 represents 15% in that calculation, also known as price plus taxes.

In Ruby there are two kind of strings, those enclosed by " " and others by ' '.

" " double quotes accept many special characters including % for substitutions, but single quotes are simple, they need \ to interpreter a third ' single quote as apostrophe or the stupid floating dash that appears in idioms like Siletrea's cat to show other people that such cat belongs to you. (Some memes would tell you otherwise implying the cat owns you according to the cat's own perspective XD) " " double quotes accept one or more ' single quotes inside and treats them as a quote (you're reporting what a neighbor told you last week, i.e. something about how dangerous a street has become since a gang took control of it) like in...

"My neighbor actually told me last week: 'those scumbags have taken over Elm Street and keep attacking clueless people that use it as a shortcut to save a few minutes...' It seems police is afraid of confronting them because the gang still own that street."

String substitutions, meaning you are gonna replace a weird character with an actual value (a number, a name), are defined like this.

CAT_OWNER = "%s's pet cat"
owner_name = 'DerVVulfman'

print sprintf(CAT_OWNER, owner_name) #=> "DerVVulfman's pet cat"

But let's say we had defined CAT_OWNER in a different way...

CAT_OWNER = "%s's pet cat has a weird name, it's %s."
owner_name = 'DerVVulfman'
cat_name = 'Patches'

print sprintf(CAT_OWNER, owner_name, cat_name) #=> "DerVVulfman's pet cat has a weird name, it's Patches."

sprintf means special print format, it's an adaptation of sprintf command found in C so that's why it kept it's weird name in Ruby even if it's not as readable as most commands in Ruby actually are. sprintf is used for string substitutions a lot depending on a scripter's taste. You can substitute as many characters (%s) as you defined in the original string. Keep in mind that the original string was not modified, sprintf made a copy of it with one or two names included.

There are more possibilities to substitute different stuff but I guess that one might help you a lot once you take the grasp of it.

DerVVulfman had said earlier Wrote:& thingie (not listed) ... we think of as the 'and' symbol is called an ampersand. Good for doing if... tests. 'if this & that.'

Why do we use & ampersand? Well, blame ancient Romans that defined the term "and" as et back in the days. Yes, it's an e plus a t mixed in a single symbol.

. Dots - well, they let us access methods or properties or attributes that belong to any object (a class, a module, an array, a hash, a variable, a number, even a string) if they already exist. Otherwise you'd get a NoMethodError message in no time because Ruby could not find it anywhere. (The only class where you can call a none existing method would be Struct, a special kind of class that can be altered at any time, but I think that's too complex for you now and we rarely use it anyway. It's like, err, combining a class with a hash so it lets you call and set any method, really, any method at anytime and returns nil if it just doesn't exist instead of the error message I mentioned above.)

.. Double Dots, ... Triple Dots - they are a different story, they are part of a Range! Range in Ruby means you set an initial value like 13 and a last value like 17 or 18 as the last value. Automatically you'll get every single value inbetween as well! There's a catch you gotta observe, double dots actually includes all those values (always numbers, no exceptions!), but triple dots exclude the last value.

0..18 #=> a Range representing all ages that would make a person be called a minor and get arrested if found drinking alcohol.
0...19 #=> same as above but skips 19

first_value..last_value #=> if first_value is 19 and last_value is 100 it will work like any Range that's defined with numbers.

countdown = 60 #=> let's say it represents 60 minutes here
first_value = 0
last_value = 120

range = first_value..last_value
range.include?(countdown) #=> true it IS included because first_value equals 0 and last_value equals 120.

every minute we substract a minute to our lovely countdown

countdown -= 1 #=> 59 minutes left because countdown - 1 would be 59

But that would be a mere calculation, to make the variable keep the new value we set it like this: countdown = countdown - 1 or countdown -= 1, they mean exactly the same, both will allow us to substract 1 minute from countdown.

if countdown == first_value
print "Siletrea's birthday party begins now!"
else
print "Siletrea should wait patiently..."
end

Yeah, I know, there's a second command named include... well, that's not completely accurate, it's called include? so Ruby thinks it's different from include. How can you be so sure? Well, use it to include a module like RPG and you'll get an error that will shutdown your game after you close the pop up window XD. include? with that question mark ? is a query or something like a question you make while holding a conversation with range. It's like asking range...

"Do you include 60, my dear friend range?"

Instead of getting a response like yes or not, range will tell you it's true or false only.
"For God has not destined us for wrath, but for obtaining salvation through our Lord Jesus Christ," 1 Thessalonians 5:9

Maranatha!

The Internet might be either your friend or enemy. It just depends on whether or not she has a bad hair day.

[Image: SP1-Scripter.png]
[Image: SP1-Writer.png]
[Image: SP1-Poet.png]
[Image: SP1-PixelArtist.png]
[Image: SP1-Reporter.png]

My Original Stories (available in English and Spanish)

List of Compiled Binary Executables I have published...
HiddenChest & Roole

Give me a free copy of your completed game if you include at least 3 of my scripts! Laughing + Tongue sticking out

Just some scripts I've already published on the board...
KyoGemBoost XP VX & ACE, RandomEnkounters XP, KSkillShop XP, Kolloseum States XP, KEvents XP, KScenario XP & Gosu, KyoPrizeShop XP Mangostan, Kuests XP, KyoDiscounts XP VX, ACE & MV, KChest XP VX & ACE 2016, KTelePort XP, KSkillMax XP & VX & ACE, Gem Roulette XP VX & VX Ace, KRespawnPoint XP, VX & VX Ace, GiveAway XP VX & ACE, Klearance XP VX & ACE, KUnits XP VX, ACE & Gosu 2017, KLevel XP, KRumors XP & ACE, KMonsterPals XP VX & ACE, KStatsRefill XP VX & ACE, KLotto XP VX & ACE, KItemDesc XP & VX, KPocket XP & VX, OpenChest XP VX & ACE
Reply }
#24
(09-07-2017, 06:55 AM)DerVVulfman Wrote: As == means 'equal to', the != means 'NOT equal to'

The % just gets the leftover remainder.   Integers are WHOLE numbers only, and if you divide 13/5, the system will typically produce only 2, not 2.6.  When dealing with whole numbers, 13/5 gets a value of 2, with a remainder of '3' (which you will NOT see).  And if you run 13%2, you ONLY get the remainder of '3', and nothing else.  The % symbol only gets the remainder of the division.

I guess to get ALL of the math for 13/5, you would need to calculate 13/5 (to get 2) and 13%5 (to get the remainder '3').

....  % also has another function for string manipulation (ie changing the way your text is displayed)... but that's a bit more complex.

You won't find '\' in anything really other than string data manipulation in the Message system, or in directory/folder paths, so I don't think you need to worry about it as yet.  It's not math nor comparison based.

is that the only uses for !

and how would one get a script to use things inside of XP's folders? is there a special command for that?
[Image: SP1-Writer.png]
[Image: 55e3faa432d9efb86b8f19a6f25c0126-dawz35x.png]

new logo for Yesteryear created by Lunarberry!
Reply }
#25
(09-07-2017, 04:54 PM)kyonides Wrote:
DerVVulfman Wrote:I guess to get ALL of the math for 13/5, you would need to calculate 13/5 (to get 2) and 13%5 (to get the remainder '3').
Or get a very specific result by dividing 13/5.0 #=> 2.6
If the last number is a float (a number with decimals), then you get the exact result at once, no need for remainders then. This situation would be useful if you want to calculate stuff like percents, but not that useful if you want to calculate in game item prices because nobody would expect decimals there.

Item ID 1 is a Potion, it's price is set to 50, adding 15% of taxes (yeah, expensive indeed) would make it cost 57.5 but you don't want that because... well, the party has gold pieces only, no silver coins, no copper coins, so you prefer to round it as much as to avoid decimals completely. In that case you would not just do this...

50*1.15

but...

(50*1.15).round

57.5 then becomes 57! round alters the previous algorhythm or calculation surrounded by parenthesis by removing all decimals.

Why did I multiply the price by 1.15? Because 1 represents 100% and 0.15 represents 15% in that calculation, also known as price plus taxes.

In Ruby there are two kind of strings, those enclosed by " " and others by ' '.

" " double quotes accept many special characters including % for substitutions, but single quotes are simple, they need \ to interpreter a third ' single quote as apostrophe or the stupid floating dash that appears in idioms like Siletrea's cat to show other people that such cat belongs to you. (Some memes would tell you otherwise implying the cat owns you according to the cat's own perspective XD) " " double quotes accept one or more ' single quotes inside and treats them as a quote (you're reporting what a neighbor told you last week, i.e. something about how dangerous a street has become since a gang took control of it) like in...

"My neighbor actually told me last week: 'those scumbags have taken over Elm Street and keep attacking clueless people that use it as a shortcut to save a few minutes...' It seems police is afraid of confronting them because the gang still own that street."

String substitutions, meaning you are gonna replace a weird character with an actual value (a number, a name), are defined like this.

CAT_OWNER = "%s's pet cat"
owner_name = 'DerVVulfman'

print sprintf(CAT_OWNER, owner_name) #=> "DerVVulfman's pet cat"

But let's say we had defined CAT_OWNER in a different way...

CAT_OWNER = "%s's pet cat has a weird name, it's %s."
owner_name = 'DerVVulfman'
cat_name = 'Patches'

print sprintf(CAT_OWNER, owner_name, cat_name) #=> "DerVVulfman's pet cat has a weird name, it's Patches."

sprintf means special print format, it's an adaptation of sprintf command found in C so that's why it kept it's weird name in Ruby even if it's not as readable as most commands in Ruby actually are. sprintf is used for string substitutions a lot depending on a scripter's taste. You can substitute as many characters (%s) as you defined in the original string. Keep in mind that the original string was not modified, sprintf made a copy of it with one or two names included.

There are more possibilities to substitute different stuff but I guess that one might help you a lot once you take the grasp of it.


DerVVulfman had said earlier Wrote:& thingie (not listed) ... we think of as the 'and' symbol is called an ampersand. Good for doing if... tests. 'if this & that.'

Why do we use & ampersand? Well, blame ancient Romans that defined the term "and" as et back in the days. Yes, it's an e plus a t mixed in a single symbol.

. Dots - well, they let us access methods or properties or attributes that belong to any object (a class, a module, an array, a hash, a variable, a number, even a string) if they already exist. Otherwise you'd get a NoMethodError message in no time because Ruby could not find it anywhere. (The only class where you can call a none existing method would be Struct, a special kind of class that can be altered at any time, but I think that's too complex for you now and we rarely use it anyway. It's like, err, combining a class with a hash so it lets you call and set any method, really, any method at anytime and returns nil if it just doesn't exist instead of the error message I mentioned above.)

.. Double Dots, ... Triple Dots - they are a different story, they are part of a Range! Range in Ruby means you set an initial value like 13 and a last value like 17 or 18 as the last value. Automatically you'll get every single value inbetween as well! There's a catch you gotta observe, double dots actually includes all those values (always numbers, no exceptions!), but triple dots exclude the last value.

0..18 #=> a Range representing all ages that would make a person be called a minor and get arrested if found drinking alcohol.
0...19 #=> same as above but skips 19

first_value..last_value #=> if first_value is 19 and last_value is 100 it will work like any Range that's defined with numbers.

countdown = 60 #=> let's say it represents 60 minutes here
first_value = 0
last_value = 120

range = first_value..last_value
range.include?(countdown) #=> true it IS included because first_value equals 0 and last_value equals 120.

every minute we substract a minute to our lovely countdown

countdown -= 1 #=> 59 minutes left because countdown - 1 would be 59

But that would be a mere calculation, to make the variable keep the new value we set it like this: countdown = countdown - 1 or countdown -= 1, they mean exactly the same, both will allow us to substract 1 minute from countdown.

if countdown == first_value
print "Siletrea's birthday party begins now!"
else
print "Siletrea should wait patiently..."
end

Yeah, I know, there's a second command named include... well, that's not completely accurate, it's called include? so Ruby thinks it's different from include. How can you be so sure? Well, use it to include a module like RPG and you'll get an error that will shutdown your game after you close the pop up window XD. include? with that question mark ? is a query or something like a question you make while holding a conversation with range. It's like asking range...

"Do you include 60, my dear friend range?"

Instead of getting a response like yes or not, range will tell you it's true or false only.

ohh! so you can round things to their nearest using .round?

how many commands like that are there? .something
[Image: SP1-Writer.png]
[Image: 55e3faa432d9efb86b8f19a6f25c0126-dawz35x.png]

new logo for Yesteryear created by Lunarberry!
Reply }
#26
NetZ (or ntzrmtthihu777) took an few online help document on RUBY and converted them into downloadable help files.... (>Here<)

The link marked "Pogramming Ruby - The Pragmatic Programmer's Guide" is what I use. BUT.... it's a REGULAR book. But Chapter 22 (Built-In Classes & Modules) gives you lists of all statements n commands. .... a LOT of statements and commands. The help file in RPGMaker XP may cover some commands, but this sucker has four times the number of commands listed! Mebby more.

Ya MAY wanna take a look at the help files. Dunno. But it's something to look at.

And it may give you more things to ask about.
Up is down, left is right and sideways is straight ahead. - Cord "Circle of Iron", 1978 (written by Bruce Lee and James Coburn... really...)

[Image: QrnbKlx.jpg]
[Image: sGz1ErF.png]    [Image: liM4ikn.png]    [Image: fdzKgZA.png]    [Image: sj0H81z.png]
[Image: QL7oRau.png]    [Image: uSqjY09.png]    [Image: GAA3qE9.png]    [Image: 2Hmnx1G.png]    [Image: BwtNdKw.png%5B]
  Above are clickable links
Reply }
#27
(09-08-2017, 04:20 AM)DerVVulfman Wrote: NetZ (or ntzrmtthihu777) took an few online help document on RUBY and converted them into downloadable help files.... (>Here<)

The link marked "Pogramming Ruby - The Pragmatic Programmer's Guide" is what I use.  BUT.... it's a REGULAR book.  But Chapter 22 (Built-In Classes & Modules) gives you lists of all statements n commands.   .... a LOT of statements and commands.    The help file in RPGMaker XP may cover some commands, but this sucker has four times the number of commands listed!  Mebby more.

Ya MAY wanna take a look at the help files.  Dunno.  But it's something to look at.

And it may give you more things to ask about.

appreciated but both links are down
if anything I learned that a manual in in XP so I'll poke around in there tomorrow and then quiz you guys if I don't understand stuff! XD
[Image: SP1-Writer.png]
[Image: 55e3faa432d9efb86b8f19a6f25c0126-dawz35x.png]

new logo for Yesteryear created by Lunarberry!
Reply }
#28
OK guys! BIG question time!

how to create a call in a script to do a script call!

and how to utilize the print function WITH script call?

I made my 1st script! and now I wanna get creative!
[Image: SP1-Writer.png]
[Image: 55e3faa432d9efb86b8f19a6f25c0126-dawz35x.png]

new logo for Yesteryear created by Lunarberry!
Reply }
#29
Print command is a support tool, not an actual goal, keep it away from actual scripting code unless you need it for debugging or throwing error messages at people XD. Really, people complain about them a lot. Learn how to use game windows or sprites for displaying disclaimers or timers or silly greetings.

class Sprite_MakeFunOfSiletrea < Sprite
def initialize(x, y, width, lines)
super(Viewport.new(x, y, width, lines * 28))
self.bitmap = bit = Bitmap.new(width, lines * 28)
bit.draw_text(4, 4, width-8, 24, 'XP')
end
end

Now you've got a sprite that's sticking its tongue out XD

What's a Viewport? It's like a window glass or screen that lets you see what's inside, that's why it needs x and y coordinates, width and height. Unlike cameras, you're not supposed to move it at all, but move its contents instead.

Bitmap handles drawings, it's a collection of colored or transparent bits or dots that allow you to display text or even so called cute fakemon (a lame way to use it indead). In this case it needs a width and some height. Later you can call its draw_text method to tell it in its ears that it should print that emoticon on screen. You need to pass x, y, width, a line height, text, and sometimes a number additionally to align it to your right hand side or center it.
"For God has not destined us for wrath, but for obtaining salvation through our Lord Jesus Christ," 1 Thessalonians 5:9

Maranatha!

The Internet might be either your friend or enemy. It just depends on whether or not she has a bad hair day.

[Image: SP1-Scripter.png]
[Image: SP1-Writer.png]
[Image: SP1-Poet.png]
[Image: SP1-PixelArtist.png]
[Image: SP1-Reporter.png]

My Original Stories (available in English and Spanish)

List of Compiled Binary Executables I have published...
HiddenChest & Roole

Give me a free copy of your completed game if you include at least 3 of my scripts! Laughing + Tongue sticking out

Just some scripts I've already published on the board...
KyoGemBoost XP VX & ACE, RandomEnkounters XP, KSkillShop XP, Kolloseum States XP, KEvents XP, KScenario XP & Gosu, KyoPrizeShop XP Mangostan, Kuests XP, KyoDiscounts XP VX, ACE & MV, KChest XP VX & ACE 2016, KTelePort XP, KSkillMax XP & VX & ACE, Gem Roulette XP VX & VX Ace, KRespawnPoint XP, VX & VX Ace, GiveAway XP VX & ACE, Klearance XP VX & ACE, KUnits XP VX, ACE & Gosu 2017, KLevel XP, KRumors XP & ACE, KMonsterPals XP VX & ACE, KStatsRefill XP VX & ACE, KLotto XP VX & ACE, KItemDesc XP & VX, KPocket XP & VX, OpenChest XP VX & ACE
Reply }
#30
(09-08-2017, 05:59 PM)kyonides Wrote: Print command is a support tool, not an actual goal, keep it away from actual scripting code unless you need it for debugging or throwing error messages at people XD. Really, people complain about them a lot. Learn how to use game windows or sprites for displaying disclaimers or timers or silly greetings.

class Sprite_MakeFunOfSiletrea
def initialize(x, y, width, lines)
super(Viewport.new(x, y, width, lines * 28))
self.bitmap = bit = Bitmap.new(width, lines * 28)
bit.draw_text(4, 4, width-8, 24, 'XP')
end
end

Bitmap... I see that a lot! What does bitmap mean? EDIT: you edited after I posted so I got the answer thx!

(My intention is to make the popup windows slightly uncomfortable so don't worry!)
[Image: SP1-Writer.png]
[Image: 55e3faa432d9efb86b8f19a6f25c0126-dawz35x.png]

new logo for Yesteryear created by Lunarberry!
Reply }


Possibly Related Threads…
Thread Author Replies Views Last Post
   Help iwth script (RGSS Player crash) Whisper 3 8,534 06-17-2017, 05:03 PM
Last Post: Whisper
  How can I use the cmd of "require" in rgss superegp 2 5,918 11-03-2015, 06:16 AM
Last Post: kyonides
   Scripting in VX vs VX Ace Miharu 5 9,095 02-21-2015, 10:10 AM
Last Post: Taylor
   Combat animations via scripting; How? ZeroSum 2 5,114 09-20-2013, 06:58 PM
Last Post: ZeroSum
Question  RGSS stoped to work Chaos17 5 7,750 02-14-2013, 05:13 PM
Last Post: DerVVulfman
   Ruby, RGSS & General Code Discussion Kain Nobel 6 10,891 12-22-2012, 05:11 AM
Last Post: MechanicalPen
   [Request] Tut. for RGSS Eldur 9 11,929 12-07-2012, 04:27 AM
Last Post: DerVVulfman
   [ASK-RGSS] Behemoth's CBS alike Getsuga_kawaii 0 4,231 04-29-2010, 03:07 PM
Last Post: Getsuga_kawaii
   Scripting I think spazfire 7 10,182 04-12-2010, 03:21 AM
Last Post: DerVVulfman
   Beginner Scripting Tuts? KDawg08 1 4,140 03-31-2010, 11:03 PM
Last Post: Hsia_Nu



Users browsing this thread: 16 Guest(s)