piranha305's Forum Posts

  • 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

  • Try Construct 3

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

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

  • https://piranha305.itch.io/tanktrax has the c3p file for the tank game.

  • Ashley can that loading happen across layouts? so if i load an object on the first layout, will it have to be placed in to the next layout as well, or will it remain in memory?

  • i don't see why you have to limit yourself to a sprite? using a sprite might make thinsg easier in some case (animations, editable bounding box, solid collision) but using a tiled background is pretty valid if you have the right use case for it. i mean it's just a tileable sprite without some of the functionality ? just cause it has background in the name does not mean it has to be exclusively in the background? you can use it health bars and a ton of other stuff (non background) ?

  • if you really wanted to use tiles for this my not just just a tile map instead? tilemaps support collision

  • Never really used this myself, but if u really wanted linq there are alternatives. github.com/mihaifm/linq

  • no man, you got me wrong, that not how i intended to sound, I am also a professional dotnet developer, 7 years, not as tenured as you. I was just pointing out that that the standard dot net library will not provide you that much benefit, if you port it to wasm to use in javascript, not just will you face the interoperability cost, you will also not get much from most of the dotnet standard classes that deal with low level os calls, File system. Since c3 is run from a browser, you will hit the browsers sandboxed limitation, and even using 3rd party library (any unity api is out of the question since those are compiled to mono), but you will also have compile those down to wen assembly.

    on that note, one of the guys who use to work at microsoft started working WebWindow (https://blog.stevensanderson.com/2019/11/18/2019-11-18-webwindow-a-cross-platform-webview-for-dotnet-core/) which if it gets mature could be of interest to wrap construct3 games.

  • Dot net core has an upcoming web framework called blazor. Which hosts the dotnet framework in web assembly. I am not sure if that's coupled with the blazor framework. If they have it in separate wasm file you might be able to leverage it, but only the dotnet standard libs, 3rd party dotnet library won't work. and to be honest I don't really see alot of benefit adding the dotnet framework on top of c3. Any thing you think you need dotnet for will probably be easier in javascript