|
Post by fabocihe on Apr 20, 2016 14:07:22 GMT
For my script, there could be several settings that i can set on the 1st run. After that, i can choose to "reuse" or "configure". If "reuse" is chosen, it will use previous values.
So how can i load previous vales?
|
|
|
Post by zpt on Apr 20, 2016 15:22:04 GMT
There is lots of ways to implement this. You could store defaults separately and use them if such checkbox set.
def_opt1 = 1 def_opt2 = 100
dialogInit() addCheckBox("use_def", "Reset settings", false) newRow() addTextView("Option 1:") addEditNumber(opt1,0) newRow() addTextView("Option 2:") addEditNumber(opt2,10) dialogShow("Options")
if use_def then opt1 = def_opt1 opt2 = def_opt2 end
Or you could use removePreference()
dialogInit() addTextView("Reset settings?") newRow() addCheckBox("reset_settings", false) dialogShow("Reset")
if reset_settings then removePreference("opt1") removePreference("opt2") end
dialogInit() addTextView("Option 1:") addEditNumber(opt1,0) newRow() addTextView("Option 2:") addEditNumber(opt2,10) dialogShow("Options")
Or write settings into file.
|
|
|
Post by fabocihe on Apr 21, 2016 2:20:32 GMT
Are they any sample codes to read or write to file?
|
|
|
Post by AnkuLua on Apr 21, 2016 10:10:02 GMT
|
|
|
Post by byrdlua on Nov 22, 2016 14:56:06 GMT
I tried writing to a local file; it failed due to no write access.
As I'm familiar with Android, I know I should be able to write to a public path on the SD card (virtual or otherwise). What I don't see is a way to get this path, since it varies from device to device. e.g. Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS);
I suppose I could figure it out per device and use a first run config to figure out which device I'm on, but there should be a better way.
Thanks!
|
|
|
Post by AnkuLua on Nov 22, 2016 15:23:38 GMT
Use scriptPath() and save the file to the script folder.
fileName = scriptPath() .. "log.txt" file = io.open(fileName, "w")
|
|