Count characters in player name and reduce length if exceeding #

Danis[h]

New Member
Reaction score
19
Okay, so I've made a multiboard in which each player's name has to fit.. So obviously to becomes a problem with column width if the player has a very lengthy name.

So what I would like to do is to phrase the name. Or rather count up each character in the string (if possible) and then cut it off at a given number of characters..

example.. character limit for player names is set to 8
Player 5 is named "SomethingStupid" then I would like for my trigger to check his name, see that it is 15 characters long and then change it to display as
"Somethin..."

Result being that his name has been cut down in length to 8 characters with a tripple dot appended to it.


Nevermind.. the solution was very very simple..
Trigger:
  • Name Policing
    • Events
      • Map initialization
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 6, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Length of (Name of (Player((Integer A))))) Greater than 8
            • Then - Actions
              • Set NameLabel[(Integer A)] = ((Substring((Name of (Player((Integer A)))), 1, 8)) + ...)
            • Else - Actions
              • Set NameLabel[(Integer A)] = (Name of (Player((Integer A))))
 
Trigger:
  • Untitled Trigger 001
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set LB_MaxLength = 8
      • For each (Integer A) from 1 to 12, do (Actions)
        • Loop - Actions
          • Set TempInt = (Length of (Name of (Player((Integer A)))))
          • Set LB_Names[(Integer A)] = (Name of (Player((Integer A))))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • TempInt Greater than LB_MaxLength
            • Then - Actions
              • Set LB_Names[(Integer A)] = ((Substring(LB_Names[(Integer A)], 1, LB_MaxLength)) + ...)
            • Else - Actions


This should do it, but it does not set the player names. You need a few variables but I guess you are experienced enough to know how to make them.

Edit:
Your setup works better, but I was trying to add something to the system what you didn't requested. Meaning..
For example, 8 is the maximum + 3 making it 11. If a length is 11 the name will stay intact. If it isn't it is adjusted and cut down to 8.
Just posted the code anyways.
 
Trigger:
  • Untitled Trigger 001
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set LB_MaxLength = 8
      • For each (Integer A) from 1 to 12, do (Actions)
        • Loop - Actions
          • Set TempInt = (Length of (Name of (Player((Integer A)))))
          • Set LB_Names[(Integer A)] = (Name of (Player((Integer A))))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • TempInt Greater than LB_MaxLength
            • Then - Actions
              • Set LB_Names[(Integer A)] = ((Substring(LB_Names[(Integer A)], 1, LB_MaxLength)) + ...)
            • Else - Actions


This should do it, but it does not set the player names. You need a few variables but I guess you are experienced enough to know how to make them.

Edit:
Your setup works better, but I was trying to add something to the system what you didn't requested. Meaning..
For example, 8 is the maximum + 3 making it 11. If a length is 11 the name will stay intact. If it isn't it is adjusted and cut down to 8.
Just posted the code anyways.

Thanks for taking time to do this for me, and you're right about the 11 characters total thing. Although aesthetically I think having two people with trippe-dots by the end of their names and then one which goes to 11 without any dots will looks odd, since his letters will extend further than the rest have been allowed to.
 
Thanks for taking time to do this for me, and you're right about the 11 characters total thing. Although aesthetically I think having two people with trippe-dots by the end of their names and then one which goes to 11 without any dots will looks odd, since his letters will extend further than the rest have been allowed to.
There is a system in vJass for this issue, with it you can determine the width of an entire string, instead of counting characters.

Hold on and give me a few minutes to find it, perhaps you have the ability to make a GUI version out of it, but I suggest just custom calls for it anyways.

Edit:
http://www.wc3c.net/showthread.php?t=97876&highlight=string+width
 
There is a system in vJass for this issue, with it you can determine the width of an entire string, instead of counting characters.

Hold on and give me a few minutes to find it, perhaps you have the ability to make a GUI version out of it, but I suggest just custom calls for it anyways.

I am familiar enough with JASS to read and understand a system (for the most part) Although being lazy it's often easier to just use GUI. Since you don't have to type stuff.

Also, I'm making a Tower Defense. So GUI is adequate.
 
Thanks for taking time to do this for me, and you're right about the 11 characters total thing. Although aesthetically I think having two people with trippe-dots by the end of their names and then one which goes to 11 without any dots will looks odd, since his letters will extend further than the rest have been allowed to.

just change your condition to length > 11 but keep the substring 1-8, this way you would ignore people with nick 11 characters or less
(just in case you havent done this, lol)
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • The Helper The Helper:
    News portal has been retired. Main page of site goes to Headline News forum now
  • The Helper The Helper:
    I am working on getting access to the old news portal under a different URL for those that would rather use that for news before we get a different news view.
  • Ghan Ghan:
    Easily done
    +1
  • The Helper The Helper:
    https://www.thehelper.net/pages/news/ is a link to the old news portal - i will integrate it into the interface somewhere when i figure it out
  • Ghan Ghan:
    Need to try something
  • Ghan Ghan:
    Hopefully this won't cause problems.
  • Ghan Ghan:
    Hmm
  • Ghan Ghan:
    I have converted the Headline News forum to an Article type forum. It will now show the top 20 threads with more detail of each thread.
  • Ghan Ghan:
    See how we like that.
  • The Helper The Helper:
    I do not see a way to go past the 1st page of posts on the forum though
  • The Helper The Helper:
    It is OK though for the main page to open up on the forum in the view it was before. As long as the portal has its own URL so it can be viewed that way I do want to try it as a regular forum view for a while
  • Ghan Ghan:
    Yeah I'm not sure what the deal is with the pagination.
  • Ghan Ghan:
    It SHOULD be there so I think it might just be an artifact of having an older style.
  • Ghan Ghan:
    I switched it to a "Standard" article forum. This will show the thread list like normal, but the threads themselves will have the first post set up above the rest of the "comments"
  • The Helper The Helper:
    I don't really get that article forum but I think it is because I have never really seen it used on a multi post thread
  • Ghan Ghan:
    RpNation makes more use of it right now as an example: https://www.rpnation.com/news/
  • The Helper The Helper:
  • The Helper The Helper:
    What do you think Tom?
  • tom_mai78101 tom_mai78101:
    I will have to get used to this.
  • tom_mai78101 tom_mai78101:
    The latest news feed looks good
  • The Helper The Helper:
    I would like to see it again like Ghan had it the first time with pagination though - without the pagination that view will not work but with pagination it just might...
  • The Helper The Helper:
    This drink recipe I have had more than a few times back in the day! Mind Eraser https://www.thehelper.net/threads/cocktail-mind-eraser.194720/

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top