Ambiera ForumDiscussions, Help and Support. |
|
[ 1 2 ] Page 1 of 2 |
|
|||||
|
How could I save an existing variable to an external .txt file or .INI file? If I had a variable name like: "Score" I'm trying to use these JS methods without success: ccbGetCopperCubeVariable(varname) ccbWriteFileContent(filename, content) If I use: ccbGetCopperCubeVariable to get the value of the variable into the content of the text file and then write that value using: ccbWriteFileContent But then the saved .INI file content would look something like this: Score=562 Saved inside scores.ini which could be saved in the same directory as the game app. Niko could you give me a hint as to how the code would be written out to make this work? Or if there is an easier way to just get in game variable data in and out of CC to and from an external text file that could reside in the same directory as my app. please let me know. Thanks. Ed. |
||||
|
If you are struggling to write a script for writing out that content of your file, it will probably get very difficult for you to read it, because this would involve even more complex code (parsing ini files isn't that simple). But to start, for writing out that file, it would look like this:
I haven't tried this, but I think it should work. Note that on newer versions of Windows, it is not allowed to write into certain directories, so the file will end up somewhere else, if it is for example installed in "C:\program files", but this is virtualized, so for the game, it should work anyway, you might just not see the file at the location of your game. |
||||
|
Thanks Niko. That works fine cheers. |
||||
|
Thanks edkeyte for this very interesting topic and Thanks Niko as well for this answer. I would appreciate if someone can post here the reverse operation Load operation I tried the following code to read a value from file and assign to a variable in coppercube
|
||||
|
If you can be helpful, you can see the plugin that I tried to do. reads an external file to edit a selected object. http://www.ambiera.com/forum.php... |
||||
|
Thanks a lot pmax for your code I've found the error in my code as well I discovered where was my problem variables should be defined before being used var <variable name> and in the ccb functions has to be used between single quotes ... I don't have any java programming basics background ..
|
||||
|
That's great techno-valley! Thanks! The loaded data works but unlike the first example from niko you are not getting just the number value of the score. You're getting both the full text from the file and the score too. Do you know how to just get the number without the first part? Here's what it looks like anyway. http://www.queenseng.com/cc-test... Also @pmax code is fantastic! Thanks. Ed. |
||||
|
yes Just replace the load code with the following
Code explanation: The second line containing " readline = " code reads from Character number 6 ("equal sign =") till the end of line (varContent.length-1 to avoid taking the next line carriage return) Let me know if you have any question. Thanks for pmax code as well |
||||
|
This is a very helpful discussion, thanks for posting. I tried the sample and it works very well for an exe but does not seem to work in WebGL. What do you think needs to be changed in the code to work in WebGL |
||||
|
Hello Volt, from the documentation ccbWriteFileContent(filename, content) Note: This function may not do anything depending on the target it runs on (websites for example have no access to the file system). I've tried to save locally to the disk using WebGL and Flash output. It didn't work neither for WebGL nor for Flash. |
||||
|
Hello techno-valley, Thanks for the response, what about saving to a file on my server? www.mydomain.com/save.txt |
||||
|
Hello volt, you may check the following two commands in the documentation ccbDoHTTPRequest(url, callback) ccbCancelHTTPRequest(connectionIdToCancel) You can update a database hosted on the server other than saving text file for example. |
||||
|
Hey, How to save multiple variables, position and other parameters in a single file?? |
||||
|
Please, can you provide an example of this saving and loading codes? the one once posted is no longer available... Please, reply! |
||||
|
I've created a quick example. You may download here : http://www.techno-valley.com/cce... |
[ 1 2 ] Page 1 of 2 |
|