RGSS scripting dissections and explinations
#47
(09-10-2017, 04:58 PM)DerVVulfman Wrote: 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.
 2 bunny ears " is stronger then 1 bunny ear ' but takes more memory then 1 bunny ear '

you can clear out a array "organizing box" using .clear

you can make a single line if statement!!! mind BLOWN

and 2 &'s makes a then? the last ones confusing logic-wise but OH WELL


Quote: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'?

thank you for the compliments regarding my 3D works! and for helping clarify my...learning style...
no I'm not a sniper! I've never even HELD a gun before!...I can however use a bow and arrow >:D

and parenthisis? thats "frownyface" ( and "smily" ) right?
[Image: SP1-Writer.png]
[Image: 55e3faa432d9efb86b8f19a6f25c0126-dawz35x.png]

new logo for Yesteryear created by Lunarberry!
Reply }


Messages In This Thread
RE: RGSS scripting dissections and explinations - by Siletrea - 09-10-2017, 06:57 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
   Help iwth script (RGSS Player crash) Whisper 3 8,529 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,112 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,884 12-22-2012, 05:11 AM
Last Post: MechanicalPen
   [Request] Tut. for RGSS Eldur 9 11,907 12-07-2012, 04:27 AM
Last Post: DerVVulfman
   [ASK-RGSS] Behemoth's CBS alike Getsuga_kawaii 0 4,227 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,136 03-31-2010, 11:03 PM
Last Post: Hsia_Nu



Users browsing this thread: 10 Guest(s)