Lou Bagel's Forum Posts

  • Did you add events such as

    'On Tap Object' (and then select your object) Go to Instructions layout

    I'm not sure what you mean by 'go to layer' . . . as that sounds just like moving an instance to a specific layer.

    Yes, you should also look at the bounding box for the sprite that is to be tapped. This will determine what space is able to be tapped.

  • How do you interact with Construct timers from a script?

    I'm aware of setTimeout and setInterval in JavaScript but I'm looking to interact with events & timers that are already setup.

    When I get an instance of an object with a timer I see behaviors.Timer but I don't see a method to start or stop one. Do I need to 'get' the instance of the timer with a method?

    I'm not seeing Timers in the scripting docs either.

  • Update

    I am testing out declaring my main object in the global scope and attaching runtime to it as a parameter inside the boilerplate function runOnStartup.

    I literally just did this seconds ago so will see if I find any issues from this. The main reason I needed this now is to call some functions setup in event sheets.

    I have also attached the Sprite this logic is controlling in a parameter and that seems to be working fine. I pass it to my script from an 'On Layout Start' - on the layout this sprite is on.

    In another case when I call a method from an event sheet I pass the instance 'picked' with the events, using getFirstPickedInstance().

    So I am finding different ways to go about this that all seem to be working out fine right now.

    As far as the tip to put scripts in an anonymous function, I don't believe I need that as I am using a runtime worker. skymen, you can correct me if I'm wrong. Also, it isn't my biggest concern as this logic wouldn't really benefit any cheaters.

  • Tested the above functions with this code:

    const a = runtime.objects.Array.getFirstPickedInstance();
    const b = parseArray(a);
    console.log(b);
    b[1][0] = 'test text';
    const success = setC3Array(a, b);
    console.log("success: ", success);

    Only thing odd was that the console.log(b) already had the 'test text' . . .

  • So, I mean I can make these two global functions:

    function parseArray(c3ArrayInstance){
    	const a = c3ArrayInstance;
    	return Array(a.width).fill(0).map((c, x) => {
    		return Array(a.height).fill(0).map((d, y) => a.getAt(x, y));
    	});
    }
    
    function setC3Array(c3ArrayInstance, arr){
    	let success = true;
    	try {
    		const w = arr.length;
    		let h = arr.sort((a, b) => a.length - b.length)[0].length;
    		c3ArrayInstance.setSize(w, h);
    		arr.forEach((x, xi) => {
    			x.forEach((y, yi) => {
    				c3ArrayInstance.setAt(y, xi, yi);
    			})
    		})
    	} catch(err){
    		console.log('Errror on setC3Array function', err);
    		success = false;
    	}
    	return success;
    }

    They seem to be working fine. Like I said, it would make sense to me that there would be a getArray() and setArray() method on the prototype.

    Maybe it is because it is unlikely that users that are using Scripting in C3 will also use the C3 Array plugin. Like I mentioned before, I am looking to do this because I read the C3 Arrays will be included in the Save/Load plugin but arrays in scripts would not be.

  • Don't know if this is of any help, but I made an example of Arrays here , It has an example of how to Add to a C3 Array in Javascript.

    https://www.construct.net/en/forum/construct-3/scripting-51/please-add-templates-145895/page-3?kws=sizcoz

    Hey sizcoz thanks for trying to help!

    I took a look at one of the projects you posted on that thread. It looked like arrays created in JavaScript. I'm looking to grab an Array, as in the Construct object added to the project, inside a script.

    So here is a screenshot as I grabbed an array and logged it:

    runtime.objects.Array.getFirstPickedInstance();
    

    You can see the width and height, that it is 4x5x1, but I don't see the actual data.

    The only method on the prototype is getAt(). It just seems weird that I'd have to loop to turn an array into an array.

    Anyway, the point of this comment - let me know if I was looking at the wrong part of that thread, ha. Thanks!

  • When picking an array and logging it, I'm not surprised it is an object, but I am surprised that I don't see the actual array of values anywhere on the object. Am I missing something?

    I am getting the instance like this: runtime.objects.Array.getFirstPickedInstance();

    Which is inside an event, and is finding the instance of the array I want.

    The main reason right now that I am wanting to work with the array in both Events and JavaScript is the built-in Save function. As if I only store the array in my script it won't be saved.

    I was hoping to grab the actual array so I could filter/map/reduce/etc integrating my events and scripts. I'm not wanting to loop through width and height and use the getAt() for each value. Seems to defeat the purpose (conciseness, readability, etc). I guess I could make a global function to translates arrays to/from Construct/JavaScript - but just surprised at this.

    Is JSON the same? Could use JSON instead of an array . . .

  • I guess I can just pass in runtime to each method that needs it. Will give that a try . . .

  • Reading through Docs and Forums, and a little testing out, it seems like when using script files:

    • Accessing Construct objects is done via runtime, which is passed into functions such as the runOnStartup
    • To integrate with events, specifically having functions in a script file called, the functions need to be declared in global scope, which means NOT in runOnStartup

    Is there a way to do both?

    I'm thinking declare an object in the global scope and add methods to it from inside the runOnStartup function . . . but wanted to tread carefully until I'm understanding further.

    --A little background:

    I'm actually working in a fairly large project that is ported over from C2 (using C3 runtime). I wanted to create some objects in script files that handle a lot of the logic (such as filtering, sorting, mapping arrays) and then either call functions (Event Sheet functions that were setup prior) or assign variables (Global and/or Instance). So that is why I'm trying to get it declared in the global scope but have access to runtime / fully integrate and interact.

    So I'm new to Scripting in C3, just recently upgraded, but experienced with both Construct and JavaScript.

    Thanks for any help here! I don't want to spend too much time figuring this out right now if this solution isn't possible/practical, or even if it isn't recommended as I don't want to cause myself troubleshooting issues down the line.

    Thanks

  • Bump

    I am getting this error at times as well and not sure where to find info on this

  • Yeah, I'll probably delete the post or at least edit the original post so I don't mislead people . . . but I swear I triple checked the distance and angle expression, each, and it was different. Then after writing the post I went back and it wasn't. So either I am going crazy right now or I was pulling up a different expression?

    But it would be helpful to know if anything else changed . . . or to know what I was looking at . . .

  • ...okay, now I went back to Construct 3 and the distance and angle has not changed. Either I was looking at something else or am going crazy . . .

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I've been using Construct 2 for years and just purchased Construct 3. I'm happy with it already but have a fairly large project I just imported into Construct 3. Everything seemed to work great for the most part, as I played for a while to see if any huge issues, but now I'm finding a few things that needed to be updated everywhere.

    What I have found so far:

    • Construct 2 distance(x1, y1, x2, y2) -> Construct 3 distance(x1, x2, y1, y2)
    • Angle is ditto above (and probably all similar expressions
    • Effects with colors are consolidated from 3 expressions of R, G, B to one expression using RGB255() system expression (or a few others you can use)

    Posting this to help others but would also love if any other differences were pointed out so I can make the change and not have to find them the hard way!

    Also, feel free to link to other forum or blog posts. I did a quick search but not a lengthy one.

  • I laughed entirely way to hard when Dave ran into a coworker and looked disappointed to have to listen to them talk. I am actually working on a corporate satire game as well. Dave-man looks extremely relatable.. Especially this morning.

    haha thank you!

    Yes, that is basically the whole point of the game - avoid Chatty Cathy. The gameplay of the "levels" is very similar to PacMan but with Chatty Cathy instead of ghosts.

  • New Trailer:

    Subscribe to Construct videos now