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

Discussion in 'RGSSx Script Support' started by omarproductions, Oct 14, 2017.

  1. omarproductions

    omarproductions Villager Member

    Messages:
    5
    Likes Received:
    0
    First Language:
    English
    Primarily Uses:
    RMVXA
    Hey guys, I wanna know how do I have a variable show in a text window using scripts?
     
    #1
  2. Kes

    Kes Global Moderators Global Mod

    Messages:
    19,154
    Likes Received:
    9,820
    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.

    I've moved this thread to RPGMaker VX Ace. Please be sure to post your threads in the correct forum next time. Thank you.



    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.
     
    #2
  3. omarproductions

    omarproductions Villager Member

    Messages:
    5
    Likes Received:
    0
    First Language:
    English
    Primarily Uses:
    RMVXA
    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
     
    #3
  4. Kes

    Kes Global Moderators Global Mod

    Messages:
    19,154
    Likes Received:
    9,820
    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?

    Moving this now to RGSSx Script Support

     
    #4
  5. Shaz

    Shaz Veteran Veteran

    Messages:
    36,911
    Likes Received:
    10,849
    Location:
    Australia
    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.
     
    #5
  6. omarproductions

    omarproductions Villager Member

    Messages:
    5
    Likes Received:
    0
    First Language:
    English
    Primarily Uses:
    RMVXA
    Yes
    what I'm getting is Score: █[0001] instead of Score: 0
     
    #6
  7. Sixth

    Sixth Veteran Veteran

    Messages:
    2,086
    Likes Received:
    756
    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.
     
    #7
  8. omarproductions

    omarproductions Villager Member

    Messages:
    5
    Likes Received:
    0
    First Language:
    English
    Primarily Uses:
    RMVXA
    I'm getting an error say wrong number of arguments (6 for 9).
     
    Last edited: Oct 15, 2017
    #8

Share This Page