Hey guys, I wanna know how do I have a variable show in a text window using scripts?
[HELP] How display a variable in a text window using scripts.
RGSSx Script Support'Scripts' is the section where members can post scripts they have written which they wish to share with the community.
Moved to: RPGMaker VX Ace
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.
Moved to: RPGMaker VX Ace
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
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?
Moderator note: Moving this now to RGSSx Script Support
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?
Moderator note: Moving this now to RGSSx Script Support
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.
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.
Yes
what I'm getting is Score: █[0001] instead of Score: 0
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:
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:
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.
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"
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).
Original thread: https://forums.rpgmakerweb.com/threads/help-how-display-a-variable-in-a-text-window-using-scripts.85688/