Custom Objects With Properties?

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
xLite
Posts: 11
Joined: Mon Jun 20, 2011 4:13 pm

Custom Objects With Properties?

Post by xLite » Tue Jun 28, 2011 10:38 pm

Does LiveCode let you create objects with properties like in Javascript for example where you can create an object like so:

Code: Select all

var myObject = {property:1, anotherProperty:"test"}; // myObject.anotherProperty would output "test"
I need to store these types of objects in an array but I have no idea how to make them if even possible?


Thanks for any and all help.

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

Re: Custom Objects With Properties?

Post by Mark » Tue Jun 28, 2011 11:22 pm

Hi,

What exactly do you want to store in those properties?

An object in an xTalk language like LiveCode is completely different from an object in JavaScript. There is no analogy. Try to avoid confusion and forget about JavaScript.

There are custom properties in LiveCode. You can set them with the following syntax:

Code: Select all

set the cBla of btn "Some Button" to "whatever data you like"
You can also use arrays:

Code: Select all

put "some data" into mySomeArray["This is a Key"][42]
Arrays can have multiple dimensions.

You can set a custom property to an array, but those are more difficult to edit (both manually and by script).

Code: Select all

set the cArrayproperty of fld "Some Field" to myWhateverArray
Kind 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

xLite
Posts: 11
Joined: Mon Jun 20, 2011 4:13 pm

Re: Custom Objects With Properties?

Post by xLite » Tue Jun 28, 2011 11:55 pm

Thanks for the response. Basically what I'm trying to achieve is a pathfinding algorithm, specifically A* if you are familiar with that sort of thing. So I need to be able to cycle through and array of "Nodes" which make up a path. In each "Node" object I need the x position, y position, the type (whether you can walk on this node or not with your avatar) and a few other properties related to pathfinding.

Is there anything you could reccomend that would best suit what I'm trying to achieve?

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

Re: Custom Objects With Properties?

Post by Mark » Wed Jun 29, 2011 12:13 am

Hi,

I think that speed is the most important thing here. I'd keep all data in one big array and use the "repeat for each key" command to process the array. By not reading data from and writing data to objects, you might save some time. Probably, you will want to create a key for each node and sub-keys for objects on each node and other information about the nodes.

I've heard of A* but I think there are other people who know more about it than me.

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

Post Reply