New account registration is temporarily disabled.

[VX ACE] MINOR WINDOW_BATTLELOG ISSUE

Posts

Pages: 1
Hey guys, I'm trying to determine which type of object (enemy or actor) a combatant is and what their ID is whenever they use a skill (the idea's to determine those things and then use them to access a note tag that defines them as male, female or neutral, so their battle messages can be properly personalized - "Alex fires his pistol" rather than "Alex fires their pistol" or simply "Alex attacks").

I've run into somewhat of a problem here, though. The code below tells me that enemy objects are of the Game_Enemy type when I print subject.class, though the if clause doesn't return true. It does return true whenever an actor uses a skill but only because it detects their class as being of the RPG::Class variety - apparently, class functions differently for actors than it does for everybody else.

Any idea on how I can properly distinguish between friend and foe? Hope you'll be willing to bear with me and help me out. I've got some experience with Lua and C but I'm bloody new to Ruby and the VX Ace's pre-existing code in general.


class Window_BattleLog < Window_Selectable

#--------------------------------------------------------------------------
# * (Title)
#--------------------------------------------------------------------------

def display_use_item(subject, item)
if item.is_a?(RPG::Skill)
print "subject.class: "
puts subject.class
if subject.class.is_a?(Game_Enemy)
puts "Enemy object detected."
end
if subject.class.is_a?(RPG::Class)
puts "Class object detected."
end
$game_variables[2] = "placeholder"
$game_variables[3] = "placeholder"
$game_variables[4] = "placeholder"
add_text(subject.name + item.message1)
unless item.message2.empty?
wait
add_text(item.message2)
end
else
add_text(sprintf(Vocab::UseItem, item.name, subject.name))
end
end

end
Well subject is referring to Game_Actor and Game_Enemy scripts. So you can do this instead:


if subject.is_a?(Game_Actor)
p "Actor"
else
p "Enemy"
end
That's what I figured too, but it doesn't work. puts (or print) subject.class results in either RPG::Class:(address) or Game_Enemy being printed into my console; is_a? can detected RPG::Class but not Game_Enemy (or Game_Actor, for that matter).
Well not really sure what you are trying to do with subject.class or why you are trying to see if it's and RPG:: since the RPG::'s are constants so the subject should never equal it.
Anyways this is my full code for doing this:

if subject.is_a?(Game_Actor)
gender = subject.actor.gender
else
gender = subject.enemy.gender
end


and the note tags for gender:

#==============================================================================
# ** RPG::Actor
#==============================================================================
class RPG::Actor
def gender
if @gender.nil?
if @note =~ /<(?:gender):(.*)>/i
@gender = $1
else
@gender = "M"
end
end
@gender
end
end
#==============================================================================
# ** RPG::Actor
#==============================================================================
class RPG::Enemy
def gender
if @gender.nil?
if @note =~ /<(?:gender):(.*)>/i
@gender = $1
else
@gender = "M"
end
end
@gender
end
end


all that's left is doing a statement with gender to change the text.
author=Quasi

if subject.is_a?(Game_Actor)
gender = subject.actor.gender
else
gender = subject.enemy.gender
end



Apologies if I've been unclear about this in my previous posts. It's this bit right here that I can't seem to make work, at least not as a part of Window_BattleLog (or display_use_item, to be precise).

is_a?(Game_Enemy) never returns true. is_a?(Game_Actor) doesn't return true either; in addition, attempting to print subject.class when the subject in question should be an actor results in some weird override kicking in and producing the actor's database class (that is, Monk, Paladin, ...) which is the only thing that is_a? actually returns true for (thus the if clause in my OP, obviously it's not gonna be in what I'm actually trying to put together).

I'm hoping that someone might be able to help me figure out why is_a?(Game_Enemy) (or Game_Actor) doesn't work because I'm at a total loss about that.

It's not some custom script I'm using either by the way, already checked that.
That is weird since it worked fine for me. You can also try the built in check that I forgot about lol.

if subject.actor?

elsif subject.enemy?

end


As for the subject.class, subject alone is the class (it's Game_Actor or Game_Enemy), and when you add .class your reading that classes def for class, which happens to be the database class ( wow that sounds confusing lol. ) which is why I was asking why you were doing subject.class.is_a? when it should just be subject.is_a?
author=Quasi
As for the subject.class, subject alone is the class (it's Game_Actor or Game_Enemy), and when you add .class your reading that classes def for class, which happens to be the database class ( wow that sounds confusing lol. ) which is why I was asking why you were doing subject.class.is_a? when it should just be subject.is_a?

Uh...

Well, wow. Turns out I'm just objectively terrible at reading comprehension - I didn't actually realize you cut out the .class bit in the sample code you've provided in your earlier posts, doing that did the trick (and you nicely explained why in that quoted post). Curse you, sleep deprivation.

Thanks for the help, and for bearing with me, me not picking up that bit must've made things much more difficult for you. Everything's working fine now. Cheers!
Pages: 1