Syndicate content

Words on screen

46 posts / 0 new
Last post
Offline
Mega TownieSuper TownieGreat TownieTownie
Joined: 15 Jan 2010
Words on screen

I just need a little push in the right direction...
I know that there is a line of scripting I can do that will make words appear on the screen, for my HUD.
It's something along the lines of self.contents.draw_text(0,0,24,24,"hi") but I just get an error when I do that.
It would also be nice if someone can tell me where to put this in the script (Sticking Out Tongue)

Thanks! Laugh

egg_dragon's picture
Offline
Ultra TownieMega TownieSuper TownieGreat TownieTownie
Joined: 23 Oct 2005

You would need to have that text drawn inside of a window. Check your inbox Wink

meustrus's picture
Offline
RoyalÜber TownieUltra TownieMega TownieSuper TownieGreat TownieTownie
Joined: 18 Jan 2006

Just create a window like so:

$window = Window_Base.new(x, y, width, height)
$window.contents = Bitmap.new(width - 32, height - 32)
$window.draw_text(4, 0, width - 40, height - 32, "Text")

Replace "x" "y" "width" and "height" with the correct dimensions.

If you don't want a window background, you could do a similar thing with a plain Sprite:

$hud = Sprite.new
$hud.x = x
$hux.y = y
$hud.bitmap = Bitmap.new(width, height)
$hud.bitmap.draw_text(0, 0, width, height, "Text")

If you want the text centered or right aligned, first make sure the "x" and "width" are set to the entire bounding box it will be centered in (to center the screen, use a width of 640). The :draw_text function has an optional argument after the text that is {0: Left; 1: Center; 2: Right}.

Offline
Mega TownieSuper TownieGreat TownieTownie
Joined: 15 Jan 2010

Thanks guys!
Soz Egg, i'll use mews way because I don't won't the window seen, but I get an error though.

$hud = Sprite.new
$hud.x = 36
$hud.y = 36
$hud.bitmap = Bitmap.new(36, 36)
$hud.bitmap.draw_text(0, 0, 36, 36, $game_variables[16])

When I write that in I get an error on line 5 about nil class for []

but when I write

$hud = Sprite.new
$hud.x = 36
$hud.y = 36
$hud.bitmap = Bitmap.new(36, 36)
$hud.bitmap.draw_text(0, 0, 36, 36, 'text'[16])

It works fine! Angry

Any ideas what I'm doing wrong?

Oh, and what do I write to call the script, just "$hud" ?

meustrus's picture
Offline
RoyalÜber TownieUltra TownieMega TownieSuper TownieGreat TownieTownie
Joined: 18 Jan 2006

You misunderstand, that script goes in a Call Script inside an event. Then, I think, your first code should work.

Offline
Mega TownieSuper TownieGreat TownieTownie
Joined: 15 Jan 2010

Like this?

But I get this error!

Any ideas mew or egg?

egg_dragon's picture
Offline
Ultra TownieMega TownieSuper TownieGreat TownieTownie
Joined: 23 Oct 2005

Karl, it should be:

$game_variables[x].to_s

That will fix it.

Offline
Mega TownieSuper TownieGreat TownieTownie
Joined: 15 Jan 2010

ooooh...
THANKYOU!!!! Laugh Laugh
So if I want to put more words or variables into the hud, do I have to make a different sprite/box everytime?

egg_dragon's picture
Offline
Ultra TownieMega TownieSuper TownieGreat TownieTownie
Joined: 23 Oct 2005

No. You can add more strings to that:

$hud.bitmap.draw_text(0, 0, 36, 36, $game_variables[16].to_s + "99 bottles of beer on the wall")

Just use the '+' sign between each string. If you want them on different lines, you would need to add another "$hud.bitmap.draw_text" line, but I don't know if that requires a new sprite. If you're using the window method, you only need one window but for the sprite method I'm not sure...

Offline
Mega TownieSuper TownieGreat TownieTownie
Joined: 15 Jan 2010

ooooh
Your sooo awesome at this Egg!!! Laugh Laugh
As soon as we move to Drupal, your gonna have so many points from me! Sticking Out Tongue

egg_dragon's picture
Offline
Ultra TownieMega TownieSuper TownieGreat TownieTownie
Joined: 23 Oct 2005

Shweeet!

Offline
Mega TownieSuper TownieGreat TownieTownie
Joined: 15 Jan 2010

