Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 RGSS scripting dissections and explinations
#56
Hmm, let's talk about ||

If in my previous post '&&' is used like a 'then', this '||' is the opposite of that.

Look at example below
Code:
#==============================================================================
# ** Sprite
#------------------------------------------------------------------------------
#  A sprite class for bitmap processing.
#==============================================================================
class Sprite
 alias anti_dispose_error_alias dispose
 def dispose
   disposed? || anti_dispose_error_alias # <<<<
 end
end

The code above is fixes to prevent disposed sprite to throws an error if disposed again.
Normally when Sprite is disposed twice, an error would pop up saying "Sprite was disposed.". That code is prevents that.

I believe you already know about alias so I won't touch it.
Let's look at disposed? || anti_dispose_error_alias. The method disposed? is a method in class Sprite to check if Sprite already disposed or not, the method returns true if already disposed or false if haven't.

It's just like asking the sprite : "Hey sprite, have you already disposed?"

Moving on, let's talk about '||' behavior, as you probably guessed, it's opposite of '&&'.
If '&&' will check the next sentence only if previous one are true, the '||' will check the next sentence only if previous one are false or nil!

So based on that behavior if sprite is already disposed, it will not check anti_dispose_error_alias.

false || false || false || true || false || true || ......

As you see, the program will stop reading when the condition are true.


By the way:
|| = or

disposed? || anti_dispose_error_alias
disposed? or anti_dispose_error_alias

Those two are same things.
Reply }


Messages In This Thread
RE: RGSS scripting dissections and explinations - by LiTTleDRAgo - 09-11-2017, 08:07 AM

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



Users browsing this thread: