Gui Text Box

Started by Gius, Sun 05/07/2009 20:05:12

Previous topic - Next topic

Gius

Hi,
I have added Gui Text Box,
I can give "sending" and "carriage return" while I am writing?
I can save the contents Gui Text Box in  .txt file?



thanks
Gius

Dualnames

Quote from: Gius on Sun 05/07/2009 20:05:12
Hi,
I have added Gui Text Box,
I can give "sending" and "carriage return" while I am writing?
I can save the contents Gui Text Box in  .txt file?



thanks
Gius

Not sure what sending and carriage return mean in that sentence of yours but as for saving the contents of the txtbox in a txt file yes.

Code: ags

function TextBox_OnActivate() {
String contents=TextBox.Text;
TextBox.Text="";//clears the text box
File *output = File.Open("file.txt", eFileWrite);
output.WriteString(contents);
output.Close();
}
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

GuyAwesome

TextBoxes can only be one line tall AFAIK, although the line can be longer than what's visible, so carriage return isn't directly possible. Depending on exactly what you want, it's probably possible to dummy something up that'll work similarly, e.g. using a Label (which CAN be multi-lined) to display the excess text.
I don't know what you mean by 'sending', though.

Gius

In fact my problem is to go to the second line, if it was possible, or if there is another function in Ags to have more lines to write?
the function of saving in .txt file I have to operate it with
if (IsKeyPressed (372) == 1)

I have to add as part of this code:
function TextBox_OnActivate() {
String contents=TextBox.Text;
TextBox.Text="";//clears the text box
File *output = File.Open("file.txt", eFileWrite);
output.WriteString(contents);
output.Close();
}

where else?
I use Ags 2.72

many thanks
Gius

GuyAwesome

OK, it looks like I was wrong about TextBoxes being able to handle a line longer than can be seen. I was sure it worked that way, but testing (in 3.1.2 and 2.71) says not. Sorry about that, but it doesn't really affect this suggestion:

Make a Label on your GUI the width you want the TextBox 'line' to be, but tall enough to show 2 or more lines. Make the TextBox wider - much wider, so it can contain text 2 (or more) time llonger than you want a line to be - and then move it so it can't be seen on the GUI. In the global script, add this line to repeatedly_execute
Code: ags

MyLabel.Text = MyTextBox.Text;

(replacing MyLabel and MyTextBox with the right script names)

You should now have the appearance of a multi-line textbox the player can type into. This is a very simple solution, and might not be exactly what you want - if not, you'll need to give us more details to work with :).

Dualnames' code should work OK in 2.72 as-is, you just need to move it from the TextBox OnActivate function, to the if (keycode == 372) { condtion. Also, if you use my code above, you'd need to modify it to clear the Label text as well
Code: ags

  if (keycode == 372) {
    String contents = MyTextBox.Text;
    MyTextBox.Text = ""; //clears the text box
    MyLabel.Text = ""; //clears the label
      //replace 'MyTextBox' and 'MyLabel' with real names
    File *output = File.Open("file.txt", eFileWrite);
    output.WriteString(contents);
    output.Close();
  }


One problem with that code, is that it'll overwrite the contents of file.txt every time you use it. Try replacing eFileWrite with eFileAppend.

SMF spam blocked by CleanTalk