Page 1 of 1

Lingo alt to adding code to an object at runtime

Posted: Tue May 15, 2012 6:17 pm
by CenturyMan1979
Was looking for a little help on how I can add code to a dynamically created object in livecode.

In Lingo I could do the following to add an object then add code to it. Sorry for the [dot] but this forum does not let me post using dot syntax lingo code.

tNewMem = new(Object)
tNewSprite = sprite(spriteNum)
tNewSprite[dot]puppet = true
tNewSprite[dot]member = tNewMem
sprite(spriteNum)[dot]scriptInstanceList[dot]add(Script Reference)

What would a script look like to do this in livecode if it is possible?

Re: Lingo alt to adding code to an object at runtime

Posted: Tue May 15, 2012 6:47 pm
by Klaus
Hi CenturyMan1979,

geeez, I immediately abandoned Director when the first version of MetaCard (the grandfather of LiveCode)
for Mac/Win came out and before I dived into the Director OOP stuff in 1999 :-)

You can add a "behavior", which is "just" the script of a "premade" button, to newly created objects:
...
create button
## or field or player or graphic or whatever you like to create
## No "sprites" or "puppets" in Livecode!
set the behavior of last button to the long ID of btn "the premade behavior button here..."
...
Yep, something like this :D

And welcome to the forum!


Best

Klaus