Self adjusting code?
Richard Gaskin
ambassador at fourthworld.com
Wed May 5 01:26:07 EDT 2004
Randall Reetz wrote:
> My first post to this list...
>
> I am a SuperCard user (for 14 years). I am of course interested in
> Revolution's multi-platform output. However... in reading some of your
> tutorials, I came across a blurb outlining a restriction on making
> run-time changes to Revolution projects (stacks). I am interested in
> evolving code... projects that react to, optimize and adjust to their
> environment... who uses them and their intent, and available media, data
> and communications streams. How does one do this with Revolution?
Hello Randall -
Good to see you here.
As Bill pointed out, Rev standalones can't modify themselves because no
OS allows an executable file to modify itself at runtime except Mac
Classic, where Rev enforces the same rule for consistency.
However, it's easy enough to simply move code into stack files that are
external to the application. Such components can easily modify
themselves just as SC projects can.
But there are other options that may be worth considering. Maureen
Caudill has written some good books and articles on neural networks and
genetic algorithms, and both are largely based on changes to data rather
than code per se. While the algorithms she discusses in her articles in
AI magazine and elsewhere are largely language-specific, many of the
underlying principles can be well emulated using constructs available in
Rev.
Perhaps chief among these are the getProp and setProp tokens. These are
very powerful tools to manage custom properties in complex ways by
trapping the setting or getting of a property to invoke any number of
actions. This allows tremendous flexibility with very natural syntax.
For example, you could say:
set the mediaPath of this stack to tMyPath
...and have this definition in the stack script (or a backscript or a
library or anywhere else in the message path):
setProp mediaPath pPath
put pPath into fld "mediaPath"
set the filename of player 1 to pPath
set the hilite of btn "Loaded" to true
start player 1
end mediaPath
That's a very simple example but illustrates the power of setProp for
invoking multiple actions from a single property setting.
Another construct worth noting is that custom properties can be stored
in any number of custom property sets, and can be addressed with array
notation using either strings, numbers, or variables:
put 2 into tMyVar
get the userInfo[tMyVar] of stack "Prefs"
By having multiple property sets you could construct (among other
things) parallel sets of properties whose values get invoked under
different circumstances for obtaining different data.
For example, if you had three properties for each user, you could assign
a different customPropertySet for each user with the same property names
in each:
set the customPropertySet of stack "UserInfo" to "Joe"
put the userName of stack "UserInfo" into tJoesName
put the userPassword of stack "UserInfo" into tJoesPassword
put the userLocation of stack "UserInfo" into tJoesLocation
--
set the customPropertySet of stack "UserInfo" to "Steve"
put the userName of stack "UserInfo" into tStevesName
put the userPassword of stack "UserInfo" into tStevesPassword
put the userLocation of stack "UserInfo" into tStevesLocation
For more ideas on using custom properties and property sets for
hierarchical data storage, see:
<http://lists.runrev.com/pipermail/use-revolution/2002-July/006149.html>
There is much to learn in using Rev, but coming from a strong SC
background as you are you'll find most of the syntax and algorithms
you're familiar with can be implemented in Rev with little or no
modification. But as you learn more about Rev you'll find many new
options like those outlined above which may open new doors for you.
But whether adapting an SC script for use in Rev or learning new
techniques, this list is definitely the place to be.
Welcome aboard.
--
Richard Gaskin
Fourth World Media Corporation
___________________________________________________
Rev tools and more: http://www.fourthworld.com/rev
More information about the use-livecode
mailing list