Ambiera ForumDiscussions, Help and Support. |
|
|
|||||
|
I have a text file with a string of texture names "mycursor.png", "gcur.png", "gcur_action.png", "gcur_forward.png", "gcur_down.png" this works: const cursorNames =["mycursor.png", "gcur.png", "gcur_action.png", "gcur_forward.png", "gcur_down.png"]; and I know: curtxt =ccbReadFileContent( "cursor.txt").toString('utf-8'); reads the file, but how do I use the text file rather than string in the code line I hope it makes sense :| |
||||
|
split will do the job for you. var stringfromfile=ccbReadFileContent("MyFile.txt"); var lines = stringfromfile.split('\n'); for(var i = 0; i < lines.length; i++){ print( lines[i]); } instead of '\n' you can use whatever separator you want to use here.. for example "," or space. |
||||
|
Awesome, thank you Sven |
||||
|
here's what I've come up with, I wanted various types of cursors controlled by a variable, which changes depending on the hotspot interaction, I can also do inventory cursors I might have a look at doing the switch code dynamically
|
||||
|
I think is much easier to use JSON object here: var yourCursorObject = { name : [""], path: [""], image: [] }; Does coppercube support JavaScript Json? In the meantime PLEASE start migrating your JSON-using applications over to Crockford’s json2.js. It is fully compatible with the ECMAScript 5 specification and gracefully degrades if a native (faster!) implementation exists. There are two primary methods for handling JSON: JSON.parse (which converts a JSON string into a JavaScript object) and JSON.stringify (which convert a JavaScript object into a serialized string). https://stackoverflow.com/questions/22883743/how-can-i-write-an-array-to-a-file-in-nodejs-and-keep-the-square-brackets |
||||
|
I'm struggling with js trying to figure out what works and what doesn't, I'm piecing bits together and hoping it works :) But yes I agree I need to start using JSON, I'm trying to do my own inventory and other things I'll have a look at the link, thank you |
|