Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 RGSS scripting dissections and explinations
#89
Sleepy SIletrea? XD Really?

(12-28-2018, 04:03 AM)Siletrea Wrote: @ instance is used to call things from anywhere within its own script regardless of where it is

*BRZZZZ!!!* Not exactly. "It s a variable to use from anywhere in its 'CLASS'." That is, unless you use special commands to access them... but that hasn't been covered yet.

I could make a script that has contains both Game_Siletrea class and a Scene_Siletrea class. If I make a @misha variable within Game_Siletrea, that variable is unique to Game_Siletrea. I could make a similar @misha variable in Scene_Siletrea.

Now that doesn't mean I can't let some other class read the @misha value used by Game_Siletrea..... I 'CAN!!!!' WOOO! But I gotta throw in one of TWO statements: either attr_reader or attr_accessor. The 'reader' version lets the value be read from another class... but only read from it. The 'accessor' version lets you access the value for reading and writing.

Code:
class Game_Siletrea
  def initialize
    @misha = "cat"
  end
end

class Scene_Siletrea
  def main
    @misha = "is a cat"
    (other stuff)
  end
end
.... the @misha value from Game_Siletrea can only be used in Game_Siletrea

Code:
class Game_Siletrea
  attr_reader :misha
  def initialize
    @misha = "cat"
  end
end

class Scene_Siletrea
  def main
    @misha = $game_siletrea.misha
    (other stuff)
  end
end
.... the @misha value from Game_Siletrea can be read 'BY' Scene_Siletrea.

Code:
class Game_Siletrea
  attr_accessor :misha
  def initialize
    @misha = "cat"
  end
end

class Scene_Siletrea
  def main
    @misha = "Can Dance"
    $game_siletrea.misha = "Is a Dance Dance Revolution champ!"
    (other stuff)
  end
end
.... the @misha value from Game_Siletrea can now be changed from another class....!

There's a bit more too it than just this. We need to do stuff that lets that whole '$game_siletrea' thingie to work. But once we do, this is how you can make @instance variables from one class work within other classes.

Okay, Now refresh us on what you learned about Classes, Parent Classes, Child Classes and Supers. And what did you learn about local variables and parameters, the last thing I was discussing....
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 - 12-28-2018, 05:30 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,916 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,864 04-29-2010, 03:07 PM
Last Post: Getsuga_kawaii
   Scripting I think spazfire 7 8,984 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: