[HELP] How display a variable in a text window using scripts.

omarproductions

Villager
Member
Joined
Oct 14, 2017
Messages
5
Reaction score
1
First Language
English
Primarily Uses
RMVXA
Hey guys, I wanna know how do I have a variable show in a text window using scripts?
 

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,299
Reaction score
11,718
First Language
English
Primarily Uses
RMVXA
'Scripts' is the section where members can post scripts they have written which they wish to share with the community.
[move]RPGMaker VX Ace[/move]

I am moving this to the general Support section as this is not a script issue. When you say 'script' I think you mean 'event'. It's important to keep the distinction clear because otherwise things can get very confusing.

In the text box, type
\V[n]
where n = the number of the variable you want to show up.
If you let your mouse hover over the text box, you will get a descriptive list of all the commands like this that you can type in.
 

omarproductions

Villager
Member
Joined
Oct 14, 2017
Messages
5
Reaction score
1
First Language
English
Primarily Uses
RMVXA
'Scripts' is the section where members can post scripts they have written which they wish to share with the community.
[move]RPGMaker VX Ace[/move]

I am moving this to the general Support section as this is not a script issue. When you say 'script' I think you mean 'event'. It's important to keep the distinction clear because otherwise things can get very confusing.

In the text box, type
\V[n]
where n = the number of the variable you want to show up.
If you let your mouse hover over the text box, you will get a descriptive list of all the commands like this that you can type in.

Here's my code:
class Your_Window < Window_Base

def initialize(x,y,w,h)
super
draw_text(0,0,contents.width,line_height,"Score: \V[0001]")
end

end
DataManager.init
def updates
Graphics.update
Input.update
$window.update
end

$window = Your_Window.new(0,0,100,100)
updates while true
 

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,299
Reaction score
11,718
First Language
English
Primarily Uses
RMVXA
Ah, so to be clear, this isn't to show a variable in the text box = dialogue box, but in its own text box?
If you want help with a script you're writing, it helps to have that info, plus the script, in the opening post. Otherwise just saying "text box" will lead most people to assume you mean the dialogue box.

Just a thought about your code - are you sure you should have all those leading zeros in your variable id?

[mod]Moving this now to RGSSx Script Support[/mod]
 

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
40,782
Reaction score
14,015
First Language
English
Primarily Uses
RMMV
You're doing some really weird, funky stuff there.

Why are you calling DataManager.init? Why are you calling the updates? The parent class will do all of that for you.

Where is the window being instantiated?

I think how to add a variable is the least of your problems with the code you've got.

I suggest you take a lot of time to examine how the existing windows work. If this is something that you want to see while the map is open, check out the Gold window that shows when you put \G into a text box.
 

omarproductions

Villager
Member
Joined
Oct 14, 2017
Messages
5
Reaction score
1
First Language
English
Primarily Uses
RMVXA
Ah, so to be clear, this isn't to show a variable in the text box = dialogue box, but in its own text box?
If you want help with a script you're writing, it helps to have that info, plus the script, in the opening post. Otherwise just saying "text box" will lead most people to assume you mean the dialogue box.

Just a thought about your code - are you sure you should have all those leading zeros in your variable id?

[mod]Moving this now to RGSSx Script Support[/mod]
Yes
what I'm getting is Score: █[0001] instead of Score: 0
 

Sixth

Veteran
Veteran
Joined
Jul 4, 2014
Messages
2,180
Reaction score
834
First Language
Hungarian
Primarily Uses
RMVXA
The method draw_text can not process the message code you wanted to use.
Only draw_text_ex can do that the way you wanted it to do.

Even so, never use leading zeros in any code you write.

Aside from this, using this format in any string:
Code:
"some text #{code_to_evaluate} some more text"
Will run the code you enter between the curly brackets and will display the result of that code as part of the string.
Knowing this, you can use:
Code:
draw_text(x, y, w, h, "Score: #{$game_variables[id]}", alignment)

I guess, you use the other part of your code to test the window, but still, the window doesn't need to be updated at all, since there is nothing happening in it.
The text is drawn right at the creation of it, and aside from that, it just sits on your screen idly.

There are better ways of testing your visuals. For example, make your own testing scene class, and test everything you want there.
If you want to test these things right at the beginning of the game (without entering the title menu and from there into the game), just replace the starting scene class run in the first_scene_class method of the SceneManager module to your test scene. This way you can test multiple things at once too if needed.
 

omarproductions

Villager
Member
Joined
Oct 14, 2017
Messages
5
Reaction score
1
First Language
English
Primarily Uses
RMVXA
The method draw_text can not process the message code you wanted to use.
Only draw_text_ex can do that the way you wanted it to do.

Even so, never use leading zeros in any code you write.

Aside from this, using this format in any string:
Code:
"some text #{code_to_evaluate} some more text"
Will run the code you enter between the curly brackets and will display the result of that code as part of the string.
Knowing this, you can use:
Code:
draw_text(x, y, w, h, "Score: #{$game_variables[id]}", alignment)

I guess, you use the other part of your code to test the window, but still, the window doesn't need to be updated at all, since there is nothing happening in it.
The text is drawn right at the creation of it, and aside from that, it just sits on your screen idly.

There are better ways of testing your visuals. For example, make your own testing scene class, and test everything you want there.
If you want to test these things right at the beginning of the game (without entering the title menu and from there into the game), just replace the starting scene class run in the first_scene_class method of the SceneManager module to your test scene. This way you can test multiple things at once too if needed.

I'm getting an error say wrong number of arguments (6 for 9).
 
Last edited:

Latest Threads

Latest Posts

Latest Profile Posts

Holy cow... work is demanding and I'm back in college. I'm kind of scared of my dad right now after the incident, but at least I don't live with him all the time. Anyway, working on Fandom Scouts and my FNAF character set. The FNAF sprites are actually going to be used in the game... unfortunately the enemy sprites are FNAF World traces, so no sharing those.
The honeymoon period is over with Cyberpunk 2077, It sadly doesnt live up to the hype, pretty graphics arent everything (especially when I cant even do something as simple as changing the radio station over!). Replaying Breath of the wild has reminded me what a good game really looks like, plus that one has good glitches!....
Ami


Maybe...a Drinkable Water Plant or something?
Who would have thought making interesting birds would be so difficult/fun?

Randomly spawning anywhere on map (sometimes even flying), having a chance of landing on a different spot on map when flying. Also chance of flying off screen if spooked/sees the player

I think I got it!

Forum statistics

Threads
107,680
Messages
1,031,390
Members
139,801
Latest member
IsaacRPG
Top