New IDE/Visualizer "meta" scripting functions

Information and change log about the latest ZGameEditor release.

Moderator: Moderators

Post Reply
User avatar
VilleK
Site Admin
Posts: 2274
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

New IDE/Visualizer "meta" scripting functions

Post by VilleK »

Starting a new release thread now because the existing one was so old :)

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
Previously you would need to have a big case-statement for every value of i.

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());
    }
  }
}
Some suggestions on how these new functions can be used:
- 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
Attachments
IdeFuncTests.zgeproj
(1.68 KiB) Downloaded 673 times
zgevid_idefunc.png
zgevid_idefunc.png (106.21 KiB) Viewed 14728 times
User avatar
VilleK
Site Admin
Posts: 2274
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Re: New IDE/Visualizer scripting functions

Post by VilleK »

Fixed a small bug regarding this new feature today so please download beta again if you downloaded that version.
User avatar
VilleK
Site Admin
Posts: 2274
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Re: New IDE/Visualizer scripting functions

Post by VilleK »

Updates:
- changed "xptr" datatype of the functions above to use new "Component" datatype (xptr was causing bugs).
- added setObjectProperty.
- project tree is now automatically refreshed in the IDE to show created components, when "Stop" button is clicked.
- added error message if you try to save exe-file using these new functions

Updated beta zip and example code in first post.
User avatar
VilleK
Site Admin
Posts: 2274
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Re: New IDE/Visualizer "meta" scripting functions

Post by VilleK »

Added another "meta" function: saveComponentToTextFile(component,filename);

This makes it possible for a ZGE program to generate a new zgeproj-project. ZGE projects can now self-generate :)

Example below generates a new project that displays "Hello world".

Also added "DEBUG" flag so scripts can execute special code while in IDE (and it will be automatically be removed from binary).

Code: Select all

if(DEBUG) { //Code within DEBUG only compiles in IDE and Visualizer, it is removed for binary builds

  Component newApp = createComponent(null,null,"ZApplication");

  Component text = createComponent(newApp,"OnRender","RenderText");

  setStringProperty(text,"Text","Hello world!");
  saveComponentToTextFile(newApp,"c:\\temp\\hello.zgeProj");

 }
Also added a UI-scaling setting in Settings dialog to increase scale to 125%.

Updated beta.
Post Reply