Super simple question

Started by mroedesigns, August 29, 2011, 01:38:23 pm

Previous topic - Next topic

mroedesigns

I'm a complete noob when it comes to RGSS, so I have probably the easiest question ever.  :^_^':

I'm making a common event for small messages (ie 'Quest Received'). I want it to show a picture which is simple, and then display the message text ($game_variables[4]) centered over that picture. I don't want to use the 'show text' option because I just want it to appear for about 3-5 seconds and then disappear on its own.

Thanks in advance for your help :D


LivingstoneIPresume

Here's a reply from another noob- see what you can do with it... :D
To draw text in a bitmap:
bitmap.draw_text(x, y, width, height, string)

Bitmap syntax can be found here: http://save-point.org/showthread.php?tid=2901

mroedesigns

Well here's what I have so far.

Spoiler: ShowHide
#------------------------------------------------------------------
# A very simple script used to display quick messages to the
# player without requiring any input.
#
# Call with QuickMessage.new('message')
#
#------------------------------------------------------------------

class QuickMessage
 
  attr_accessor :message
  attr_accessor :image
 
   def initialize(message)
     
     @message = message
     
     @image = Sprite.new
     @image.bitmap = RPG::Cache.picture("message")
     
     @image.x = 100
     @image.y = 100
     
     self.contents = Bitmap.new(width - 32, height - 32)
     self.contents.draw_text(0,0,20,20, @message)
     
   end

end


But i don't know how to center the text, or how to make it all disappear after a certain amount of time.

LivingstoneIPresume

Here's how centering is usually done:
cw = text.width / 2
ch = text.height /2
Set the bitmap's x to 240 - cw and y to 320 - ch

Sorry I can't give a definite answer or syntax here, I am a newbie.

stripe103

August 29, 2011, 04:47:53 pm #4 Last Edit: August 29, 2011, 04:52:56 pm by stripe103
Quote from: LivingstoneIPresume on August 29, 2011, 04:18:48 pm
Here's how centering is usually done:
cw = text.width / 2
ch = text.height /2
Set the bitmap's x to 240 - cw and y to 320 - ch

To be more exact;
object_x = (parent_width / 2) - (object_width / 2)
object_y = (parent_height / 2) - (object_height / 2)
Where object is the thing you want to center and parent is the thing you want to center it in.

And if you don't already have the answer by tomorrow, I'll help you with the timing and disposing, when I'm not on my phone.

G_G

Look through my achievements script. While Stripe has the answer to centering text, you can still look at how I used pop up images for achievements. I made the script so it would be "global". As in you can gain achievements from any scene and see the pop up.
http://forum.chaos-project.com/index.php/topic,3330.0.html

stripe103

August 30, 2011, 11:43:34 am #6 Last Edit: August 30, 2011, 11:46:05 am by stripe103
Okay, so I'm not sure it's the most optimal way of making timed things in scripting, but the way I usually make things is quite simple

You need to make a new variable in the initialize function named for example frames and then just have this code in your update function
if frames == 20 # Or any other value you want
  # Do things
  frames = 0  # Reset the frame count since the action is already done.
else
  frames += 1  # Add one to the framecount.
end

A very simple script that counts up one each time it's is run and when it's at the framecount set, it will do what it should and then reset the variable so it can run again.
It would be preferred to have it in another if that checks if the thing you need timed is actually showing so that it don't always count up and when the timed thing shows, it's at 19 or something, so it will only show in one frame.

Like I said, there is probably better solutions, but this is one of them.

mroedesigns

It's erroring out on lines 24 and 25 for some reason. I called it with QuickMessage.new('Items Recieved')

Spoiler: ShowHide

mroedesigns

I still havent been able to figure this out. I'm using the script that I posted further up, but I haven't figured out what's causing the error. I looked up some RGSS scripting stuff on google, and that's how it told me to show images, but obviously I'm doing something wrong.

Twb6543

In the code you posted above you didn't define the width or the height of the message box, which I guess is causing the problems due to the "undefined local variable or method 'width' for #<QuickMessage:0x3a123d8>"
Line, The other problems may be a result of the undefined variables or may be due to another problem with the script.

But seeing as you haven't posted your current code I can't be sure if it the problem.
If you put a million monkeys at a million keyboards, one of them will eventually write a Java program.
The rest of them will write Perl programs.

G_G

Change this
class QuickMessage

To
class QuickMessage < Window_Base

Then under def initialize put
super(x here, y here, width here, height here)

Put whatever for those variables, its what defines the window.

mroedesigns

errors out with 'super call outside of method' on line 11 ( super(142, 32, 422, 34) )

Spoiler: ShowHide
#------------------------------------------------------------------
# A very simple script used to display quick messages to the
# player without requiring any input.
#
# Call with QuickMessage.new('message')
#
#------------------------------------------------------------------

class QuickMessage < Window_Base
 
  super(142, 32, 422, 34)
 
  attr_accessor :message
  attr_accessor :image
 
   def initialize(message)
     
     @message = message
     
     @image = Sprite.new
     @image.bitmap = RPG::Cache.picture("message")
     
     @image.x = 142
     @image.y = 32
     
     self.contents = Bitmap.new(422, 34)
     self.contents.draw_text(142,32,20,20, @message)
     
   end
   
