mOOnpunk's Forum Posts

  • I guess you have to let the bots on the site if you want ai to be knowledgeable about construct. At the moment their knowledge is still very hit and miss.

  • chatGTP bot probably someone asked chat gtp a question about construct and its looking for the answer.

  • // SDK v1

    let myinstance = this._inst.GetWorldInfo();

    myinstance.SetXY(x, y);

    // SDK v2

    // Access the position property directly or use the methods provided

    this.x = x;

    this.y = y;

    this.setBboxChanged();

    This returns a runtime error, function not found.

  • what is the correct way to update the bounding box in sdk v2?

    At runtime.

    i use a red rectangle to compute the bounds and need the bounding box to get its shape and position from it, but it wont update.

    Thanks.

  • Thanks i will take another look.

  • Thanks.

    I tried console.log(this)...

    instance.js:127 [Polygon] DrawingInstance: this: DrawingInstance bounds: {minX: -50, maxX: 50, minY: -50, maxY: 50, width: 100, …} collisionMode: "0" moved: (6) [408, 119, 458, 219, 358, 219] points: (6) [0, -50, 50, 50, -50, 50] rotatedBounds: {minX: 0, maxX: 0, minY: 0, maxY: 0, width: 0, …} updateBbox: true #t: C3.WorldInfo _x: 408 _y: 169 _w: 100 _h: 100 _ox: 0.5 _oy: 0.5 _boundingBox: C3.Rect {_left: 358, _top: 119, _right: 458, _bottom: 219} _inst: C3.Instance runtime: self.IRuntime [[Prototype]]: self.ISDKWorldInstanceBase

    The #t: C3.WorldInfo object exists, but the instance isn’t linked to it via GetWorldInfo().

    The plugin executes

    plugin.js:1 [Polygon] plugin.js: Loading plugin.js type.js:1 [Polygon] type.js: Loading type.js instance.js:1 [Polygon] instance.js: Loading instance.js conditions.js:1 [Polygon] conditions.js: Loading conditions.js main.js:1 [Polygon] main.js: Loading main.js main.js:17 [Polygon] main.js: All plugin scripts imported.

    globalThis.SDK is undefined, but globalThis.ISDKPluginBase, globalThis.ISDKObjectTypeBase, and globalThis.ISDKWorldInstanceBase are available.

    main.js:4 [Polygon] main.js: SDK namespace: undefined plugin.js:5 [Polygon] plugin.js: SDK namespace: undefined plugin.js:6 [Polygon] plugin.js: ISDKPluginBase available: true type.js:5 [Polygon] type.js: SDK namespace: undefined type.js:6 [Polygon] type.js: ISDKObjectTypeBase available: true

    DrawingInstance lacks the GetWorldInfo() method required for IWorldInstance.

    instance.js:126 [Polygon] DrawingInstance: Constructor called instance.js:127 [Polygon] DrawingInstance: this: DrawingInstance instance.js:130 [Polygon] DrawingInstance: GetWorldInfo exists: false instance.js:134 [Polygon] DrawingInstance: this properties: ["runtime", "objectType", "plugin", "effects"] instance.js:145 [Polygon] DrawingInstance: Could not assign GetWorldInfo, C3.Instance lacks method instance.js:174 [Polygon] DrawingInstance: WorldInfo after init: undefined instance.js:176 [Polygon] DrawingInstance: GetWorldInfo missing after init, instance may not be fully registered as IWorldInstance

    Overlapping fails

    conditions.js:23 [Polygon] IsOverlapping: this.GetWorldInfo() failed, this: DrawingInstance

    Ashley any guidance?

  • I'm stuck until this is resolved. Shame i think a lot of people would have liked this plugin.

  • i think rgba() use a range from 0-100, not 0-255.

  • Thanks for help and patience.

    I wish the examples were much more expansive.

    Now i have another issue.

    When evaluating my Is overlapping condition i get the runtime error;

    [Polygon] IsOverlapping: Error during testOverlap: TypeError: expected IWorldInstance at C3.Runtime._UnwrapIWorldInstance (runtime.js:1:64349) at self.ICollisionEngine.testOverlap (ICollisionEngine.js:1:264) at DrawingInstance.IsOverlapping (conditions.js:32:40) at C3.Condition._RunObject_FirstFilter (condition.js:1:7732) at C3.Condition._RunObject (condition.js:1:6915) at C3.EventBlock._DebugRunAndBlock (eventBlock.js:1:11113) at _DebugRunAndBlock.next (<anonymous>) at C3.EventBlock.DebugRun (eventBlock.js:1:9888) at DebugRun.next (<anonymous>) at C3.EventSheet.DebugRun (eventSheet.js:1:3736)</anonymous></anonymous>

    My instance.js defines the instance class as follows:

    C3.Plugins.Polygon.Instance = class DrawingInstance extends globalThis.ISDKWorldInstanceBase
    {
     constructor()
     {
     super();
     // ... initialization code ...
     }
    
     _onCreate()
     {
     console.log("[Polygon] _onCreate called. this.GetWorldInfo():", this.GetWorldInfo && this.GetWorldInfo());
     }
    
     // ... other methods ...
    }
    

    My conditions.js implements the IsOverlapping condition like this:

    IsOverlapping(objectClass)
    {
     if (!objectClass || typeof objectClass.getAllInstances !== "function") {
     console.warn("[Polygon] IsOverlapping: Invalid objectClass provided");
     return false;
     }
    
     const runtime = this.runtime || C3.runtime;
     if (!runtime || !runtime.collisions) {
     return false;
     }
    
     const instances = objectClass.getAllInstances();
     if (!instances || instances.length === 0) {
     return false;
     }
    
     const thisWorldInfo = this.GetWorldInfo && this.GetWorldInfo();
     if (!thisWorldInfo) {
     console.warn("[Polygon] IsOverlapping: this.GetWorldInfo() failed:", this);
     return false;
     }
    
     for (const otherInst of instances) {
     const otherWorldInfo = otherInst.GetWorldInfo && otherInst.GetWorldInfo();
     if (!otherWorldInfo) {
     console.warn("[Polygon] IsOverlapping: otherInst.GetWorldInfo() failed for instance:", otherInst);
     continue;
     }
    
     try {
     if (runtime.collisions.testOverlap(this, otherInst)) {
     return true;
     }
     } catch (e) {
     console.error("[Polygon] IsOverlapping: Error during testOverlap:", e);
     return false;
     }
     }
    
     return false;
    }
    

    I used globalThis.ISDKWorldInstanceBase for instance.js, as recommended.

    The plugin.js sets this._info.SetPluginType("world"), and this.runtime is available and set to self.IRuntime.

    I'm using runtime.collisions.testOverlap.

    Added logging to confirm that this.GetWorldInfo() is failing for the DrawingInstance. The Sprite instance (otherInst) has a valid WorldInfo object (C3.WorldInfo), but the Polygon instance (this) doesnt.

    "[Polygon] IsOverlapping: this.GetWorldInfo() failed: DrawingInstance"

    The Sprite instance (otherInst) has a valid WorldInfo object, as no otherInst.GetWorldInfo() failed log appears.

    The DrawingInstance has a property #t: false, while the Sprite instance has #t: C3.WorldInfo.

    Added _onCreate to instance.js to log GetWorldInfo() during the instance creation, but it does not appear to be called (no corresponding log appears).

    Thanks.

  • Ashley

    I'm getting an error

    "Failed to load all engine scripts in worker: TypeError: Class extends value undefined is not a constructor or null

    at type.js:3:69"

    Used C3.SDKPluginBase for plugin.js, C3.SDKWorldInstanceBase for instance.js, and C3.SDKObjectTypeBase for type.js.

    All three classes are undefined, causing the same error in each file.

    The plugin works fine in the editor (edit-time scripts use SDK.IPluginBase, etc.).

    The plugin defines a custom collision polygon via getCollisionPoly and uses runtime.testOverlapInstances for the IsOverlapping condition, which should work once the runtime loads.

  • There is also this plugin.

    construct.net/en/make-games/addons/538/rexsequencematcher-c3runtime

    Not sure if its sdk 2 though.

  • R0J0hound i couldn't get my files to work, so i've extended yours, using polyK.js to compute the earclipping.

    Hope you dont mind.

    I just need to add the actions and expressions then i'll release it for the community.

  • I'm sorry. I misread your reply.

  • I cant get Draw() to work no matter what i do.

    I modified the example and only _draw will call, even though my files are set up and configured for SDK V2.

    const C3 = globalThis.C3;

    C3.Plugins.MyCompany_PolygonRenderer.Instance = class PolygonRendererInstance extends globalThis.ISDKWorldInstanceBase {

    constructor() {

    super();

    console.log("[PolygonRenderer] Constructor executed for instance");

    }

    OnAddedToLayout() {

    console.log("[PolygonRenderer] OnAddedToLayout executed for instance");

    const worldInfo = this._inst.GetWorldInfo();

    console.log(`[PolygonRenderer] Position after OnAddedToLayout: x=${worldInfo.GetX()}, y=${worldInfo.GetY()}`);

    }

    OnCreated() {

    console.log("[PolygonRenderer] OnCreated executed for instance");

    this._InitializeInstance();

    }

    OnCreate() {

    console.log("[PolygonRenderer] OnCreate executed for instance (testing SDK v1 compatibility)");

    this._InitializeInstance();

    }

    _InitializeInstance() {

    const worldInfo = this._inst.GetWorldInfo();

    // Force position to a visible area for debugging

    worldInfo.SetX(100);

    worldInfo.SetY(100);

    worldInfo.SetWidth(50);

    worldInfo.SetHeight(50);

    worldInfo.SetBboxChanged();

    console.log(`[PolygonRenderer] Instance position after initialization: x=${worldInfo.GetX()}, y=${worldInfo.GetY()}, width:${worldInfo.GetWidth()}, height:${worldInfo.GetHeight()}`);

    const layer = this.layer;

    if (layer) {

    console.log(`[PolygonRenderer] Layer properties: visible=${layer.isVisible}, opacity=${layer.opacity}, scale=${layer.scale}, parallaxX=${layer.parallaxX}, parallaxY=${layer.parallaxY}`);

    // Force layer visibility for debugging

    layer.isVisible = true;

    layer.opacity = 1;

    } else {

    console.warn("[PolygonRenderer] No layer information available for this instance");

    }

    // Force instance visibility

    this._inst.SetVisible(true);

    console.log(`[PolygonRenderer] Instance visibility forced: visible=${this._inst.isVisible}`);

    // Log runtime and layout information

    const runtime = this._runtime;

    if (runtime) {

    console.log(`[PolygonRenderer] Runtime layout: width=${runtime.GetMainRunningLayout().GetWidth()}, height:${runtime.GetMainRunningLayout().GetHeight()}`);

    const allInstances = runtime.GetMainRunningLayout().GetAllInstances();

    console.log(`[PolygonRenderer] Total instances in layout: ${allInstances.length}`);

    let found = false;

    for (const inst of allInstances) {

    if (inst === this._inst) {

    found = true;

    console.log(`[PolygonRenderer] This instance found in layout: UID=${inst.GetUID()}`);

    }

    }

    if (!found) {

    console.warn("[PolygonRenderer] This instance NOT found in layout instances!");

    }

    }

    }

    OnLayoutStart() {

    console.log("[PolygonRenderer] OnLayoutStart executed for instance");

    }

    OnLayoutEnd() {

    console.log("[PolygonRenderer] OnLayoutEnd executed for instance");

    }

    Tick() {

    console.log("[PolygonRenderer] Tick executed for instance");

    const worldInfo = this._inst.GetWorldInfo();

    console.log(`[PolygonRenderer] Position in Tick: x=${worldInfo.GetX()}, y=${worldInfo.GetY()}`);

    // Force position each frame to ensure it stays at x=100, y=100

    if (worldInfo.GetX() !== 100 || worldInfo.GetY() !== 100) {

    console.warn("[PolygonRenderer] Position was overridden, forcing back to x=100, y=100");

    worldInfo.SetX(100);

    worldInfo.SetY(100);

    worldInfo.SetBboxChanged();

    }

    }

    getBoundingQuad() {

    if (!this._inst) {

    console.warn("[PolygonRenderer] getBoundingQuad called before instance is fully initialized");

    return new C3.Quad();

    }

    const worldInfo = this._inst.GetWorldInfo();

    console.log(`[PolygonRenderer] Getting bounding quad for instance at (${worldInfo.GetX()}, ${worldInfo.GetY()}) with width: ${worldInfo.GetWidth()}, height:${worldInfo.GetHeight()}`);

    const quad = super.getBoundingQuad();

    console.log(`[PolygonRenderer] Default bounding quad: minX=${worldInfo.GetX()}, minY=${worldInfo.GetY()}, width=${worldInfo.GetWidth()}, height=${worldInfo.GetHeight()}`);

    return quad;

    }

    Draw(renderer) {

    if (!this._inst) {

    console.warn("[PolygonRenderer] Draw called before instance is fully initialized");

    return;

    }

    console.log("[PolygonRenderer] *** DRAW METHOD EXECUTED ***");

    const worldInfo = this._inst.GetWorldInfo();

    console.log(`[PolygonRenderer] Drawing instance at (${worldInfo.GetX()}, ${worldInfo.GetY()}) with width: ${worldInfo.GetWidth()}, height: ${worldInfo.GetHeight()}`);

    // Set up renderer state

    renderer.setBlendMode("normal"); // Set normal alpha blending

    renderer.setColorFillMode(); // Set fill mode to color fill

    renderer.setColorRgba(1, 0, 0, 1); // Red, fully opaque

    // Draw a simple 50x50 red square at the instance's position

    renderer.rect(worldInfo.GetX(), worldInfo.GetY(), worldInfo.GetX() + 50, worldInfo.GetY() + 50);

    }

    _draw(renderer) {

    // Test if runtime expects SDK v1 method name

    if (!this._inst) {

    console.warn("[PolygonRenderer] _draw called before instance is fully initialized");

    return;

    }

    console.log("[PolygonRenderer] *** _draw METHOD EXECUTED ***");

    const worldInfo = this._inst.GetWorldInfo();

    console.log(`[PolygonRenderer] _draw instance at (${worldInfo.GetX()}, ${worldInfo.GetY()}) with width: ${worldInfo.GetWidth()}, height: ${worldInfo.GetHeight()}`);

    // Set up renderer state

    renderer.setBlendMode("normal"); // Set normal alpha blending

    renderer.setColorFillMode(); // Set fill mode to color fill

    renderer.setColorRgba(1, 0, 0, 1); // Red, fully opaque

    // Draw a simple 50x50 red square at the instance's position

    renderer.rect(worldInfo.GetX(), worldInfo.GetY(), worldInfo.GetX() + 50, worldInfo.GetY() + 50);

    }

    };

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Then why does the official sdk V2 drawing example runtime instance.js use _draw?

    const C3 = globalThis.C3;

    const tempQuad = new C3.Quad();

    C3.Plugins.MyCompany_DrawingPlugin.Instance = class DrawingInstance extends globalThis.ISDKWorldInstanceBase

    {

    constructor()

    {

    super();

    this._testProperty = 0;

    const properties = this._getInitProperties();

    if (properties)

    {

    this._testProperty = properties[0];

    }

    }

    _release()

    {

    super._release();

    }

    _draw(renderer)

    {

    const imageInfo = this.objectType.getImageInfo();

    const texture = imageInfo.getTexture(renderer);

    if (!texture)

    return; // dynamic texture load which hasn't completed yet; can't draw anything

    let quad = this.getBoundingQuad();

    const rcTex = imageInfo.getTexRect();

    renderer.setTexture(texture);

    if (this.runtime.isPixelRoundingEnabled)

    {

    const ox = Math.round(this.x) - this.x;

    const oy = Math.round(this.y) - this.y;

    if (ox !== 0 && oy !== 0)

    {

    quad = new DOMQuad(new DOMPoint(quad.p1.x + ox, quad.p1.y + oy),

    new DOMPoint(quad.p2.x + ox, quad.p2.y + oy),

    new DOMPoint(quad.p3.x + ox, quad.p3.y + oy),

    new DOMPoint(quad.p4.x + ox, quad.p4.y + oy));

    }

    }

    renderer.quad3(quad, rcTex);

    }

    _saveToJson()

    {

    return {

    // data to be saved for savegames

    };

    }

    _loadFromJson(o)

    {

    // load state for savegames

    }

    _setTestProperty(n)

    {

    this._testProperty = n;

    }

    _getTestProperty()

    {

    return this._testProperty;

    }

    };