line break in strings

Status
Not open for further replies.
Level 3
Joined
Feb 8, 2010
Messages
34
I want to make a string variable, which I will display as a game message. But I want the game message to be more than one line. Is that possible to do this with a single variable?
 
Level 9
Joined
May 22, 2009
Messages
276
you might try |n, even tho this might not work, if it doesn't just use a variable for each sentence

e.g.:

String= Hello player |nYou're now playing this game |nThis is the third message
Game- Show message: String

in game this would be:

Hello Player
You're now playing this game
This is the third message
 
Level 3
Joined
Feb 8, 2010
Messages
34
just use a variable for each sentence

That wouldn't work for me either. I want a simple trigger like:

  • Events
  • Player - Player 1 (Red) Selects a unit
  • Actions
  • Set string[1] = hello
  • Set string[2] = hello again
  • Set unit[1] = peasant 0001
  • Set unit[2] = peasant 0002
  • For each (Integer A) from 1 to 2, do (Actions)
  • Loop - Actions
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • (Triggering unit) Equal to unit[(Integer A)]
      • Then - Actions
        • Game - Display to Player Group - Player 1 (Red) the text: string[Integer A]
because I'll have a lot of units and strings ;D
 
Level 9
Joined
Aug 2, 2008
Messages
219
|n somehow does not work for the trigger editor. Usually linbreaks are done with "\n". But this seems to fail in GUI. Your problem can be solved if you do the concatenation (combining 2 or multiple strings to one string) with custom script.
  • Events
    • Player - Player 1 (Red) types a chat message containing TEST as An exact match
  • Conditions
  • Actions
    • Set STRING[0] = Hello.
    • Set STRING[1] = My name is:
    • Set STRING[2] = [INSERT A STUPID NAME HERE]
    • Custom script: set udg_STRING[3] = udg_STRING[0]+"\n"+udg_STRING[1]+"\n"+udg_STRING[2]
    • Game - Display to (All players) the text: STRING[3]
The output will be:
Hello.
My name is:
[INSERT STUPID NAME HERE]


set udg_STRING[3] = udg_STRING[0] + "\n"+udg_STRING[1] + "\n" + udg_STRING[2]: Put the udg_ prefix before the GUI variables then set the desired variable to the value you want. Use + to combine strings and "\n" (which is also a string) will do the linebreak, but you have to use the " in customscript/jass.

I hope this helps you a bit.
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
Well, you could use substring... but that might make things a little difficult.
You can count the amount of characters before the line break, then show "substring(String, 1, [length]) + |n + substring(String, Length+1, total Length)".

eg:
String = "Hello there. How are you?".
Length = 13
Command string = Substring(String, 1, 13) + |n + Substring(String, 14, total length)
Final string:
Hello there.
How are you?

You can also automatically calculate the amount of characters until a there's point (.) and add a linebreak after that, so you don't need to count yourself.
The problem is that it will break the line with every point though :D

This might not be really clear, but I suggest you look at the command "Substring" if you didn't do so already.
(and |n does work in the trigger editor, for me at least).
 
Status
Not open for further replies.
Top