Page 1 of 1

Howto create a new Card with Code

Posted: Thu Apr 10, 2014 6:55 am
by arthurik
hello,

i am a newbie on Livecode.
Now i would like to create a Plugin. This Plugin do the following:
on Button click the Plugin create an new Card with Code.
I now how to create a blank (without Code) Card, but how to write code into new created Card?
The code is functions and commands like:
on myCommand
...
end myCommand

I hope that you can understand me, my English is not so good

arthurik

Re: Howto create a new Card with Code

Posted: Thu Apr 10, 2014 9:59 am
by Mark
Hi Arthurik,

There are several ways to do this. If you create a plug-in, probably it is a good idea to start your script with setting the defaultStack. After that, you can create cards etc. I'm assuming that your plug-in opens as a palette from the plug-ins menu.

Code: Select all

on mouseUp
  set the defaultStack to the topstack
  create card
  set the script of it to "on mouseUp" & cr & "beep" & cr & "end mouseUp"
end mouseUp
This script creates a card that beeps when you click on it.

Now assume that you have a button "Template" in your plug-in:

Code: Select all

on mouseUp
  put the script of btn "Template" into myScript
  set the defaultStack to the topstack
  create card
  set the script of it to myScript
end mouseUp
There are many possibilities. If you give a little more information, we can find a better solution.

Kind regards,

Mark

Re: Howto create a new Card with Code

Posted: Thu Apr 10, 2014 12:43 pm
by arthurik
Hello Mark,

thats it. Works great, thank you.
On this way I can read out a xml or a text file and write more code into the new Stack or Card.

arthurik