Jump to content

Variable Value Retention across SAVES


SecretSquirrel-BJC

Recommended Posts

Probably another dumb question

 

I read in Whack a Lackey, that arrays and timers are not retained across save-resumes

 

However I have the following issue

 

If I have a variable A defined at the outermost scope of the LUA program, initially set to 1

Then later it gets updated to 2

 

If the cartridge is saved and resumed, then I would expect it to stay at 2.

 

But it doesn't.

 

Do all variables behave like this? Or is there some special setting/construc that I need to use?

 

PS not using the builder interface except to compile and test

 

PPS My workaround might be to stuff variables inside something that will be retained like an item.name or description etc

Edited by SecretSquirrel-BJC
Link to comment

Thinking out aloud to myself....

 

Just found out that if I had added the global variable to <cart>.ZVariables then any value changes would have persisted across the save/restore. Doh!!

 

If you don't add it, then on restore, the global variable gets reset to the same value as it had at the start.

 

Very interesting.

 

Stuffing them into another object also worked.

Link to comment

By "Stuffing them into another object worked" do you mean compressing your data to a single string and storing it in an items name, description, etc?

 

For your global variables you put in ZVariables, were they basic types (int, string) or did you try something more complex like an Array?

 

Thinking out aloud to myself....

 

Just found out that if I had added the global variable to <cart>.ZVariables then any value changes would have persisted across the save/restore. Doh!!

 

If you don't add it, then on restore, the global variable gets reset to the same value as it had at the start.

 

Very interesting.

 

Stuffing them into another object also worked.

Link to comment

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...