
I added a few functions to the scripting language that can only be used from the IDE and Visualizer. The reason for this is that in the minimal binary version of the code all component names have been removed.
New functions:
- findComponent(name) -- Returns the component with that name if it exists, or null otherwise.
- createComponent(owner,propertylistName,componentclassname) -- Creates a new component as child to an existing component, and returns the new component.
- setNumericProperty(component,propertyName,index,value) -- Set value of a numeric property. The "index" is used with multi-value properties such as Color.
- setStringProperty(component,propertyName,value) -- Set value of a string property.
- setObjectProperty(component,propertyName,value) -- Set value of a object property (example: "Texture" property of MaterialTexture is a object property).
Examples:
Suppose you have 10 bitmaps named "Bitmap1" to "Bitmap10". And you want to modify one of them depending on the value of an integer. Then you can simply do this:
Code: Select all
Bitmap b=findComponent("bitmap" + intToStr(i));
if(b!=null)
//do something with b
Creating components: In the attached example I have code that creates 10 bitmaps, set properties, and also create child producer component to each bitmap.
Code: Select all
for(int i=1; i<10; i++) {
Component c=createComponent(App,"Content","bitmap");
setStringProperty(c,"Name","Bitmap" + intToStr(i));
setNumericProperty(c,"Width",0,512);
setNumericProperty(c,"Height",0,512);
Component nested;
if(i & 1) {
nested=createComponent(c,"Producers","BitmapExpression");
setStringProperty(nested,"Expression",
"Pixel=vector4(1.0," +
"abs(cos(Y*" + intToStr(random(4,3)) + ")) * ." + intToStr(rnd()*1000) + "," +
"abs(sin(X*" + intToStr(random(4,3)) + ")) * ." + intToStr(rnd()*1000) + "," +
"1.0);");
} else {
for(int j=0; j<3; j++) {
nested=createComponent(c,"Producers","BitmapRect");
setNumericProperty(nested,"Color",0,rnd());
setNumericProperty(nested,"Color",1,rnd());
setNumericProperty(nested,"Size",0,rnd());
setNumericProperty(nested,"Size",1,rnd());
setNumericProperty(nested,"Size",2,rnd());
setNumericProperty(nested,"Size",3,rnd());
}
}
}
- Debug/support routines in the IDE when creating projects
- Useful in Visualizer scripts
- Generate code. For instance, in a visualizer script it could create custom Expression components, MeshExpression, BitmapExpression etc, could be powerful for generated content.
Updated ZGE is here: http://www.zgameeditor.org/files/ZGameEditor_beta.zip