piranha305's Recent Forum Activity

  • 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

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

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • https://piranha305.itch.io/tanktrax has the c3p file for the tank game.

piranha305's avatar

piranha305

Early Adopter

Member since 26 Apr, 2016

Twitter
piranha305 has 34 followers

Connect with piranha305

Trophy Case

  • 8-Year Club
  • Jupiter Mission Supports Gordon's mission to Jupiter
  • Forum Contributor Made 100 posts in the forums
  • x6
    Coach One of your tutorials has over 1,000 readers
  • Regular Visitor Visited Construct.net 7 days in a row
  • Steady Visitor Visited Construct.net 30 days in a row
  • RTFM Read the fabulous manual
  • x5
    Quick Draw First 5 people to up-vote a new Construct 3 release
  • x3
    Lightning Draw First person to up-vote a new Construct 3 release
  • Great Comment One of your comments gets 3 upvotes
  • Email Verified

Progress

18/44
How to earn trophies