3

Is there a data structure within LiveCode that can be used as a "holder" for associated data, letting me handle it collectively? I come from a Java / Javascript / C background so I am looking for a Class or Struct sort of data structure.

I've found examples of Groups, which seem to have some of this functionality, but it feels a bit like I'm bending the language to meet my needs.

As a specific example, suppose I had an image field on my screen that would randomly display an image and, when pressed, play an associated sound clip. I'd expect to create a list of "structures" that contained the path to the image and the path to the associated sound clip, and use that data to populate the image field and to decide what sound clip to play.

Would a Group be the correct structure to use in this case? Or am I approaching this in a way that isn't really fitting with the way LiveCode works?

z--
  • 2,186
  • 17
  • 33
DaveH
  • 7,187
  • 5
  • 32
  • 53
  • 1
    Hi, Dave. Sounds like custom properties might be all you need - you could store the list of image and sound paths against the image object. – splash21 May 28 '13 at 13:34
  • Could you please make your question more precise? A group with a field for the path to the image and another field for the path to the sound clip might be the right thing. Then you might jump randomly to a card and when opening displaying the image and playing the sound. See also my answer mentioning arrays. You might want to use an array and store it as a custom property of the array. – z-- May 28 '13 at 22:58

3 Answers3

1

It takes a little getting used to, but the xTalk world is much simpler and more open than any ordinary procedural language. So much of what you once had to manage is no longer required.

So when splash21 said that you could store all your image and sound references in a custom property, he was really saying that the LiveCode environment contains intrinsic, high level functionality that makes these sorts of things instantly accessible, and the only thing required of you is to call for them, and they simply work.

The only way to appreciate this is to make a few simple programs, to really see what is possible. Make your application. Everything you mentioned can be accomplished with perhaps a dozen lines of code in a single handler. I recommend that you join the LiveCode use list and forums. The community is vibrant and eager to help, frequently with full blown solutions to specific problems, but more importantly, as guides and mentors to new users

Craig Newman

dunbarx
  • 756
  • 5
  • 4
  • I completely agree with you. For this reason, I believe xTalk languages should not include classes and structs the same way as C++ or PHP. xTalk languages are a different type of language, not based on classes but on the message hierarchy. Let's keep it simple! – Mark Jun 15 '13 at 11:25
  • it's a long way from the strictly typed world I'm used to, but I'm beginning to get my head round it now I think. – DaveH Nov 13 '13 at 19:58
1

Arrays in LiveCode are actually associative arrays (like hash maps). A key is associated with a value. The value might be as well an array.

Chapter 5.5.7 of the User's Guide says

Array elements may contain nested or sub-elements, making them multi-dimensional. This type of array is ideal for processing hierarchical data structures such as trees or XML. To access a sub-element, simply declare it using an additional set of square brackets.

put "ABC" into myVariable["myKeyName"][“aChildElement”]

see also How to store pictures in a stack?

Community
  • 1
  • 1
z--
  • 2,186
  • 17
  • 33
0

Dave- I'm hoping to get a struct-like container implemented in the near future. Meanwhile you can, as splash21 mentioned, use custom properties (or better yet, custom property sets) to do what you want. This will give you a pseudo-struct for each object and you can implement the file and sound specifications into the properties. And if you use that in conjunction with a behavior object you'll end up very close to a real inheritable class formation.

mwieder
  • 231
  • 2
  • 6