Netherwulf Posted November 12, 2020 Share Posted November 12, 2020 Greetings! I'm hitting a wall trying to create a game state file that can be opened and read back. Here is my code. filePath = FileSystem:GetAppDataPath() .. "gamestate.txt" function Script:UpdatePhysics() if window:KeyHit(Key.S) then local stream = FileSystem:WriteFile(filePath) if (stream==nil) then Debug:Error("Failed to write file.") end stream:WriteInt(GameData) stream:Release() end end When I run the program and press the key to create and save the file, the debug error is fired and the program ends. I can't tell if the problem lies in my code or somewhere else. Quote Link to comment Share on other sites More sharing options...
Marcousik Posted November 12, 2020 Share Posted November 12, 2020 I worked on this and it runs ok in this code order: DISPLAY was the variable I wanted to save written. Quote local path = FileSystem:GetAppDataPath().."/MyFile.txt" FileSystem:CreateFile(path) local stream = FileSystem:OpenFile(path) if (stream) then stream:Seek(0) stream:WriteLine(DISPLAY) -- stream:Seek(0) -- debug -- System:Print(stream:ReadLine()) stream:Release() end Quote Link to comment Share on other sites More sharing options...
Josh Posted November 12, 2020 Share Posted November 12, 2020 Your second code shows a "/" is inserted, and the first one does not. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Netherwulf Posted November 12, 2020 Author Share Posted November 12, 2020 7 hours ago, Josh said: Your second code shows a "/" is inserted, and the first one does not. The path being in the proper format was the first thing I looked into when I started having trouble. That doesn't seem to be the issue. Furthermore, I tried using the FileSystem:CreateFile() and FileSystem:OpenFile() commands that Marcousik suggested, but that doesn't work for me either. My local "stream" variable continues to return a nil value. Quote Link to comment Share on other sites More sharing options...
Solution Netherwulf Posted November 13, 2020 Author Solution Share Posted November 13, 2020 UPDATE: I finally got it to work. It seems that I had "Sandboxing" enabled in the editor's options and that was preventing it from working. Thanks for all your help. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.