Hi all,
I know to many of you this is probably really basic stuff, but I've been trying to learn RGSS3 so I can start implementing some graphical ideas for battles and menus. Right now I'm following DP3's tutorials and messing around with Scene_Battle, but even the simplest of stuff (which he still explains very well) is getting the best of me. So I'll start with something simple.
Basically I'm trying to figure out when and how I can access attributes of the class Game_Enemy, which (allegedly) contains data for its id, stats, weaknesses, and so on. More specifically, I'm trying to show a graphic when an enemy acquires a certain state; in other words, I'm using Game_Enemy, Game_Battler, Game_Troop, and Spriteset_Battle to determine whether an enemy has a state, and then to show a graphic.
So I started by inserting a Game_Battler method into Victor's Element States script which runs a method to check for states to add when an enemy is hit by a certain element (this is because the state is acquired when an enemy is hit by a weakness, or "result.resist > 1.0").
The conditional is where my own code begins. It's pretty simple: If the script is adding a state and that state happens to be 17 (the state I'm checking for), execute another method in Game_Battler:
Also very simple: If boolean create_cutin is not already true and the instance of Game_Enemy isn't dead (since we don't want to show the graphic if an enemy is dead), make the boolean true.
I then went into Game_Troop to access this boolean:
More of the same... I think. If that instance of Game_Battler (Game_Enemy in this case) return variable create_cutin as true, then it saves a variable that can be accessed via "attr_reader," which will be used in Scene_Battle to determine whether or not to draw the graphic.
So I could keep going on a bit about how I made a new viewport in Spriteset_Battle in order to show the graphic and so on, but for now I'm concerned with the fact that I received an error for the Game_Troop method (undefined variable or method "enemy") which can't possibly be true since the variable is defined right here on line 68:
So why the heck does it return this error? I'm also confused as to when I can reference a class like "enemy.method." Does it have to be a universal variable or can it be run at any time as long as the class is running? Also since all the battle graphics are drawn through Spriteset_Battle, how can I connect Game_Troop and Spriteset_Battle so that the latter runs a method when a Game_Troop method returns true?
I think I'm understanding the idea of syntax, but the ability to connect classes and have them function alongside each other really confuses me. Hopefully someone can help me understand this!
I know to many of you this is probably really basic stuff, but I've been trying to learn RGSS3 so I can start implementing some graphical ideas for battles and menus. Right now I'm following DP3's tutorials and messing around with Scene_Battle, but even the simplest of stuff (which he still explains very well) is getting the best of me. So I'll start with something simple.
Basically I'm trying to figure out when and how I can access attributes of the class Game_Enemy, which (allegedly) contains data for its id, stats, weaknesses, and so on. More specifically, I'm trying to show a graphic when an enemy acquires a certain state; in other words, I'm using Game_Enemy, Game_Battler, Game_Troop, and Spriteset_Battle to determine whether an enemy has a state, and then to show a graphic.
So I started by inserting a Game_Battler method into Victor's Element States script which runs a method to check for states to add when an enemy is hit by a certain element (this is because the state is acquired when an enemy is hit by a weakness, or "result.resist > 1.0").
Code:
def element_state_change(id)
regexp = /<ELEMENT STATE (ADD|REMOVE) #{id}: (\d+)(?:, *(\d+)%)?>/i
get_all_notes.scan(regexp) do
type = $1.downcase
id = $2.to_i
rate = $3 ? $3.to_i / 100.0 : 1
type == "add" ? add_state_normal(id) : remove_state(id) if rand < rate
if type == "add" && id == 17
phoe_create_cutin_graphic
end
end
end
The conditional is where my own code begins. It's pretty simple: If the script is adding a state and that state happens to be 17 (the state I'm checking for), execute another method in Game_Battler:
Code:
def phoe_create_cutin_graphic
if !create_cutin == true && !dead?
create_cutin = true
else
create_cutin = false
end
Also very simple: If boolean create_cutin is not already true and the instance of Game_Enemy isn't dead (since we don't want to show the graphic if an enemy is dead), make the boolean true.
I then went into Game_Troop to access this boolean:
Code:
def determine_cutin_eligibility
if enemy.create_cutin == true
@cutin_eligibility = true
else
@cutin_eligibility = false
end
end
More of the same... I think. If that instance of Game_Battler (Game_Enemy in this case) return variable create_cutin as true, then it saves a variable that can be accessed via "attr_reader," which will be used in Scene_Battle to determine whether or not to draw the graphic.
So I could keep going on a bit about how I made a new viewport in Spriteset_Battle in order to show the graphic and so on, but for now I'm concerned with the fact that I received an error for the Game_Troop method (undefined variable or method "enemy") which can't possibly be true since the variable is defined right here on line 68:
Code:
enemy = Game_Enemy.new(@enemies.size, member.enemy_id)
So why the heck does it return this error? I'm also confused as to when I can reference a class like "enemy.method." Does it have to be a universal variable or can it be run at any time as long as the class is running? Also since all the battle graphics are drawn through Spriteset_Battle, how can I connect Game_Troop and Spriteset_Battle so that the latter runs a method when a Game_Troop method returns true?
I think I'm understanding the idea of syntax, but the ability to connect classes and have them function alongside each other really confuses me. Hopefully someone can help me understand this!