Data objects

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

bbalmerTotalFluency
Posts: 51
Joined: Mon Apr 06, 2020 1:19 pm
Location: Thailand
Contact:

Data objects

Post by bbalmerTotalFluency » Sat Dec 10, 2022 3:51 am

Hi:

I love LC. I like the objects such as fields - very cool. I'd like to make a data object that is a combination of data and programming logic. Is that possible and if so how using livecode.

More detail:

Let's say I wanted to make a person object. It might contain data such as firstname, lastname, age, gender etc. And it might have code like to respond to a greeting with "Hi my name is <firstname> pause <lastname> etc. Obviously, I can do that with a field object and some code but I'd like to bundle it together into an object. Is it possible?

Klaus
Posts: 13793
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Data objects

Post by Klaus » Sat Dec 10, 2022 10:08 am

Hi bbalmerTotalFluency,

something like this will be possible in LC 10, look here:
https://livecode.com/progress-update-on ... invention/
Until then I would just use a GROUP with all neccessary objects and scripts.

Best

Klaus

SWEdeAndy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 256
Joined: Sat Aug 16, 2008 9:48 am
Location: Stockholm, Sweden
Contact:

Re: Data objects

Post by SWEdeAndy » Sat Dec 10, 2022 12:42 pm

bbalmerTotalFluency wrote:
Sat Dec 10, 2022 3:51 am
I'd like to make a data object that is a combination of data and programming logic.
I think in a sense, every single control in LiveCode can be considered a 'data object'. Every control can store any amount of data as custom properties, and every control is independently scriptable. So you don't need to use a field to hold the data, a button or widget or group etc can store the same data, and when you click/hover over it/leave it/move it etc, it can provide that data in any way that you have scripted it to do.

What is it you feel is lacking in the current LC functionality?
Andreas Bergendal
Independent app and system developer
WhenInSpace: https://wheninspace.se

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: Data objects

Post by mwieder » Sat Dec 10, 2022 5:04 pm

I think what you're trying to do is possible with a combination of custom properties and behavior objects.
For instance for a person object you might do something like

create a button named "PersonObject"
The PersonObject button becomes the Person class in Object-oriented terms
in the script of button "PersonObject" enter

Code: Select all

on respondToGreeting
  answer "my name is" && the firstname of me && the lastname of me
end respondToGreeting
create another button
set the firstname of it to "Jack"
set the lastname of it to "Benny"
set the age of it to 39
# here's the magic that makes this a Person object
set the behavior of it to the long id of button "PersonObject"

repeat creating more Person buttons for more people. As long as you set the behavior to the class button they'll all respond similarly.

Is that something like what you're after?

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9567
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Data objects

Post by dunbarx » Sat Dec 10, 2022 6:01 pm

Mark has created an entire community, all of whom share one thing in common. They all refer their base functionality back to a single source, that original button. In the old days, where I still live, that source would have been the card or stack, but I am old and getting older.

But I am with Andy here. I do not yet see if that was what you are seeking. Could you attain your goal with a single magical "person object", however that gadget was finally built? In other words, what exactly makes that object special?

Craig

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9567
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Data objects

Post by dunbarx » Sat Dec 10, 2022 6:05 pm

You know you can import an image to be your object, say a photo of John von Neumann, galavanting all over the screen.

I guess what I am really asking is this, to make sure that it is not the object itself that matters, but rather functionality and attributes of that object.

Craig

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: Data objects

Post by mwieder » Sat Dec 10, 2022 6:19 pm

Yeah, I don't know what the end goal is here, but if you're dealing with a lot of people I wouldn't create lots of Person objects, I'd use a database.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9567
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Data objects

Post by dunbarx » Sun Dec 11, 2022 4:39 am

Rereading the initial post, I think the issue is far simpler than we thought.

@bbalmerTotalFluency (do you have a nickname?) Can you post a quick example of what you want, with perhaps a short wishlist of functionality? Especially consider whether or not your project changes much if you have two objects instead of one.

Craig

bbalmerTotalFluency
Posts: 51
Joined: Mon Apr 06, 2020 1:19 pm
Location: Thailand
Contact:

Re: Data objects

Post by bbalmerTotalFluency » Sat Jan 28, 2023 6:29 am

What is it you feel is lacking in the current LC functionality?
I strongly suspect the deficiency is in my brain and not in livecode. I'm just aware that in say ruby, you can create a class that is ONLY the class you are creating with only the methods you create. It feels odd using a field for example as an object, however, I can see that it can store its own data and have methods defined on it. Perhaps, it's just what I'm used to and I'm not far enough up the livecode mountain yet to appreciate the view.

Thanks for replying

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: Data objects

Post by mwieder » Mon Jan 30, 2023 1:05 am

I've done a fair amount of ruby coding, and yes, there are different modes of thinking about things necessary here.
There's no such thing as an abstract class in LiveCode - depending on what you're doing at any given time, behavior scripts or control objects are usually going to take their place.

There are some things I'd love to bring over from ruby (an import statement, a lambda function like yield, etc) but for the most part I just accept the fact that there are different paradigms at work and go on from there.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9567
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Data objects

Post by dunbarx » Mon Jan 30, 2023 1:48 am

All.

I have little experience outside of xTalks. A little Fortran, a little Basic.

A theme in this thread is the concept of a custom object class that can be created in certain languages, as opposed to xTalks, where (until widgets came along) one had to select from a fixed suite of pre-existing objects, and add whatever functionality one could.

So what is the main advantage of being able to create a new custom object class? What can such a gadget do that, say, a graphic, field or image cannot?

A widget?

Craig

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: Data objects

Post by mwieder » Mon Jan 30, 2023 6:47 am

So what is the main advantage of being able to create a new custom object class?
Ask any n programmers and you'll get n-squared answers. And classes aren't always the answer to everything (yes, I know that's 42)... there are cases where making everything class-based adds unnecessary complication. That, IMO, is where java fails.

But here's a real-world example from experience:
Let's say you want to create a linked list and use it several times in a complex program. In LiveCode this is difficult: you'll end up creating an internal structure and common handlers, then for each new list you'll call the internal common handlers but name each caller differently and end up with a maintenance nightmare.

With a code-based class you could create a linked-list class and then easily create new instances of that class without having to replicate a lot of the basic calls.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9567
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Data objects

Post by dunbarx » Mon Jan 30, 2023 3:29 pm

Mark.

I sort of see what you mean. I suppose I am so used to doing things the xTalk way that I do not see the native complexity of doing such a thing in LC as a burden, just the way things are.

So can a tailor-made widget become that linked list object class? In other words, do widgets provide that functionality?

Craig

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: Data objects

Post by mwieder » Mon Jan 30, 2023 7:24 pm

A graphic is a class in many ways.

When you create a new graphic circle it has a lot of inherited properties of the generic graphic object.
When you create a circle with a 1-inch radius you don't have to do a lot of extra coding when you create a new circle with a 2-inch radius.
It's all there in the graphic class (with the exception that the radius property is different in each new circle).
But you can set the foreground color of each without having to know a lot about the internal workings of the basic graphic class.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7210
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Data objects

Post by jacque » Mon Jan 30, 2023 7:35 pm

I think the template objects are probably similar to classes too, but of course we are limited to the predefined ones.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”