Hehe, I could do with a tad more help Sticking Out Tongue
How do I change the colour of the font?
I've tried "$hud.font.color = red" (Of course with the "s) but i think I'm doing something wrong...
Funnily enough, I'm not getting the error about the 'red' part; i get the error about the '.font' part, but I have no idea whatsoever Frown
Help would be really... helpful! Laugh

egg_dragon's picture
Offline
Ultra TownieMega TownieSuper TownieGreat TownieTownie
Joined: 23 Oct 2005

Since it's a sprite you're using, I'm not sure how to change the color of it. If you were just drawing text in a window you would use ".font.color". Maybe the sprite would be something like ".hue = red"? I'm sure Meu can tell you, but it looks like you guys are about to kill him in Wolf Hunt, so whether he WANTS to tell you is a different matter Sticking Out Tongue

Offline
Mega TownieSuper TownieGreat TownieTownie
Joined: 15 Jan 2010

You... don't... know...?
OMG!!!!
Oh well, I suppose you can't know everything, anyway, you've been a great help so far and haven't failed me.
Is there a way I make the window scripting, but somehow set the windows background thingy to 0 opacity?

egg_dragon's picture
Offline
Ultra TownieMega TownieSuper TownieGreat TownieTownie
Joined: 23 Oct 2005
$window.opacity = 0

Try that.

Offline
Mega TownieSuper TownieGreat TownieTownie
Joined: 15 Jan 2010

.hue actually works, but you get an error regarding the "red" I'm guessing I need to put numbers there or something...?
I tried "crisis color/colour" but I still get errors, what should I type in..?

(oh, and for the window idea, I get errors when I try to make the simplest windows, can you give me a little example? Sticking Out Tongue)

Offline
Townie
Joined: 13 Jul 2010

woo, script kiddies.. How fun.. any nice xp friendly tutorials on xp friendly ruby on rails (assuming this is the primary language used).

Also, Any good guides for peeps coming from other languages.. I mean I can probably find that.. these posts gave some insight to how RPG maker handles scripting, but when should the scripts be used in the events VS.. under scripts? from what I can tell, the scripting editor appears to work for the structure of the development software, declaring global functions for use and formatting windows and such.. Pardon my vagueness, My learning up to this part have been purely bookworm, Non functional programs mostly copy pasta from books.. different languages, vax 3.2, python, C, CGI scripting vaguely, most work done in MS-DOS scripting. Choice.com was meh best friend.

Uhh-huh, yeah., I think I get it.

egg_dragon's picture
Offline
Ultra TownieMega TownieSuper TownieGreat TownieTownie
Joined: 23 Oct 2005

Generally you'd want to call the scripts from an event when you're trying to achieve something temporary (such as a special window that only gets used a small handful of times throughout the game) and even then only when the code is small--the "call sript" window only allows for about 8 or 10 lines of code.

Offline
Townie
Joined: 13 Jul 2010

why doesn't this work?

text = "Hello"
text.class
=> String

$hud = Sprite.new
$hud.x = 36
$hud.y = 36
$hud.bitmap = Bitmap.new(36, 36)
$hud.bitmap.draw_text(0, 0, 36, 36,
$text)

It's wierd not sure I completely understand the way to set the variable type, or how to call it.
I can understand the .to_s as converting to a string.. but why not a int? how is a int declared?

Uhh-huh, yeah., I think I get it.

Offline
Mega TownieSuper TownieGreat TownieTownie
Joined: 15 Jan 2010

Indigo, I would really prefer it if you made your own thread, instead of kind of butting into mine...
Egg, any ideas about changing the colour?

egg_dragon's picture
Offline
Ultra TownieMega TownieSuper TownieGreat TownieTownie
Joined: 23 Oct 2005

Indigo, try

@text = "Hello"
$hud = Sprite.new
$hud.x = 36
$hud.y = 36
$hud.bitmap = Bitmap.new(36, 36)
$hud.bitmap.draw_text(0, 0, 36, 36, 
@text)

Karl, did you try replacing the color names with numbers?

Offline
Mega TownieSuper TownieGreat TownieTownie
Joined: 15 Jan 2010

Yup, and I get errors left, right and center. I've been trying$hud.hue (100, 0, 0, 0) Because that's what it kinda looks like if you do an event "change picture color tone". Any other ideas?

egg_dragon's picture
Offline
Ultra TownieMega TownieSuper TownieGreat TownieTownie
Joined: 23 Oct 2005

Here ya go, Karl:

$hud = Sprite.new
$hud.x = 36
$hud.y = 36
$hud.bitmap = Bitmap.new(36, 36)
$hud.bitmap.font.color = Color.new(255, 255, 255, 255)
$hud.bitmap.draw_text(0, 0, 36, 36, "text")