end

ForeverZer0

That one's pretty self-explanatory.  Calls to the super have to be within methods. 

The parent class has to have a method defined by the same name, as well.  That's what the "super" call does.  It calls the method of the parent class.   
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

AngryPacman

I.e.,
Spoiler: ShowHide
#------------------------------------------------------------------
# A very simple script used to display quick messages to the
# player without requiring any input.
#
# Call with QuickMessage.new('message')
#
#------------------------------------------------------------------

class QuickMessage < Window_Base
 
 attr_accessor :message
 attr_accessor :image

  def initialize(message)

    super(142, 32, 422, 34)

    @message = message
   
    @image = Sprite.new
    @image.bitmap = RPG::Cache.picture("message")
   
    @image.x = 142
    @image.y = 32
   
    self.contents = Bitmap.new(422, 34)
    self.contents.draw_text(142,32,20,20, @message)
   
  end
 
end

G_G's a silly boy.

mroedesigns

It's  not giving me any errors now but it's not displaying the text either  :huh:

Spoiler: ShowHide
class QuickMessage < Window_Base
 
  attr_accessor :message
  attr_accessor :image
   
   def initialize(messagetxt)
     
     super(142, 32, 422, 34)
     
     @image = Sprite.new
     @image.bitmap = RPG::Cache.picture("message")
     
     @image.x = 142
     @image.y = 32
     
     @message = messagetxt
     
     self.contents = Bitmap.new(422, 34)
     self.contents.draw_text(142, 32, 40, 40, @message)
     
   end
   
end

ForeverZer0

September 04, 2011, 03:37:48 pm #15 Last Edit: September 04, 2011, 03:42:37 pm by ForeverZer0
Spoiler: ShowHide
module QuickMessage
 
 def self.show(message, timer)
   b = Bitmap.new(1, 1)
   width = b.text_size(message).width + 32
   b.dispose
   window = Window_Base.new((640 - width) / 2, 208, width, 64)
   window.contents = Bitmap.new(width - 32, 32)
   window.contents.draw_text(0, 0, width - 32, 32, message, 1)
   loop {
     Graphics.update
     Input.update
     timer -= 1
     break if timer == 0
     break if Input.trigger?(Input::C)
   }
   Input.update
   window.dispose
 end
end


Call with "QuickMessage.show("TEXT HERE")
The window will auto-size and center on the screen, end exit when the player presses the confirm button.


EDIT: 
I didn't notice you wanted it to go away on its own, so I added that function.  Call with either the above mentioned call which will default to 4 seconds, or call with "QuickMessage.show("TEXT HERE", FRAMECOUNT)".  It will disappear on its own after the number of frames has passed.  If you don't want the player to be able to exit the window themselves, remove the "Input.update" and "break if Input.trigger?(Input::C)" lines in the code.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

mroedesigns

September 04, 2011, 03:44:18 pm #16 Last Edit: September 04, 2011, 03:45:54 pm by mroedesigns
That's a great script and I'll probably look through it to see if I can solve my issue, but I need it in a certain size/position, not centered in the screen just within the image. And I want it to go away automatically, which it does thanks to either the Blizz-ABS or RMX-OS refresh.

Edit :: You edited your post right after I replied :p

ForeverZer0

September 04, 2011, 03:59:19 pm #17 Last Edit: September 04, 2011, 04:04:01 pm by ForeverZer0
Its a simple edit if you want it to be the same size and location all the time.  Delete the first 3 lines of the method, and change the arguments of the Window_Base.new() to static values.

EDIT:
Like this...
Spoiler: ShowHide
module QuickMessage
 
  def self.show(message, timer = 160)
    window = Window_Base.new(96, 208, 448, 64)
    window.contents = Bitmap.new(416, 32)
    window.contents.draw_text(0, 0, 416, 32, message, 1)
    loop {
      Graphics.update
      Input.update
      timer -= 1
      break if timer == 0
      break if Input.trigger?(Input::C)
    }
    Input.update
    window.dispose
  end
end
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

mroedesigns

Is there any way to do this without using the windowskin basically? All I want to do was show an image with some text over it. I don't want the normal message box behind it, that's why I'm using the image.

Also, I don't mean to be a huge pain if I am, and I really appreciate the help.  :)

G_G

See if this works.
module QuickMessage
 
  def self.show(message, timer = 160)
    bitmap = RPG::Cache.picture("picture here")
    window = Window_Base.new(96, 208, bitmap.width, bitmap.height)
    window.contents = Bitmap.new(416, 32)
    window.contents.blt(0, 0, bitmap, 0, 0, bitmap.width, bitmap.height)
    window.contents.draw_text(0, 0, 416, 32, message, 1)
    loop {
      Graphics.update
      Input.update
      timer -= 1
      break if timer == 0
      break if Input.trigger?(Input::C)
    }
    Input.update
    window.dispose
  end
end