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
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
Well here's what I have so far.
#------------------------------------------------------------------
# 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.
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.
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.
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
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.
It's erroring out on lines 24 and 25 for some reason. I called it with
QuickMessage.new('Items Recieved')(http://img839.imageshack.us/img839/5879/errorzor.png)
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.
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.
Change this
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.
errors out with 'super call outside of method' on line 11 (
super(142, 32, 422, 34) )
#------------------------------------------------------------------
# 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
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.e.,
#------------------------------------------------------------------
# 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
It's not giving me any errors now but it's not displaying the text either :huh:
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
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.
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
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...
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
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. :)
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
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.
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.
Then you're not passing text to the method. What string are you using?
QuickMessage.new('Items Received')
That script call:
(http://dl.dropbox.com/u/20787370/Temp/temp1.png)
Result (just made some dummy picture with rendered clouds for example)
(http://dl.dropbox.com/u/20787370/Temp/temp2.png)
What other scripts are you using?
In order;
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.
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.