Just adjust the numbers in "Color.new" to get the color you want. Smile

Offline
Mega TownieSuper TownieGreat TownieTownie
Joined: 15 Jan 2010

Nope... Frown
I copied and pasted what you wrote into the script call box, and got the syntax error. After deleting "$hud.bitmap.font.color = Color.new(255, 255, 255, 255)" It worked Frown

Offline
Super TownieGreat TownieTownie
Joined: 25 Jan 2010

Try using this... text_color(2) in substitution of this part: Color.new(255, 255, 255, 255)

I know it doesn't assign a direct color from RGB, but the 2 draws off from something I do not know about...
I have also only tested and successfully applied its use on self.contents type of stuff within the code...so I do not know if this would apply to your hud coding.

If the colors are the same in RMXP as it is in RMVX, 2 should be red and 3 is green. 0, is white, the default text color I'm guessing.

There's lots more colors, but I haven't experimented enough with all the different colors to memorize them.

If applied to what I'm saying, I'm intending the code to look like this:

$hud = Sprite.new
$hud.x = 36
$hud.y = 36
$hud.bitmap = Bitmap.new(36, 36)
$hud.bitmap.font.color = text_color(2)
$hud.bitmap.draw_text(0, 0, 36, 36, "text")

I've never worked with anything but window text before. So I'm just hoping this can apply to a bitmap...or sprite...

Offline
Mega TownieSuper TownieGreat TownieTownie
Joined: 15 Jan 2010

Nearly!
Well, we're getting closer at least, I got the error attached from trying $hud.bitmap.font.color = 2 after getting errors from your way, but according to the error, it understands the "$hud.bitmap.font.color = "part, we just need the right codeing to get the colour...
hmm...

Offline
Super TownieGreat TownieTownie
Joined: 25 Jan 2010

Did you try this? It's gotta be exactly what's in the code bracket below.

$hud.bitmap.font.color = text_color(2)

Or did you already try that, but accidentally put a typo in the code?

Offline
Mega TownieSuper TownieGreat TownieTownie
Joined: 15 Jan 2010

I GOT IT!!! Laugh Laugh Laugh
$hud.bitmap.font.color.set(255, 0, 0)
It was mentioned in the timer part of the script!
Laugh Yum

Offline
Super TownieGreat TownieTownie
Joined: 25 Jan 2010

Congratulations Laugh

Offline
Mega TownieSuper TownieGreat TownieTownie
Joined: 15 Jan 2010

Okay, well thanks to you two geneusis, I;ve got the hud up!!! Laugh Laugh

note the colorful numbers! Laugh

Offline
Super TownieGreat TownieTownie
Joined: 25 Jan 2010

:Drool: Can't wait for the demo of your game!

Your welcome for the thank you, though Egg_Dragon totally gets full creds for his attempts to solve this problem. Wink

BUT meustrus gets full creds for providing the base code to work off of in the first place.

Offline
Mega TownieSuper TownieGreat TownieTownie
Joined: 15 Jan 2010

I really should have said THREE geneusis, since meu was the one who gave me the scripted prite box in the first place, lol :lol3:

egg_dragon's picture
Offline
Ultra TownieMega TownieSuper TownieGreat TownieTownie
Joined: 23 Oct 2005

Hey now. My coloring method worked for me, Karl, so what did you do wrong? Hehe, j/k. Actually, I'm not kidding. So what was your syntax error? That means you typed something incorrectly or left out a bracket or comma or parenthesis or something silly like that.

UPDATE: So here's the skinny--using the call script command sucks sometimes, because if a line of code is broken into two lines it won't always work. That was the case this time. If you copy and paste my code above, it won't work because the color line is broken into 2 lines. What you need to do is, turn the coloring part of the code into 2 separate lines like this:

$hud.bitmap.font.color = 
Color.new(255, 255, 255, 255)

As long as the "Color.new" is on the same lines as the numbers, the program will read it correctly. This WILL work. The entire code will look like this:

$hud = Sprite.new
$hud.x = 36
$hud.y = 36
$hud.bitmap = Bitmap.new(36, 36)
$hud.bitmap.font.color = 
Color.new(255, 255, 255, 255)
$hud.bitmap.draw_text(0, 0, 36, 36, 
"text")

And if it doesn't, use your delete, backspace and enter keys to make it look like that! Sticking Out Tongue

Offline
Mega TownieSuper TownieGreat TownieTownie
Joined: 15 Jan 2010

Ahh, wel there we go!
But I suppose it isn't necassary anymore, because I found the other way... It does seem odd how they have to ways to script the same thing though... Confused

