In many object-oriented languages, a class is a template that is loaded when the program starts up. It is an abstract entity. The program uses that template to create new objects and initialize the properties.
In LiveCode, you have templates which are like classes. They are also abstract and are only used to create new objects. There are templates for every object/control (eg. templateButton, templateGraphic, templateCard, templateStack, templateGroup, etc). They do not exist but they have all the properties of real ones. By setting the properties of a template, you specify how the objects are created and initialized.
This may be what you were looking for:
Code: Select all
on openCard
// set the default values of the template (class)
set the fillcolor of templategraphic to red
set the lifepoint of templateGraphic to "xx"
set the experience of templateGraphic to 0
end openCard
command Personnage lp,xp
//this creates the object from the template (class)
set the lifepoint of templateGraphic to lp
set the experience of templateGraphic to xp
end Personnage
on mouseDown
// create a Graphic from the template
create graphic normal
// create a Graphic from the template, with new values
Personnage "Yolo" ,5
create graphic heros
// create another Graphic with the same properties
create graphic heros2
create graphic heros3
//change the template back to the original defaults
reset the templateGraphic
end mouseDown
notes:
- I used graphic as an example. You can use any LiveCode object or controls (See the dictionary for more details)
- fillcolor is a normal property of Graphics
- lifePoint and experience are custom properties (yours)
If this is not what you were looking for, then follow quailcreek's advice above and give us a more general idea of what you want to accomplish