12-28-2018, 05:30 AM
(This post was last modified: 12-28-2018, 05:31 AM by DerVVulfman.)
Sleepy SIletrea? XD Really?
*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.
.... the @misha value from Game_Siletrea can only be used in Game_Siletrea
.... the @misha value from Game_Siletrea can be read 'BY' Scene_Siletrea.
.... 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....
(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
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
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
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....