Tuesday, November 5, 2024
spot_img

Doable to import file to / export file from inside HTML5 recreation? – Cocos Creator


[Creator 3.8.2]

Whats up there,

I’m making a recreation the place customers create their very own platformer ranges and I used to be questioning whether it is potential to export recordsdata in-browser and skim values from recordsdata on a participant’s laptop. This type of performance could be superb, as it might enable level-sharing between creators.

How may I create an “export degree” button which, when pressed, exports a .txt file to the consumer’s downloads folder? Additionally, is there a technique to learn knowledge from the identical file from any listing on the consumer’s laptop into the sport, to be saved as a cookie in-browser? I solely must learn the information from the file, not reserve it as an asset in-game.

Lastly, is there a correct technique to flip any type of knowledge (particularly a string) right into a textual content file just like the one described above?

I do know these are loads of questions, however any assist could be extraordinarily useful to me! I’ve spent a number of hours wanting however haven’t discovered something helpful but. If somebody can provide me a working reply to all 3 questions, they are going to obtain a point out within the credit of my recreation.

Additionally, if a mod is studying this, is it potential to have my username modified? I’m reachable by DM :slight_smile:

Bump – This query is pivotal to my recreation’s success, if anybody who’s studying wants clarification on my query (shouldn’t be crucial imo) and may probably be capable to give a solution, please attain out to me!

On the net, you can not actually learn recordsdata from the participant’s laptop. The browser is a self-contained sandbox, it doesn’t have the system context, solely the browser context.

Whereas Cocos doesn’t present a file system for such circumstances, if you’re working with solely an internet platform in thoughts, you may attempt to use Net APIs to entry the browser file system → De File System Entry API: vereenvoudigt de toegang tot lokale bestanden  |  Capabilities  |  Chrome for Builders.
How one can Create and Save textual content file in JavaScript?

Nonetheless, you continue to might want to determine easy methods to learn such .txt recordsdata in Cocos area. For that, I imagine the better means could be to have a server the place the customers might add the .json / .txt recordsdata after which your recreation might react to such new uploads utilizing an HTTP or Net Sockets connection

For “cookies” based mostly knowledge, you need to use the localStorage API and work with textual content values → Consumer Information Storage | Cocos Creator

Since you aren’t contemplating App Retailer releases, I’d say that Scorching Replace tunnel can be a chance → Property Scorching Replace Tutorial | Cocos Creator

Thanks, I’ll have a look :slight_smile:

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisement -spot_img

Latest Articles