AUM 66 file handling

Posted By: ptrc1c

AUM 66 file handling - 10/06/09 14:56

Hi George
I had a use for your code from the workshop in AUM 66.
Following the tutorial I found that I could enter a string,
but after entering it I could only get the flashing cursor, it
was supposed to wait until another string was entered or the string "end" to terminate. What I found was the code used str_cpy to set the string back to "". I found this command reset the string, which originally was declared to have 20 characters, back to 0 characters. It would therfore never terminate because it would not accept strings of any length.
Here is the code I got to work. ps I have also modified the on_key command to be in main.



////////////////////////////////////////////////////////////////////
#include <acknex.h>
#include <default.c>


var string_handle;



STRING* string_str = " "; // the string can store up to 20 characters



TEXT* string_txt =

{

pos_x = 20;

pos_y = 200;

string (string_str); // player's input will be stored inside this string

flags = VISIBLE;

}



function write_strings() // writes and appends strings

{

// string_txt.visible = ON; // make the text visible (displays the cursor as well)

string_handle = file_open_append("strings.txt"); // open this file for appending (create it if it doesn't exist)

while (1)

{

inkey (string_str); // store the input inside the string named string_str

if (!str_cmpi(string_str, "end")) // if the player didn't type "end" yet

{

file_str_write (string_handle, string_str); // the string is written inside the "strings.txt" file

file_asc_write (string_handle, 13); // write the following string on a separate line

file_asc_write (string_handle, 10); // using asc(13) = carriage return + asc(10) = line feed

str_cpy(string_str, " "); // reset the input string - makes the input look better


}

else // the player has typed "end"

{

break; // so we exit the "while" loop

}


}

file_close (string_handle); // close the file, we won't be needing it from now on

sys_exit(NULL); // shut down the engine

}

void main()
{


on_f3 = write_strings;


}

Edit the spaces betwwn the quotes should be longer, dont know why its being truncated in this script
Posted By: George

Re: AUM 66 file handling - 10/07/09 07:33

The engine has changed a bit since then; now you can reset a string using something like str_cpy(my_string, "#20");
Posted By: ptrc1c

Re: AUM 66 file handling - 10/07/09 12:08

George
Thanks for the reply. I had a bit of a problem when doing another part of the workshop. Again the problem was the string declared in the str_for_asci command needed to have the ability to store at least one character or it gave an empty pointer error when the script was run. Thanks
© 2024 lite-C Forums