piranha305's Forum Posts

  • agree with newt the performance benefit you get from scripting vs events is negligible, the real benefit from scripting comes from complex data structures imo. you have alot more freedom to freely manipulate data and store data. that said with that extra freedom you can fine tune some algorithms that you have on the event sheet and you might get a bit more performance. but it really depends on what you are doing, for general game play logic you wont see that big of a boost. just take a look at the ghost shooter example it implemented using full scripting and full events and the performance is very similar, mind you its a very simple implementation. one thing i noticed from comparing both scripting had a few frame drops to like 57 fps every once in a while and the event based one stay at a constant 60 fps. mind you i was just looking at the debugger and did not dig too deep into the metrics. you should explore it on your own for the use case of you game. i'd say the way to go is a mix, pure scripting does not seem like a full replacement for the evening system, they should be used in conjunction to get the most out of construct, but like i said just my opinion.

  • It's all good man, the more info the better.

  • construct arrays are actually 3 dimensional, so the array represented as json looks like this

    { "c2array": true, "size": [ 1, 1, 1 ], "data": [ [ [ "stuff" ] ] ] }

    you would need to do something like this

    + System: On start of layout

    -> Array: Set value at 0 to "{""enemies"":[2,2], ""position"":[1,2], ""wait"":[0,0]}"

    notice you have to escape the double quotes

  • the action that loads an array from json expects a very specific format. if you just wanted to store a json string in the array, you have to set one of the index of the array to json "string".

  • yeah makes sense, sometimes its just hard to resist the shiny new toys though...

  • Ashley since chrome 80, i think null coalescing has been added to javascript. it seems the scripting feature does not support the newest features being added to javascript? https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing_operator

    it's not a big deal, since this is just syntactic sugar to help code cleanliness. but this brings up the question? as new features are added to the javascript (seems to be happening at a rapid pace nowadays) will construct keep up with these features in the scripting api? I would assumes this is just adding linter support for the new feature? but it might be more complex than that.

    will construct target a specific iteration of java script? there is a snippet in the documentation

    I am not sure the overhead of having construct keep up with these changes to the language, what are your thoughts on this?

    Tagged:

  • Congrats, this game is super awesome!

  • Not for the time being sorry, I had to remove them. I might start them back up in the future, but currently it's not possible

  • is there some other method in the scripting api, to reference a specific instance that is not already picked by a c3 condition? like for code not in an event block? like we can get the first instance? and the set of all instances? and an instance by specific index, but is there a way to reference a specific instance by some condition?

    the only way i know of atm is to iterate over all instances and check for the given condition (uid == x, instvar = x ... etc) and get that instance. using array filter still has to iterate over all the instances.

    iterating over all of them is not a big deal, but i think that is where the pain point is for ppl trying to transition. they want to run some logic for a specific instance,but don't know how to to get the reference to the instance

  • when you use getDataMap(), the object that returns can be used to add change delete key value pairs.

    https://i.imgur.com/H1ZmcqO.png

    https://www.geeksforgeeks.org/map-get-javascript/

    ** and yeah you need to add a dictionary object to be able to reference it and call getDataMap()

  • in script you always have to iterate over all the instance, construct conditions are set based operations, any new condition pretty much filters out instances from the whole set. so you have multiple instances that match the condition, they will all be pick and then action should run on both. i am not sure how picking by uid is implemented internally in c3, do they iterate over all the instance and return the matching uid? or do they already have some data structure that is keeping track of the instances and they can just select the one with the uid?

    looking at c2runtime, it seems this is the approach they take,

    they have

    this.objectsByUid = {}; // maps every in-use UID (as a string) to its instance
    

    and when new instances are created

    this.objectsByUid[instance.uid.toString()] = instance;
    

    then when they look it up

    Runtime.prototype.getObjectByUID = function (uid_)
    {
    ;
    var uidstr = uid_.toString();
    if (this.objectsByUid.hasOwnProperty(uidstr))
    return this.objectsByUid[uidstr];
    else
    return null;
    };
    

    i am not sure this is how it works in c3, since the runtime is different, they might have a way better way of doing it.

  • yeah, i would say if you need to access all your instances frequently, at the start of layout i would iterate over all of them, and store them in a map (dictionary) with uid as the key, then you should be able to reference them very easily objectMap[uid], you just have to remember to add new objects if they are created at runtime.

  • so iterating over instances should be pretty fast. the optimization would be in caching, like the uid of instances don't really change so when you find it once, you can store it, and then access it for all other operation you need and those look ups would be a bit faster. since you don't have to iterate over all the instances again, but that's very negligible unless you have 1000+ instances

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • i went a bit overboard with the iterating the text input, if you know you only have one instance of sometime you can simplify it by using something

    	const textInput = runtime.objects.TextInput.getAllInstances()[0];
    

    you don't really need the first for..of loop

  • Yes so there are essential 2 ways to go about it, you either let the conditions on the event sheet pick the object for you, or you iterate over all the objects and look for the uid your looking for

    here is a quick test project https://drive.google.com/open?id=1UExW5rLfhDLtEhr0nPaT7KlX-VjjMryT

    it show both ways of picking, using a condition to guide your picking, and a purely picking in scripting (not sure if using the event system to pick has any optimizations as opposed to iterating over all the obejcts) but with that said you can merge both approaches pretty seamlessly, narrow down you instance list with a condition and then in JS, you can further narrow down and target the instances you want to deal, with, you can even abstract it out into a function that will return the specific set of IWorldInstances you want to deal with.