New IDE/Visualizer scripting functions

Information and change log about the latest ZGameEditor release.

Moderator: Moderators

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

New IDE/Visualizer scripting functions

Postby VilleK » Mon Sep 11, 2017 1:10 pm

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.74 KiB) Downloaded 6 times
zgevid_idefunc.png
zgevid_idefunc.png (106.57 KiB) Viewed 195 times

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

Re: New IDE/Visualizer scripting functions

Postby VilleK » Wed Sep 13, 2017 8:50 am

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: 1859
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Re: New IDE/Visualizer scripting functions

Postby VilleK » Wed Sep 13, 2017 2:06 pm

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.


Return to “Releases”

Who is online

Users browsing this forum: No registered users and 1 guest