Chaos Project

RPG Maker => RPG Maker Scripts => Script Troubleshooting => Topic started by: mroedesigns on August 29, 2011, 01:38:23 pm

Title: Super simple question
Post by: mroedesigns on August 29, 2011, 01:38:23 pm
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

Title: Re: Super simple question
Post by: LivingstoneIPresume on August 29, 2011, 02:42:39 pm
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
Title: Re: Super simple question
Post by: mroedesigns on August 29, 2011, 03:25:59 pm
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.
Title: Re: Super simple question
Post by: 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

Sorry I can't give a definite answer or syntax here, I am a newbie.
Title: Re: Super simple question
Post by: stripe103 on August 29, 2011, 04:47:53 pm
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.
Title: Re: Super simple question
Post by: G_G on August 29, 2011, 06:01:53 pm
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
Title: Re: Super simple question
Post by: stripe103 on August 30, 2011, 11:43:34 am
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.
Title: Re: Super simple question
Post by: mroedesigns on August 30, 2011, 01:15:20 pm
It's erroring out on lines 24 and 25 for some reason. I called it with QuickMessage.new('Items Recieved')

Spoiler: ShowHide
(http://img839.imageshack.us/img839/5879/errorzor.png)
Title: Re: Super simple question
Post by: mroedesigns on August 31, 2011, 01:52:03 pm
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.
Title: Re: Super simple question
Post by: Twb6543 on September 01, 2011, 04:59:00 am
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.
Title: Re: Super simple question
Post by: G_G on September 01, 2011, 08:25:48 am
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.
Title: Re: Super simple question
Post by: mroedesigns on September 02, 2011, 01:35:49 am
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
Title: Re: Super simple question
Post by: ForeverZer0 on September 02, 2011, 02:23:46 am
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.   
Title: Re: Super simple question
Post by: AngryPacman on September 02, 2011, 03:51:51 am
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

Title: Re: Super simple question
Post by: mroedesigns on September 04, 2011, 03:17:19 pm
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
Title: Re: Super simple question
Post by: ForeverZer0 on September 04, 2011, 03:37:48 pm
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.
Title: Re: Super simple question
Post by: mroedesigns on September 04, 2011, 03:44:18 pm
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
Title: Re: Super simple question
Post by: ForeverZer0 on September 04, 2011, 03:59:19 pm
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
Title: Re: Super simple question
Post by: mroedesigns on September 04, 2011, 04:49:05 pm
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.  :)
Title: Re: Super simple question
Post by: G_G on September 04, 2011, 05:00:45 pm
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
Title: Re: Super simple question
Post by: ForeverZer0 on September 04, 2011, 05:02:41 pm
Spoiler: ShowHide
class QuickMessage < Sprite
 
 def initialize(message, timer = 160)
   super()
   self.bitmap = RPG::Cache.picture("message")
   self.x = 32
   self.y = 32
   # I don't know what the pic your using is, so you'll have to adjust the
   # values of the x, y here.
   self.bitmap.draw_text(0, 0, self.bitmap.width, 32, message, 1)
   loop {
     Graphics.update
     Input.update
     timer -= 1
     break if timer == 0
     break if Input.trigger?(Input::C)
   }
   Input.update
   self.dispose
 end
end


This is easier.  Same syntax, but use QuickMessage.new instead of QuickMessage.show
You need to change the x and y of the sprite, and the coordinates where the text is drawn maybe, but it will be self-centering.
Title: Re: Super simple question
Post by: mroedesigns on September 04, 2011, 05:47:26 pm
now it's doing the same thing as before, no error but no text either. And for some reason it shows a blank text box as well. Like if you did an event showtext and left it empty, it just pops up and then goes away when the image does.
Title: Re: Super simple question
Post by: ForeverZer0 on September 04, 2011, 06:09:51 pm
Then you're not passing text to the method.  What string are you using?
Title: Re: Super simple question
Post by: mroedesigns on September 05, 2011, 01:34:13 am
QuickMessage.new('Items Received')
Title: Re: Super simple question
Post by: ForeverZer0 on September 05, 2011, 02:12:05 am
That script call:
Spoiler: ShowHide
(http://dl.dropbox.com/u/20787370/Temp/temp1.png)


Result (just made some dummy picture with rendered clouds for example)
Spoiler: ShowHide
(http://dl.dropbox.com/u/20787370/Temp/temp2.png)


What other scripts are you using?
Title: Re: Super simple question
Post by: mroedesigns on September 05, 2011, 01:47:06 pm
In order;

Spoiler: ShowHide
RMX-OS Options
RMX-OS Script
RMX-OS Versioning
Global Variables and Switches for RMX-OS
Single Instance
Actor Class Mod
Quick Message Script
Quest Log
- Quest Logs RMX-OS Controller
Equipment Requirements
Passive Skills
A.T.E.S.
Global Day & Night for RMX-OS
Blizz ABS
Visual Equipment for Blizz-ABS
Blizz ABS RMX-OS Controller
Ring Menu
RMX-OS Main


Single Instance is just a script to keep players from opening multiple game sessions at once. The Actor Class mod is a script that replaces all instances of the actor name with the rmx-os network username.
Title: Re: Super simple question
Post by: ForeverZer0 on September 05, 2011, 02:51:25 pm
I don't anything there that would prevent the script from working.  The only thing that I know that really COULD even screw it up would be something that alters the Sprite or Bitmap class.  Also there is no reason a blank text box is being displayed.  Somewhere, you have another script that is doing some screwy stuff.  If you want, PM me a demo of your game and I'll look at it.