Avirlus's Recent Forum Activity

  • Thank you for adding loops to Construct 3! Now, I can create various loops with delays between iterations. However, when waiting for a condition, the loop executes immediately without waiting exactly once, but it still remembers itself and executes a second time when the condition is met.

    async TestWaitingVariable() {
    	const loopCtx = this.runtime.sdk.createLoopingConditionContext();
    	
    	while (this._variable !== true) {
    		if (!loopCtx.isStopped) {
    			await new Promise(resolve => setTimeout(resolve, 100));
    		} else {
    			break;
    		}
    	}
    	
    	if (!loopCtx.isStopped)
    		loopCtx.retrigger();
    	loopCtx.release();
    }
    

    In this example, I want to wait until the variable this._variable equals true, and if it is true, then execute the code. However, when I run the current loop, all actions execute immediately without waiting exactly once (when this._variable = false), and when I change the variable this._variable to true in another action, all actions execute once more or multiple times (depending on the number of loops previously called). How can I make it wait until the variable equals true and then execute the actions in the current loop block in Construct 3?

    Thank you for your help!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Is it possible to create loops in my Plugin SDK 2? In the old SDK 1, loops work as expected and perform their function successfully. However, in SDK 2, I can't seem to create loops that execute for each element or a specific number of times. Below is an example script I made in `conditions.js` (I created this script after extensively searching through the Construct 3 documentation, and this script only progressed to `GetSolModificators()`, but with an error due to `GetCurrentEvent()` returning null, even though I followed the documentation):

    	TestLoop(Count) {
    		const runtime = this.runtime;
    		const eventSheetManager = new C3.EventSheetManager(runtime);
    		const eventStack = eventSheetManager.GetEventStack();
    		const oldFrame = eventStack.GetCurrentStackFrame();
    		const currentEvent = oldFrame.GetCurrentEvent();
    		const solModifiers = currentEvent.GetSolModifiers();
     	const newFrame = eventStack.Push(currentEvent);
    
    		for (let i = 0; i < Count; i++) {
    			// ... optionally update state here ...
    
    			// Push a copy of the current SOL
    			eventSheetManager.PushCopySol(solModifiers);
    
    			// Retrigger the current event, running a single loop iteration
    			eventSheet.Retrigger(oldFrame, newFrame);
    
    			// Pop the current SOL
    			eventSheetManager.PopSol(solModifiers);
    		}
    			
    		// Pop the event stack frame
    		eventStack.Pop();
    		// Return false since event already executed
    		return false;
    	}
    

    The `aces.json` is as follows:

    {

    "highlight": false,

    "id": "TestLoop",

    "isLooping": true,

    "isAsync": false,

    "isInvertible": false,

    "params": [ { "id": "Count", "type": "number" } ],

    "scriptName": "TestLoop"

    }

    After creating a new project, adding this loop and actions to it on layout start or button press, an error appears in the console:

    If anyone can help me fix the error so I can finally create loops in Plugin SDK 2, I would be very grateful!

Avirlus's avatar

Avirlus

Member since 8 Sep, 2021

None one is following Avirlus yet!

Trophy Case

  • 3-Year Club
  • Regular Visitor Visited Construct.net 7 days in a row
  • RTFM Read the fabulous manual
  • x3
    Quick Draw First 5 people to up-vote a new Construct 3 release
  • Email Verified

Progress

7/44
How to earn trophies