Page 1 of 1

Custom Objects With Properties?

Posted: Tue Jun 28, 2011 10:38 pm
by xLite
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.

Re: Custom Objects With Properties?

Posted: Tue Jun 28, 2011 11:22 pm
by Mark
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

Re: Custom Objects With Properties?

Posted: Tue Jun 28, 2011 11:55 pm
by xLite
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?

Re: Custom Objects With Properties?

Posted: Wed Jun 29, 2011 12:13 am
by Mark
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