1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. Don’t forget to sign up for the Hive Cup. There’s a 555 EUR prize pool. Sign up now!
    Dismiss Notice
  4. The Hive Workshop Cup contest results have been announced! See the maps that'll be featured in the Hive Workshop Cup tournament!
    Dismiss Notice
  5. The results are out! Check them out.
    Dismiss Notice
  6. The poll for Hive's 12th Concept Art Contest is up! Go cast your vote for your favourite genie!
    Dismiss Notice
  7. The raddest synthwave tracks were chosen - Check out our Music Contest #12 - Results and congratulate the winners!
    Dismiss Notice
  8. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

UI: Change Lumber Text

Discussion in 'JASS/AI Scripts Tutorials' started by Tasyen, May 29, 2019.

Tags:
  1. Tasyen

    Tasyen

    Joined:
    Jul 18, 2010
    Messages:
    1,298
    Resources:
    16
    Tools:
    2
    Maps:
    2
    Spells:
    7
    Tutorials:
    4
    JASS:
    1
    Resources:
    16
    This is an example showing how to change the shown text in the lumber box at the top of the screen, using jass.

    First we need to know how the frame showing the lumber text is called. It is called "ResourceBarLumberText".
    After one knows the frames name, one gets access to it by using BlzGetFrameByName.
    BlzGetFrameByName loads a frame using a string (name) and an integer (creationcontext).
    After one got the frame one uses BlzFrameSetText on it, with the text wanted to be shown.

    Code (vJASS):

    function ChangeLumberTextBox takes nothing returns nothing
       local framehandle fh = BlzGetFrameByName("ResourceBarLumberText" , 0) //Load "ResourceBarLumberText" with creationcontext 0
       call BlzFrameSetText(fh , "Lumber") //Change the text to Lumber
       set fh = null
    endfunction
     

    After using/calling ChangeLumberTextBox() your screen should look kinda like that.
    One should use ChangeLumberTextBox() after map init finished.
    LumberChanged.jpg

    As soon the local player needs to update the lumber text, your custom text will be lost.

    One could also change the text shown in the other resourceboxes, By using a different name inside BlzGetFrameByName.
    • For Gold use: "ResourceBarGoldText"
    • Lumber is named "ResourceBarLumberText"
    • Food is "ResourceBarSupplyText"
    • For the box showing the Upkeep level (no, low, high) use "ResourceBarUpkeepText"
    Using BlzGetFrameByName for only one player can desync the game, hence it is recommended to set it to variable before the GetLocalPlayer Block and using that variable inside the Local Block.
     

    Attached Files:

    Last edited: Jul 5, 2019
  2. purparisien

    purparisien

    Joined:
    Jul 17, 2011
    Messages:
    518
    Resources:
    17
    Models:
    2
    Icons:
    4
    Maps:
    11
    Resources:
    17
    I like your tutorial. Is it possible to change the Upkeep text this way ? I dont want to use it with the food upkeep.
     
  3. Tasyen

    Tasyen

    Joined:
    Jul 18, 2010
    Messages:
    1,298
    Resources:
    16
    Tools:
    2
    Maps:
    2
    Spells:
    7
    Tutorials:
    4
    JASS:
    1
    Resources:
    16
    Yes, one has to use a different name. "ResourceBarUpkeepText", 0
    This 4 String-Frames are defined in "UI/FrameDef/UI/ResourceBar.fdf"
     
  4. purparisien

    purparisien

    Joined:
    Jul 17, 2011
    Messages:
    518
    Resources:
    17
    Models:
    2
    Icons:
    4
    Maps:
    11
    Resources:
    17
    Thanks you. I nearly finish it. I would like to know how we can switch to another name. Indeed I did this and it doesnt work. What do I miss ?
     

    Attached Files:

    • 1.JPG
      1.JPG
      File size:
      38.8 KB
      Views:
      134
    • 2.JPG
      2.JPG
      File size:
      36.8 KB
      Views:
      130
  5. Tasyen

    Tasyen

    Joined:
    Jul 18, 2010
    Messages:
    1,298
    Resources:
    16
    Tools:
    2
    Maps:
    2
    Spells:
    7
    Tutorials:
    4
    JASS:
    1
    Resources:
    16
    in image 2 there is no local framehandle fh in the gui trigger.
     
  6. purparisien

    purparisien

    Joined:
    Jul 17, 2011
    Messages:
    518
    Resources:
    17
    Models:
    2
    Icons:
    4
    Maps:
    11
    Resources:
    17
    Indeed it works. Thanks. Furthemore, it can be displayed for only one player without crash
     
  7. PurgeandFire

    PurgeandFire

    Code Moderator

    Joined:
    Nov 11, 2006
    Messages:
    7,427
    Resources:
    18
    Icons:
    1
    Spells:
    4
    Tutorials:
    9
    JASS:
    4
    Resources:
    18
    Useful. I'm going to go ahead and approve it, but some feedback for the future if you want to make some updates:
    • I think it'd be useful to go ahead and post the 4 other strings from ResourceBar.fdf in the main post (for upkeep/gold/whatever). I imagine a lot of people who would find this useful would also want to edit the other resource bars.
    • You don't have to null framehandle variables--only variables that have
      extends agent
      in common.j need to be nulled for the reference count bug
    • If you're writing it as a function, I would make it take the string as a parameter. It'll make it more dynamic.
      Code (vJASS):
      function ChangeLumberTextBox takes string text returns nothing
         local framehandle frame = BlzGetFrameByName("ResourceBarLumberText", 0)
         call BlzFrameSetText(frame, text)
      endfunction
    • Do you know if we need to use
      BlzDestroyFrame(...)
      on these frames? I don't know if they create a new object each time we call BlzGetFrameByName or not.
    • A lot of GUI users have been checking out your tutorials. In the past, a lot of tutorials did it your way where they wrote a function and told users to put it in the map header, but GUI users tend to run into all sorts of issues trying to get it to fit their needs. For small functions like this, I'd recommend giving an example inline like this:
    • Example
      • Events
        • Time - Elapsed game time is 0.00 seconds
      • Conditions
      • Actions
        • Set LumberText = "Custom Text Here"
        • Custom script: call BlzFrameSetText(BlzGetFrameByName("ResourceBarLumberText", 0), udg_LumberText)
     
  8. Tasyen

    Tasyen

    Joined:
    Jul 18, 2010
    Messages:
    1,298
    Resources:
    16
    Tools:
    2
    Maps:
    2
    Spells:
    7
    Tutorials:
    4
    JASS:
    1
    Resources:
    16
    They do not create an new object each time, through they can somehow desync when used in a GetLocalPlayer Block. Also its not recommented to Destroy String Texture frames, cause it crashes the game (hopefully that changes). If one uses BlzDestroyFrame the real frame is destroyed not only the reference (variable).

    Added a list with their names.
    I uploaded a map that has such a GUI-trigger, if you don't mind.
     
  9. PurgeandFire

    PurgeandFire

    Code Moderator

    Joined:
    Nov 11, 2006
    Messages:
    7,427
    Resources:
    18
    Icons:
    1
    Spells:
    4
    Tutorials:
    9
    JASS:
    4
    Resources:
    18
    Awesome, that is perfect! Thanks for following-up!