Need help with a complex "if then" structure

Moho allows users to write new tools and plugins. Discuss scripting ideas and problems here.

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
User avatar
heyvern
Posts: 7035
Joined: Fri Sep 02, 2005 4:49 am

Need help with a complex "if then" structure

Post by heyvern »

Okay my bone groups script works great...

... until you add in opening and closing files, opening files with groups then creating a new file... or launching AS with a "startup" file, etc etc.

Here's the situation:

Bone groups work by saving a text file in the same folder as the AS document with the list of bone groups. The group file is read into a table variable and this is updated and saved to the text file as you change groups. Great. This works fine as long as the group file exists or the AS file is already saved.

A new file has no groups and is not saved. If you start with a blank, new document no problems. Once you save the file it creates the text file and life is wonderful.

However if you open a file WITH a group text file and THEN start a blank new document I need to "clear" the old table variable, set some kind of "flag" indicating NOT to save the group text file (because the file isn't saved) but still update the group table variable in memory until the file is saved.

I thought this would be simple but I am getting lost in all the "if then elseif" structures.

Here is what I have so far:

Variables:

path = the current document. It would be an empty string if the file is not saved.

svFlag = true/false = if the file is not saved then don't save a group text file (false) it it is a saved file then it would be true and you can save a group text file. Either way you still need to create the table in memory for the group list.

isLoaded = true/false = the group text file in the same folder with the AS document has been loaded (true). If it doesn't exist or it hasn't been loaded yet (false) so we can load or initialize the group list.

Need this so we don't load an "old" group list on the hard drive that hasn't been saved which would overwrite the "copy" in memory. If the AS file is not saved this would still be true because you don't want to keep "erasing" the list variable in memory.

isEmpty = true/false = if there are no groups then we shouldn't save a group file... too much clutter. I don't want to create that preference file for every single document unless the groups exist.

Here's another problem... what if you DELETE all the groups? The group text preference file still exists but is now empty. Nothing I can do about that. Can't delete the file. Oh well. isEmpty can be added to the saved file if there are no groups at least so it isn't "read in" to the variable. I really need to know if there are no groups.

I can almost get this working but I just can't figure out the proper structure so it all works in every scenario; create new file, open old file, create new etc.

I don't expect any magical solutions... I like to write it out here because it seems to help my brain... and often I write it here and 5 minutes later I come up with the solution...

...

It's been 5 minutes and I still have nothing. ;)

-vern
User avatar
heyvern
Posts: 7035
Joined: Fri Sep 02, 2005 4:49 am

Post by heyvern »

Dagnabbit!

You see? I write it down... 10 minutes later I come up with a solution.

Not only a solution but NOW I don't even have to save a text file!!!! I can store the group information IN THE AS FILE!

Seem my bone group thread for my BRILLIANT solution. ;)

-vern
Post Reply