Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Actor State Color Conflict

Status
Not open for further replies.

Culex

Member

Goal
I am trying to modify the def draw_actor_state method under Window_Base to show a change in color when the actor has a state greater than 1 (Knockout) in the database.

Here is what it looked like before modification (default):
Code:
  def draw_actor_state(actor, x, y, width = 120)
    text = make_battler_state_text(actor, width, true)
    self.contents.font.color = actor.hp == 0 ? knockout_color : normal_color
    self.contents.draw_text(x, y, width, 32, text)
  end
...and here is what it looks like with user modification:
Code:
def draw_actor_state(actor, x, y, width = 120)
    text = make_battler_state_text(actor, width, true)
    self.contents.font.color = actor.hp == 0 ? knockout_color :
    [COLOR=Red]actor.states > 1 ? text_color(5) :[/COLOR] normal_color
    self.contents.draw_text(x, y, width, 32, text)
  end
Problem
My previous modification in red is where this error occurs:
Code:
Script 'Window_Base' line 192: NoMethodError occured.

undefined method '>' for []:Array
I'm not sure how I would define that or fix the problem otherwise. Thanks in advance!
 
The problem is the states part. It returns an array, (of all the states the actor is inflicted with), and you're trying to do a comparison (with the > method) on an integer. Now, either you want to check the length of the states array, in which case you would use actor.states.length > 1, or you want to find out if the states array includes an integer which is greater than one. If that is the case, then I would advise you totally scrap that mess of ? : structures and get a proper set of if statemets. To check if the array includes a number greater than 1 use this:
Code:
self.contents.font.color = normal_color
for i in actor.states
  self.contents.font.color = text_color(5) if i > 1
end
 
Please note that you do not need to report to get the resolved tag, we will do this automatically, so there is no need to report your topics

This topic has been resolved. If Culex or any other users have any questions or further problems regarding this topic, please create a new thread about them.

Thank you!
 
Status
Not open for further replies.

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top