Howto create a new Card with Code

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
arthurik
Posts: 4
Joined: Thu Apr 10, 2014 6:07 am

Howto create a new Card with Code

Post by arthurik » Thu Apr 10, 2014 6:55 am

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

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

Re: Howto create a new Card with Code

Post by Mark » Thu Apr 10, 2014 9:59 am

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
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

arthurik
Posts: 4
Joined: Thu Apr 10, 2014 6:07 am

Re: Howto create a new Card with Code

Post by arthurik » Thu Apr 10, 2014 12:43 pm

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

Post Reply