RGSS scripting dissections and explinations
#45
Hey, ya came in on your birthday!

I agree with you regarding the usage of the single-quote (') vs double-quote (") options. It is true that double-quotes are more powerful and can give you more options, but they do use more memory resources and take more time to process.

LIKEWISE.... another reason to avoid the use of global variable in your scripts (ie the $ variables) is that while they can span throughout your game, they too use more memory resources and take more time.


Best to cover explanations why things work, not just what works. Not everyone has the same learning conditions. While some people may be geniuses in 3D modeling, the educational system might have not picked up other learning disabilities. Our Siletrea is one such person, a true Savant with 3D animations, but is autistic. Better beware. anyone seen Ben Affleck's 'The Accountant'?

So, let's break down what LiTTleDRAgo offered for the different options of comparing data

FIRST, our data itself: array = [23,40,320,3020] We're just naming this array (list of values)... 'array' Just something nice and neat. And it holds four values: 23, 40, 320 and 3020. AND... remember what I said about an array's 'index' value... the Index value of an array begins with '0' (zero), not '1'. The first value in this array is called index value 0, the second would be index value 1, the third would be index value 2, and the last would be index value '3'. Counting the indexes begin with 0 and not 1.

So if I ask for the value of array[2] in my code, I would get the value of 320

Now all three examples that LiTTleDRAgo do basically the same thing. If something happens, the array is cleared... erased... gets empty. The command array.clear will clear/erase the array. If he named his array 'frodo_baggins' instead of 'array', he would have used the command 'frodo_baggins.clear' instead. But that's something else when we get to understanding arrays, when you ask.

And I just realized that LiTTleDRAgo blew it as his array has only four values and indexes count from 0. I'm adjusting his examples as there is no data in an index value of '4'.... there is no fifth piece of data in the array.

THE FIRST example:

if array[2] > array[3]
array.clear
end


Very simple. This is your simple IF...end block. The first line is your comparison.... If it is true, it does everything down until it hits the 'end' statement for that block. In this case, it will do it's job if the value in 'array[2]' (or 320) is greater than the value in 'array[3]' (or 3020), And again, that goofy 'array.clear' statement just erases the data in the array.


THE SECOND example:

array.clear if array[2] > array[3]

THIS is how I like to shorten my code. Laughing This is also a variation of the IF...end block, except it can all be done on one line if your block of code is just that short.

The actual command of 'array.clear' is the first thing you see, but it has the actual "IF' condition right next to it. And the IF condition is also the same 'if the value of 320 is more than 3020'...

OR, you could say (...hehehe...)
canadians can get drunk if age > 18
......Sound familiar? Winking

NOW FOR THE THIRD example...

(array[2] > array[3]) && array.clear

FIRST, notice that we're back to a layout where we check the condition first (array[2] > array[3]) and THEN only perform the actual code if the condition is true. [/b]&& array.clear[/b]

He put the actual test, the IF portion, in parenthesis. Remember how I said parenthesis holds values and the whole math thingie called 'precedence rules'? This keeps his whole comparison of 'array[2] > array[3]' clean and separate from everything else in that line of code.

Now AFTER that, he has && array.clear. You've seen how I said that the & symbol means 'and', right? Well, the '&&' symbol is called a logical operator and sorta means 'THEN'. So the statement is like if (arrays compared) THEN array.clear.

or....

( age > 18 ) & (location == canada) && canadians_can_get_drunk

Had to make sure you were in Canada too.
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 }


Messages In This Thread
RE: RGSS scripting dissections and explinations - by DerVVulfman - 09-10-2017, 04:58 PM

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



Users browsing this thread: 15 Guest(s)