Lou Bagel's Recent Forum Activity

  • You do not have permission to view this post

  • Did Construct 3 replace the term Zindex with Zelevation?

    I am working in a project that is ported over from Construct 2 and now objects have both a Z-Index and a Z-Elevation property.

    So I'm curious if they are different things or if they are the same then if I am going to have any issues since objects have both now.

  • Thanks! I was actually already doing that. Good to know the documentation is up to date!

  • 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.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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

Lou Bagel's avatar

Lou Bagel

Member since 7 Sep, 2015

Twitter
Lou Bagel has 3 followers

Connect with Lou Bagel

Trophy Case

  • 9-Year Club
  • Jupiter Mission Supports Gordon's mission to Jupiter
  • Forum Contributor Made 100 posts in the forums
  • Forum Patron Made 500 posts in the forums
  • Popular Game One of your games has over 1,000 players
  • Regular Visitor Visited Construct.net 7 days in a row
  • RTFM Read the fabulous manual
  • Email Verified

Progress

16/44
How to earn trophies