egg_dragon's picture
Offline
Ultra TownieMega TownieSuper TownieGreat TownieTownie
Joined: 23 Oct 2005

If you use the numbers, though, you have a much broader range of colors to choose from Wink

Offline
Mega TownieSuper TownieGreat TownieTownie
Joined: 15 Jan 2010

Not really much more, only to make lighter and darker colors...
I don't mind egg, but I'm very glad you helped me! Sticking Out Tongue
I never would have sorted this mess out without you guys!!! Laugh

egg_dragon's picture
Offline
Ultra TownieMega TownieSuper TownieGreat TownieTownie
Joined: 23 Oct 2005

Actually no, not just lighter and darker colors. There is a limit to the "text" colors that RMXP stores by default. You can see what colors those are by typing up a text window event command and doing "\c[x]" where x = the color you want, then press F2 to view your text window. Using the RGB numbers gives you far more. But hey, details details... Wink

meustrus's picture
Offline
RoyalÜber TownieUltra TownieMega TownieSuper TownieGreat TownieTownie
Joined: 18 Jan 2006

I see you've all figured this out. You set the font color with $hud.bitmap.font.color = Color.new(red, green, blue, alpha) or with $hud.butmap.font.color.set(red, green, blue, alpha). There are problems if a Call Script statement goes over more than one line. $hud.hue can be treated similarly to $hud.bitmap.font.color, except that if you change the hue after you draw the text it will change the color, while the color the font was drawn in persists.

The normal_color, crisis_color, disabled_color, system_color, and text_color(n) colors are only available inside window classes. If you have a window $window, you can get them with $window.normal_color etc.

Offline
Mega TownieSuper TownieGreat TownieTownie
Joined: 15 Jan 2010

Ahh, well there we go :Eyesroll:
And Egg, I can use four digits in my color scripting as well.
It will work the same for

$hud = Sprite.new
$hud.x = 0
$hud.y = -10
$hud.bitmap = Bitmap.new(100, 50)
$hud.bitmap.font.color.set(255, 0, 
0, 0)
$hud.bitmap.draw_text(0, 0, 100, 50, 
$game_variables[16].to_s + "/1000")

AND

$hud = Sprite.new
$hud.x = 0
$hud.y = -10
$hud.bitmap = Bitmap.new(100, 50)
$hud.bitmap.font.color.set(255, 0, 
0)
$hud.bitmap.draw_text(0, 0, 100, 50, 
$game_variables[16].to_s + "/1000")

The only difference been a ", 0". So I can make just as many colors Sticking Out Tongue

egg_dragon's picture
Offline
Ultra TownieMega TownieSuper TownieGreat TownieTownie
Joined: 23 Oct 2005

Oh, I thought you were using the "text_color" method. Nevermind Sticking Out Tongue

Offline
Mega TownieSuper TownieGreat TownieTownie
Joined: 15 Jan 2010

Nope, the text color method doesn't work silly! Sticking Out Tongue
That's only for windows!

Offline
Townie
Joined: 15 May 2010

Aaaalright... since I'm not really making progress on seeing it handled by "real" scripts, I've returned to the common event system too this night. Does any of you guys know how to display the variable always as 2 (or for hp in your case 4) digits? even if it is smaller? its supposed to fill up with 0 in front... if you get what i mean

HP 1000/1000, you get hit and are like 999/1000 - i want 0999/1000 to be returned Smile

Think it has something to do with this

text = sprintf("%02d:%02d", min, sec) <- %02d seems to say its always two digits (another example one can take from the timer... i can so see where you got some of your hud ideas karl :lol3: )

but how do i get it in this line?

$time.bitmap.draw_text(0, 0, 150, 100, $game_variables[0001].to_s + " Uhr " + $game_variables[0002].to_s)

since I don't even know what the .to_s (ok maybe i do: to string?) means, i once again cant figure it out myself Sticking Out Tongue

Grand List of Console Role Playing Cliches Had such a hilarious time following Yamitami's link... it needs to be spread! Somehow I seem to have played every single one of those games refered to Grin

My Pr

Offline
Mega TownieSuper TownieGreat TownieTownie
Joined: 15 Jan 2010

