We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.

List saved in Dictionary is appending instead of replacing List content

Home Forums Puzzles List saved in Dictionary is appending instead of replacing List content

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #41940
    rollos5son
    Participant

    Hi all!

    I’ve been tinkering with Puzzles for some time with little difficulty and much enjoyment but I’ve finally run into a challenge.

    What I’m trying to do is simulate the loading and saving of a set of objects for eventual hookup to a database (as project files). As part of this testing process I store my List of objects in a Dictionary on “save”, then attempt to load the contents of the Dictionary entry back to the List on “load”.

    My problem is that when I do this, rather than replacing the contents of the List array variable, the loaded Dictionary content is appended, so that when I do my test load I get multiple iterations of the set of objects. Worse, some of my attempts to clear the List variable first make it impossible to load the contents of the Dictionary list at all.

    If necessary I can provide an example app.

    #41948
    GLiFTeK
    Customer

    Hi,
    Before you save to your list, define it as an empty list using the “create empty list

    Then do your adding of values to it, then set it as the value ofyour dictionary key. :good:

    #41949
    rollos5son
    Participant

    Thanks for the tip!

    I’m feeling a bit foolish now because I went back over my code more thoroughly and found the problem:

    I’d set up a function within a loop to assign new names to the reloaded objects, but I was then adding the new names to the same list! :whistle: I solved the problem by assigning those names to a second list which I could then copy back into the first after finishing up the renaming. Everything is working perfectly now! :good:

    For any relative newb like me, let this post be a helpful lesson – proofread, proofread, proofread!

    #41951
    GLiFTeK
    Customer

    Oh it happens heh.

    I’ve seen my share of facepalms.

    I have a plugin you may be interested in I’ll be releasing soon for saving to offline storage that may help in your project.

    #41952
    rollos5son
    Participant

    True, yet I’m also coming to appreciate more and more that mistakes truly are a great teacher. I’ve had to learn coding on the fly and the behavior of functions still makes my head hurt, but I’m getting more used to that.

    Thanks for the heads-up on the plugin!

    #41954
    GLiFTeK
    Customer

    True, yet I’m also coming to appreciate more and more that mistakes truly are a great teacher. I’ve had to learn coding on the fly and the behavior of functions still makes my head hurt, but I’m getting more used to that.

    Thanks for the heads-up on the plugin!

    Join the Verge 3D Discord server chat if you like.
    Contact me there for info and help!

    #43362
    AVerge3Der
    Participant

    This sounds interesting to me as well, the plugin. If this can work with SQLite that would be a plus. :bye:

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.