Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • CreatiCode
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo

CreatiCode Scratch Forum

  1. CreatiCode Forum
  2. Knowledge Base
  3. 2D Blocks
  4. Export variables to files or Import files

Export variables to files or Import files

Scheduled Pinned Locked Moved 2D Blocks
1 Posts 1 Posters 786 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • CreatiCodeI Offline
    CreatiCodeI Offline
    CreatiCode
    wrote on last edited by admin
    #1

    Introduction

     

    For every variable in a project, you can write code to export it to a text file on the user’s computer, or import a file from the user’s computer into a variable. This is useful when you need to allow the user to save some data that can be used later. For example, when you program a game, you may want to allow the players to save their current progress into a file and reload it later.

     
     

    Export a Variable

     

    You can use the “export variable [VARIABLE NAME]” block to export the value of a variable to a text file. For example, when you run this program, a new file named “variable1” will be downloaded into the “Downloads” folder on the user’s computer, and its content will be “22”. Of course, you can store much more data in a variable, and it will all be saved into the file.

    cbcd340c-33a0-4709-990a-03ca3ddb49ea-image.png

     
     

    Import a File into a Variable

     

    You can also import a file into a variable like this:

    eb2bb03b-dde3-4c98-ac5f-1c709d2d5b85-image.png

    When the user runs this program, an “Open File” dialog window will pop up, and the user can select ANY file that ends with “.txt” or “.csv”. Note that the file name doesn’t have to be the same as the variable name. Once the user selects a file, that file’s content will be stored in the variable you specified. If the user has cancelled the dialog window without selecting any file, then the variable’s content will not be changed.

    1 Reply Last reply
    1

    Hello! It looks like you're interested in this conversation, but you don't have an account yet.

    Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

    With your input, this post could be even better 💗

    Register Login
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • CreatiCode