Create a custom function

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

ivaho
Posts: 37
Joined: Tue Feb 14, 2012 2:19 pm

Create a custom function

Post by ivaho » Sun Sep 16, 2012 11:41 am

Hi,

I was wondering is it possible to create my own function?
I have some commands that i use a lot and was wondering i i could create a function that i can call instead of typing the entire command over and over again?

Klaus
Posts: 14193
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Create a custom function

Post by Klaus » Sun Sep 16, 2012 11:48 am

Dag Ivaho,

sure this is possible! :D
What do you have in mind?


Best

Klaus

ivaho
Posts: 37
Joined: Tue Feb 14, 2012 2:19 pm

Re: Create a custom function

Post by ivaho » Sun Sep 16, 2012 11:53 am

Hi klaus,

Thanks for your reply.
I am using a video playout server that has al its commands in a .net framework. All are dll files.
I have the sources of the dll files.

I want to start building my own " framework" for livecode.

Klaus
Posts: 14193
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Create a custom function

Post by Klaus » Sun Sep 16, 2012 11:56 am

Hi Ivaho,

hmmm, so you want to "talk" to these DLLs?
I'm afraid this is not possible in LiveCode right out of the box!


Best

Klaus

ivaho
Posts: 37
Joined: Tue Feb 14, 2012 2:19 pm

Re: Create a custom function

Post by ivaho » Sun Sep 16, 2012 12:21 pm

All these dll files do is a command or function
for example
c# code
data.SetData("f0", this.textBoxF0.Text);

the function data.SetData does noting more than sending the data from textboxF0 to the field F0

Can i create my own custom function so I can call SetData from licecode.

Klaus
Posts: 14193
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Create a custom function

Post by Klaus » Sun Sep 16, 2012 12:26 pm

Hm, sorry, don't get it. 8)

So this C# snippet puts text from one field into another field?
Like:
put fld "textboxF0" into fld "F0"
?

ivaho
Posts: 37
Joined: Tue Feb 14, 2012 2:19 pm

Re: Create a custom function

Post by ivaho » Sun Sep 16, 2012 4:04 pm

The SetData, sends the text of field F0 to a template on the server containing a field named F0.

SetData contains a command build like an xml string that puts text field F0 from a gui into a template on the server

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Create a custom function

Post by sturgis » Sun Sep 16, 2012 4:16 pm

Sounds like you're trying to write a wrapper for the dlls that talk to your server app.

The info is old, and I think the stuff relating to externals has changed recently so I'm not sure it still applies. (follow through and build the example and see if they work) If they work then maybe you can either write a wrapper for the dlls or convert the source of the dlls themselves to become externals.

See info here: http://www.runrev.com/developers/lesson ... ls-part-1/

There is also a part 2.

ivaho
Posts: 37
Joined: Tue Feb 14, 2012 2:19 pm

Re: Create a custom function

Post by ivaho » Sun Sep 16, 2012 4:54 pm

I think my explanation is not clear enough.

The data.setdata is In the dll file as the following command.

---
CG 1 ADD 0 "demo/test" 1 "<templateData><componentData id=\"f0\">
<data id=\"text\" value=\"Text from text field 1\">
</data> </componentData><componentData id=\"f1\">
<data id=\"text\" value=\"text from text field 2\">
</data></componentData><componentData id=\"f2\">
<data id=\"text\" value=\"text from text field 3\"></data> </componentData></templateData>"
---

What i do in live code at the moment is to write this complete command to a text file and than sends this text file to my server.

I want to create a function that does this for me.

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Create a custom function

Post by sturgis » Sun Sep 16, 2012 5:02 pm

Ah k. Gotcha

Something like this might work

Change your code like so:
CG 1 ADD 0 "demo/test" 1 "<templateData><componentData id=\"f0\">
<data id=\"text\" value=\"[[the text of field 1]]\">
</data> </componentData><componentData id=\"f1\">
<data id=\"text\" value=\"[[the text of field 2]]\">
</data></componentData><componentData id=\"f2\">
<data id=\"text\" value=\"[[the text of field 3]]\"></data> </componentData></templateData>"

Place this into a property.
Create a function

function myFunc
-- merge will replace the [[]] sections with data specified, IE the text from each field
put merge(the propertyIPutItIn of this stack) into tData
--do your send to the server stuff here using tData

end myFunc

There might be more to your requirements, but hopefully this will give you the idea.
ivaho wrote:I think my explanation is not clear enough.

The data.setdata is In the dll file as the following command.

---
CG 1 ADD 0 "demo/test" 1 "<templateData><componentData id=\"f0\">
<data id=\"text\" value=\"Text from text field 1\">
</data> </componentData><componentData id=\"f1\">
<data id=\"text\" value=\"text from text field 2\">
</data></componentData><componentData id=\"f2\">
<data id=\"text\" value=\"text from text field 3\"></data> </componentData></templateData>"
---

What i do in live code at the moment is to write this complete command to a text file and than sends this text file to my server.

I want to create a function that does this for me.

ivaho
Posts: 37
Joined: Tue Feb 14, 2012 2:19 pm

Re: Create a custom function

Post by ivaho » Sun Sep 16, 2012 7:20 pm

Thanks for your help.

I'll habe to find out about that property and the function and howto use merge.

But ill now where to look for.

Thanks

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Create a custom function

Post by sturgis » Sun Sep 16, 2012 7:28 pm

You might look at http://www.runrev.com/developers/docume ... rs-course/ to help get yourself up to speed with livecode.

Also http://lessons.livecode.com which has guides to specific tasks such as using properties.

ivaho
Posts: 37
Joined: Tue Feb 14, 2012 2:19 pm

Re: Create a custom function

Post by ivaho » Wed Sep 19, 2012 10:59 am

I've been reading and following the video cource but I didn't find out about how to create a property containing my code that I could call from my custom function.

Klaus
Posts: 14193
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Create a custom function

Post by Klaus » Wed Sep 19, 2012 11:48 am

Dag Ivaho,
ivaho wrote:I've been reading and following the video cource but I didn't find out about how to create a property containing my code that I could call from my custom function.
this is pretty straightdforward:
1. manually:
Copy the text you want to store in a custom property.
Select the object where you want to add the custom property -> e.g. Inspector for the stack (or whatever, EVERY object, card and stack can hold custom properties!)
Click on the + sign, give your property a name and PASTE the text into the field at teh bottom.

2. via script:
Put the text into a field and use the message box:
set the cWhatEverNameHere of stack "your stack name here" to the text of fld "field with the text in it"

Et voila, you just created your first custom property :-)


Best

Klaus

ivaho
Posts: 37
Joined: Tue Feb 14, 2012 2:19 pm

Re: Create a custom function

Post by ivaho » Wed Sep 19, 2012 1:05 pm

It is that easy. Very nice.

And how to call that custom propertie, if i put the custom propertie on a button will the MouseUp event trigger the custom propertie.
And how when the custom propertie is placed on a card

Post Reply