Author Topic: Save and reuse data - fe.nv?  (Read 2272 times)

l3m35

  • Jr. Member
  • **
  • Posts: 16
    • View Profile
Save and reuse data - fe.nv?
« on: March 20, 2020, 04:18:22 PM »
Sorry, one more question because I'm lost this time.

The situation: I have a time counter to show for how long AM is running, and I'd like to store the total time. So if the user exists the Layout, the time (like XXX seconds) will be stored for the next sessions.

How can I store the value? Write it to a file? I was playing around with fe.nv, but docs don't have much about it.

Thanks!

Edit: besides, I have the counter already working, I just need to save and reuse hrs, min and sec:

Code: [Select]
local hrs = x
local mnts = x
local elapsed_tc = x
« Last Edit: March 20, 2020, 04:23:30 PM by l3m35 »

zpaolo11x

  • Hero Member
  • *****
  • Posts: 1233
    • View Profile
    • My deviantart page
Re: Save and reuse data - fe.nv?
« Reply #1 on: March 21, 2020, 01:00:41 AM »
Using fe.nv is the easiest way because fe.nv is an actual squirrel variable, so it's easier to get the data back in the layout. There's not much documentation regarding fe.nv, bear in mind that if you use it as a straight variable, and another theme does the same, clash will occur.

My suggestion is to treat it as a table, define your own identifier and save/read data using structures like:

Saving:
fe.nv[“custom name”] <- Data

Reading:
variable =  fe.nv[“custom name”]

Otherwise you can use the file module to save and read data from files, I do this now, I got rid of fe.nv for the reason I explained before

l3m35

  • Jr. Member
  • **
  • Posts: 16
    • View Profile
Re: Save and reuse data - fe.nv?
« Reply #2 on: March 24, 2020, 03:17:42 PM »
Thanks, I'm trying to write the seconds count to a file, sounds like a better solution. Sadly I had no luck writing the file yet, could you tell me if I'm going wrong here?

Code: [Select]
function on_transition( ttype ) {
local ini_file = ReadTextFile("counter")
if ( ttype == Transition.StartLayout ) {
local line = ini_file.read_line()
return line
}
}

This is working to read the file. But how to write the file?

Code: [Select]
function off_transition( ttype ) {
local wrt_file = WriteTextFile("counter")
if ( ttype == Transition.EndLayout ) {
local writeit = wrt_file.write_line("12345798")
return writeit
}
}

I guess I'm very close, but not working...

zpaolo11x

  • Hero Member
  • *****
  • Posts: 1233
    • View Profile
    • My deviantart page
Re: Save and reuse data - fe.nv?
« Reply #3 on: March 25, 2020, 12:02:10 AM »

I guess I'm very close, but not working...

In my code I just use something like

Code: [Select]
wrt_file.write_line("12345798")

instead of

Code: [Select]
local writeit = wrt_file.write_line("12345798")

l3m35

  • Jr. Member
  • **
  • Posts: 16
    • View Profile
Re: Save and reuse data - fe.nv?
« Reply #4 on: March 26, 2020, 01:38:46 PM »
In my code I just use something like

Code: [Select]
wrt_file.write_line("12345798")

instead of

Code: [Select]
local writeit = wrt_file.write_line("12345798")

Well...

Code: [Select]
function launch_transition( ttype, var ) {
[...]
break; // Transition.StartLayout works fine reading the file

case Transition.EndLayout:
WriteTextFile("counter").write_line("12345798");
break;
}
};

Not working for me at all. I'm completely lost, it doesn't write the file :(

Thank you anyway! I'll keep trying.