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.

A couple questions involving scripting

Star

Sponsor

Hey guys, I'm having a little trouble trying to figure out a few things in scripting.

One being I don't know how to make an "enter" or a page break when creating a text string. This is involving the help_window.set_text.

Then there's a further problem then that. If my description that I want has a really long description that I want to go over to the next line, it just condenses it's size instead.

Another thing. How can you call a display on what elements a skill has?

I want something like

def draw_element(element,x,y)
elem = RPG::Cache.picture(element.name)
cw = elem.width
ch = elem.height
src_rect = Rect.new(0, 0, cw, ch)
self.contents.blt(x , y, elem, src_rect)
end


@skill = current_skill
for i in 0...@actor.skill[@skill].element_set
element = $data_skills[@actor.skills[@skill]].element
x = i * 24
y = 100
draw_element(element, x, y)

to work, but I can't even find an idea in the default scripts of how to make it work.

Thanks for your help guys!
 
First of all, you can't just make line breaks into text... you need a method like Trick's awesomely helpful draw_wrapped_text method, which looks like this:
Code:
class Bitmap

  #-------------------------------------------------------------------------

  def draw_wrap_text(x, y, width, height, text, lineheight)

    strings = text.split

    strings.each do |string|

      word = string + ' '

      word_width = text_size(word).width

      x, y = 0, y + lineheight if x + word_width > width

      self.draw_text(x, y, word_width, height, word)

      x += word_width

    end

  end

  #-------------------------------------------------------------------------

end
Usage should be pretty self-explanatory.


Now for the elements, it's a bit of a more difficult manner, as elements aren't based on a class, e.g. Element. Instead, they are data within $data_system, meaning to address their names, you'd have to do something like this:
Code:
p $data_system.elements[element_id]


That being said, please use code tags for your code examples next time, the similar names aren't coincidential ;)
 

Star

Sponsor

Thank's Blue. Don't worry, I know about the tags, I just didn't think such a small code was necessary for tag usage and it felt weird when you said that. :P

Code:
class Bitmap

  #--------------------------------------------------------------------------

  # * Dummy Bitmap 

  #--------------------------------------------------------------------------

  @@dummy = Bitmap.new(32, 32)

  attr_accessor :dummy

  #--------------------------------------------------------------------------

  #   Name      : Text Size

  #   Info      : Gets text size based off dummy bitmap

  #   Author    : SephirothSpawn

  #   Call Info : One Argument, a String

  #--------------------------------------------------------------------------

  def Bitmap.text_size(text)

    return @@dummy.text_size(text)

  end

  #-------------------------------------------------------------------------

  #   Name      : Draw Wrapped Text

  #   Info      : Draws Text with Text Wrap

  #   Author    : Trickster

  #   Call Info : Five Arguments

  #               Integer X and Y, Define Position

  #               Integer Width, defines the width of the text rectangle

  #               Integer Height, defines the height of the text

  #               String Text, Text to be drawn

  #   Modified  : Brew.  Add 'p' for line breaks

  #-------------------------------------------------------------------------

  def draw_wrap_text(x, y, width, height, text)

    # Get Array of Text

    strings = text.split

    # Run Through Array of Strings

    strings.each do |string|

      # Get Word

      word = string + ' '

      # If /n move to next line

      if string == " /n"

        x = 0

        y += height

        next

      end

      # Get Word Width

      word_width = text_size(word).width

      # If Can't Fit on Line move to next one

      x, y = 0, y + height if x + word_width > width

      # Draw Text Memory

      self.draw_text(x, y, word_width, height, word)

      # Add To X

      x += word_width

    end

  end

end

 

That's the true text_wrap method, it needs a dummy class for it to work properly. I got it working like Cuban Missiles, and now I can wrap my text around everything.

Still working at the element thing, although I might give up on it since I got the text wrap method working at least.
 
Are you just looking to have the element name printed? Cause if so, go check out the icon drawing stuff in GTBS for the status window. it uses an icon based on the name of the element/state you are inflicted with or will use etc.
 
Star":2szctqvs said:
That's the true text_wrap method, it needs a dummy class for it to work properly. I got it working like Cuban Missiles, and now I can wrap my text around everything.
While the method I posted above is not the exact one from the MACL, but instead a simplified version of myself, it still works perfectly fine, stand-alone, and definately without the use of any kind of dummy bitmap... so, if you didn't get 'mine' to work (which is kind of what I think you're saying), tell me what's not working, and I'll tell you how to fix it. But in general, it should be plug-and-play.
 

Star

Sponsor

Gubid":2luad0bi said:
Are you just looking to have the element name printed? Cause if so, go check out the icon drawing stuff in GTBS for the status window. it uses an icon based on the name of the element/state you are inflicted with or will use etc.
Well. I was really looking for how to define what elements a skill, weapon, or armor has in the database, and then display a custom icon for it, but I coudln't figure out how to identify the which ones had elements associated to them.

word_width = text_size(word).width

Came up no method error at text_size, but it's all ancient history now. My guess is that Text_size needed to have a dummy def class for it to work. *shrugs*
 
text_size is a method of bitmap. So you have to create a 1,1 bitmap or something then do that.. and dispose of it when done.

Also,
elements = $data_weapons[@actor.weapon_id].element_set
Its just an array, so do as you want after that.

Works the same way with skills and items. Athough, attack and defense element sets are different. Just check the help file for what their names are.
 

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