Save an object's properties to a text file

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
mokogobo
Posts: 37
Joined: Wed Jun 18, 2008 6:27 pm
Contact:

Save an object's properties to a text file

Post by mokogobo » Wed Jun 18, 2008 6:59 pm

Hello.

I'm working on a project in Revolution and need to generate a number of "image" objects based on a common template image object. I've set up an image object just how I want the template image object to be, and am curious if I can save the settings of the object to a text file and later reload them to create more image objects.

An alternative method would be to set up my image object and then make it invisible, and copy it, but I'd prefer to generate the objects completely dynamically from settings stored in a file. I'm not able to find any good documentation on the entire list of properties available to Revolution objects, so I'd just like to save the existing properties to a file, and reload them later. Any ideas?

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Wed Jun 18, 2008 7:47 pm

Dear mokogobo,

I export all properties of all objects and cards of a stack to an XML file, for DIFfersifier (which is at http://economy-x-talk.com/differsifier.html ). It is quite simple to do this, using the propertynames function and a repeat loop.

I wouldn't do this, however, only to replicate an object inside Revolution. If this is all you want, it is so much easier to save a custom template object in your project and copy it to wherever you need it. A simple copy command is much easier and probably much faster than reading all properties from a file and setting the properties of an object using a repeat loop.

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

mokogobo
Posts: 37
Joined: Wed Jun 18, 2008 6:27 pm
Contact:

Post by mokogobo » Wed Jun 18, 2008 8:25 pm

Mark wrote:If this is all you want, it is so much easier to save a custom template object in your project and copy it to wherever you need it. A simple copy command is much easier and probably much faster than reading all properties from a file and setting the properties of an object using a repeat loop.
Do you mean to create the object, make it invisible or store it to a "template card" and just copy it, or is there a better way?

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Wed Jun 18, 2008 8:26 pm

Dear mokogobo,

Yes, that's what I mean.

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

mokogobo
Posts: 37
Joined: Wed Jun 18, 2008 6:27 pm
Contact:

Post by mokogobo » Wed Jun 18, 2008 8:35 pm

Mark wrote:Dear mokogobo,

Yes, that's what I mean.

Best,

Mark
Okay. That's what I originally did, but it felt a bit too "hacky". I found that the "templateImage" can be configured to set the default properties for new images created. This seems like a nice way to go about it...

I'm thinking:
1) Initially load properties from an XML file and close file
2) Use the loaded properties to set the templateImage
3) Create any images needed
4) Reset the template image

Anyway, thanks for your direction.

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Wed Jun 18, 2008 8:49 pm

Hi mokogobo,

You should just save the object in your project and copy it when you need it. That's the best way to do it.

Best regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

mokogobo
Posts: 37
Joined: Wed Jun 18, 2008 6:27 pm
Contact:

Post by mokogobo » Wed Jun 18, 2008 10:11 pm

Mark wrote:Hi mokogobo,

You should just save the object in your project and copy it when you need it. That's the best way to do it.

Best regards,

Mark
Alright. Is the best way to save it to a new card on the same stack, or a new stack? I'm having some trouble copying the image from another card on the same stack... it closes the current card or makes it invisible. While I could switch back to the desired card, I'd prefer the copying took place in the background. Any pointers?

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Wed Jun 18, 2008 10:54 pm

Dear mokogobo,

It doesn't matter where you keep the object, as long as it is part of your project. You need to refer to the object as part of a stack, if it isn't part of the current stack: copy img x of cd y of stack z to this cd.

The stack with the object needs to be in memory. I am not sure, right now, whether the card with the object has to be on screen. If is has to be, you can still set the right of the stack to -100, to make it invisible, or perhaps set the invisible of the stack to true. Just experiment a but and see what works best for you.

Best regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

mokogobo
Posts: 37
Joined: Wed Jun 18, 2008 6:27 pm
Contact:

Post by mokogobo » Wed Jun 18, 2008 11:34 pm

Thanks. I really appreciate your help. :-)

Post Reply