Conditional branches probably
If variable is equal to 1000, show $time.bitmap.draw_text(0, 0, 150, 100, $game_variables[0001].to_s + " Uhr " + $game_variables[0002].to_s)
If below or equal to 999 $time.bitmap.draw_text(0, 0, 150, 100, "0" + $game_variables[0001].to_s + " Uhr " + $game_variables[0002].to_s)
If below or equal to 99 $time.bitmap.draw_text(0, 0, 150, 100, "00" + $game_variables[0001].to_s + " Uhr " + $game_variables[0002].to_s)
If below or equal to 9 $time.bitmap.draw_text(0, 0, 150, 100, "000" + $game_variables[0001].to_s + " Uhr " + $game_variables[0002].to_s)

That would probably work! Sticking Out Tongue

Offline
Townie
Joined: 15 May 2010

You're a fox (Hope that proverb's international and I'm not insulting you :lol3: ).
But let's face it: might work, but it's ugly Sticking Out Tongue

ps: can anyone spot a mistake here? Im either drunk or rpg maker xp acts reaaally strange.

$mp.bitmap.draw_text(0,0,150,100, "MP " + $game_variables[0007].to_s + "/" + $game_variables[0008].to_s)

mp is the name of the sprite/bitmap, [0007] is actual sp, [0008] maxsp. Results in syntax error... though i checked it a 1000 times, and it looks just like the other hud parts

$hp.bitmap.draw_text(0,0,150,100, "HP " + $game_variables[0005].to_s + "/" + $game_variables[0006].to_s)

which work Gasp

hmmm if i use variable 0006 for testing it works as well as soon as i just change it to 8 its syntax :Drool:

edit: ops sry, yes i got draw_text, not draw.text Grin
gonna try with print later tonight - still strange, for hp/maxhp and the variables getting those values it works perfectly, for sp too... just not for maxsp oO

Grand List of Console Role Playing Cliches Had such a hilarious time following Yamitami's link... it needs to be spread! Somehow I seem to have played every single one of those games refered to Grin

My Pr

meustrus's picture
Offline
RoyalÜber TownieUltra TownieMega TownieSuper TownieGreat TownieTownie
Joined: 18 Jan 2006

Try this:

text = sprintf("HP %04d/%04d", $game_variables[5], $game_variables[6])
$hp.bitmap.draw_text(0,0,150,100,text)
text = sprintf("MP %04d/%04d", $game_variables[7], $game_variables[8])
$mp.bitmap.draw_text(0,0,150,100,text)

Remember that it's draw_text, not draw.text

Offline
Townie
Joined: 15 May 2010

Ok, all done, even some battle system parts are in there, because with a decent Hud i will remove the main menu. Looks the following.

LEVEL 68/99 HP 033/647 MP 015/187
WEAPON 01 SPELL 01
00 UHR 00

All based on those sprites "we" worked out related to variables. Everything updated in parallel process.

My "new" question concerns the second line of the hud:

- How do I display a certain String, if a variable has a certain value... if you get what i mean.
I know, you could do with hundreds of conditional branches here once again. But I'm sure it's possible by defining the "value" of variable 0009 as a string. $game_variables[9] is the weapon variable in my case. This is how it is assigned by the program.

@Conditional Branch: [Daniel] is [Sword] equipped
Control Variables[0009:Weapon] = 1
Else
@Conditional Branch: [Daniel] is [Axe] equipped
Control Variables[0009:Weapon] = 2
Else
@Conditional Branch: [Daniel] is [Bow] equipped
Control Variables[0009:Weapon] = 3
Branch End
Branch End
Branch End

This is how the sprite is displayed:

Script:
$weapon = Sprite.new
$weapon.x = 200
$weapon.y = 0
$weapon.bitmap = Bitmap.new(150, 100)
$weapon.font.color.set(180, 180, 180)
text = sprintf("WEAPON 02%d", $game_variables[9])
$weapon.bitmap.draw_text(0, 0, 150, 100, text)

and instead of displaying "WEAPON 01" or "WEAPON 02" or "WEAPON 03"
i would love "WEAPON Sword" for Variable 9 = 1
"WEAPON Axe" for Variable 9 = 2
"WEAPON Bow" for Variable 9 = 3

Grin

i thought you might declare that somehow

If $game_variables[9] == 1
$game_variables[9] = "Sword"
else if $game_variables[9] == 2
$game_variables[9] = "Axe"
else if $game_variables[9] == 3
$game_variables[9] = "Bow"

could that work? and how do i insert the variable correctly afterwards? because if its a digit, its marked by %02d / %03d / %04d for insertion. whats the link for a string-variable Grin

Grand List of Console Role Playing Cliches Had such a hilarious time following Yamitami's link... it needs to be spread! Somehow I seem to have played every single one of those games refered to Grin

My Pr

Topic locked

Who's online

There are currently 1 user and 0 guests online.

Online users