Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Programming and Scripting
Saving to another line of the file

Hey
Guest
Quote
2021-03-21 14:21:15

Could you please help me? I save the position of an object in a file, but if I have multiple objects, and I need to save the position for each one, then how can I do it in a single file? That is, can I somehow save the data on another line of the same file? And, if so, how can a particular line be read?
https://cloud.mail.ru/public/WfE...


Hey
Guest
Quote
2021-03-21 19:33:57

Please help if you know


smnmhmdy
Registered User
Quote
2021-03-21 19:44:39

You can load the file into a variable and just use regular javascript parsing functions to split each line into an array.
var Text = ccbReadFileContent("Text.txt");
var ParsedText = Text.split("\n");

Now you can loop through each element of ParsedText and load the position of each object accordingly

To add a new line to the existing file you should be able to first load the whole file, add the new line to it, and then rewrite it back into the disk
var Text = ccbReadFileContent("Text.txt");
var Text = Text + "\n" + "SOMETHING HERE";
ccbWriteFileContent("Text.txt", Text);



just_in_case
Moderator
Quote
2021-03-22 07:37:18

There is already an extension available to download from Ambiera's Coppercube extension page which allows you to read a specific line from a file. I posted the extensions years ago cause I thought it will be useful for people to save and load values and to read dialogues and all those stuff.

You can also use the method proposed by @smnmhmdy to save the value to new lines and read them afterwards.

hope that helps.


Hey
Guest
Quote
2021-03-22 17:51:56

Thank you very much, guys! I did it all right.


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Intern?tional" (you are not logged in)


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   






Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact