Please add more templates and tutorials on scripting

2 favourites
From the Asset Store
Background Story generation templates. See the Arcade demo.
  • 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

    Indeed that is what I was looking for to do, I see that you used on here:

    //we only have one text box, but lets pick it by it's uid (5)

    for(const input of textInputs){

    //we have picked the text box with uid 5

    if(input.uid === 5)

    so I suppose this the way to pick directly the UID without looping through all the instances if I already have saved the UID example on a variable or Dictionary?

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

  • I think there is a bug with the Mouse Plugin

    Event 1 the condition says on left-clicked but it doesn't work and it works only when you right-click on the object, if you deactivate all the events and leave only event 1 you will be able to reproduce 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.

    Ho Grate Thanks

    Is the objectMap[uid] is how you reference the dictionary? or it's different unique just for JS

    Will be awesome if you had an example saving the UIDS on Dictionary and then Pick one UID directly from the objectMap[uid]

    This is the last thing I was looking for to start playing around and testing

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

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

    Woow Awesome Thanks a lot that is Amazing def this it should be as a tutorial on how they do it with c3 as its really important I would say the most important thing to learn how to pick by UID as is the only way to get good performance at least on Mobile, I hope Ashley sees this and can confirm if it's done like this so we can use it Ashley

    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?

    Def they store the (UID & IID) of the objects as its not the same as when you use pick by comparison as Pick, by comparison, it always loops through all the instance of that object and its the opposite for the (UID & IID) as they pick it directly, I can't remember how they store them exactly something like an Array or List something like that but def its much better to pick them directly especially when you big amount of instances

  • The way events work is pretty significantly different from JavaScript coding, and the typical patterns you'll use to get things done are different. So it's best not to try and think of questions like "how do I make this event in script", it's better to change your perspective to "how do I do what I need to do with JavaScript coding". For example often picking by UID is used when calling functions in events in order to pass an instance, but you should not do this in JavaScript, because you can pass an instance directly. This makes the question "how do I pick by UID?" redundant and basically wrong to ask, so (as is pretty much always the case with help anyway) it's best to focus on your goal and how to get there, not some random details.

    I must strongly discourage you from looking at the C2 runtime code. Much of it is nearly 10 years old and you can generally do much better with modern JS features. For example you pointed out some code that is far more suitable for a Map, and the only reason the C2 runtime doesn't do that, is because it didn't exist when it was first written.

  • Thanks very much for your time Ashley

    I see what you mean that we need to think differently and not on the c2 world thanks for the advice however every construct user is goona end up thinking in the same way, for this reason, could I recommend a few things? but obviously, if you think it's wrong you can ignore it, this is just my observation based on my very sort experience testing the scripting.

    If could recommend some "Scirra made" Very short Tutorials but targeted to C2 users that been using the engine for a while so you could correct them in how they not suppose to think as you did with me and this you could do it by adding a few quick very short temples or Tutorials to teach that they not suppose to do it that way:

    This will be my recommendation for Short Tutorials or Demos:

    Picking:

    1-How to pick an object by "Comparation" iterating through all the instances and pick the ones that match the condition

    2-Pick by UID or like you said the equivalent in JS to pick directly without iterating through all the instances and best practice to follow to get the best performance.

    3-Advance Picking: Pick an object which has stored on his Instance Variable some UIDs or as you explained the JS equivalent that Picks other objects directly as the UID does.

    Behaviours:

    Because now we know how to do basic Picking we can start manipulating their Behaviours

    1-How to manipulate the behaviours of the picked objects

    Variables:

    1-How to manipulate (Global, Local, Instance Variables, Booleans) etc...

    I think for starting this will be really good for people like me that they just wanted to quickly test the scripting and see how is working. Even these some random details are gonna be helpful because you can combine them with events whenever gets stuck, the point is to get started and then you can learn and improve as you go.

    This is the equivalent as when you start with construct that they show you in a tutorial for beginners to create a square object add the Platform behaviour and keyboard and you can start jumping and get excited already, so that gives you the motivation to learn more and put more effort instead of starting from the boring part of learning the whole Javascript syntax because you may get bored quickly but if you start already interacting with construct and the objects like make them move, Jump, etc.... it's more exciting and then the boring part it becomes less boring at least for me. So basically something that gets you started right away then you do after the whole JS study bit by bit.

    But this is just my view and it may be different for other people, so if you think its wrong or is not worth it you can just ignore it, it's all good.

    Lastly, I would like to add that the more you teach your user base how to use your engine and get best performance best practices and stuff, the more Good Games we will make.

    Thank you for your time.

  • I just noticed that the Mouse Bug that I mentioned yesterday it wasn't a bug, it was code running from the "Script.js" which I didn't see it yesterday ))

  • The whole idea of "picking" is exactly what I said before. It doesn't really apply to scripting. You have to adopt a different approach. I guess you could use a series of array filters, but it's not really the typical style for game programming in JavaScript.

  • 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

  • Yes, look in the scripting reference, there are already methods to get first/all instances for both picked and all created instances.

  • Thanks piranha305 for the explanation that is exactly what I'm trying to do, especially for a custom Pathfinder which has to loop through hundreds of instances, I would like to know if we can pick directly as we do with UID so we don't have to loop through all the instances, this is very important to keep it up with Performance especially in Apps for Mobiles

  • I have to ask again, why are you trying to pick by UID in script? Usually the normal thing to do is just pass an instance reference directly, so there is no need for UIDs. Are you passing UIDs between events and scripts or something?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I have to ask again, why are you trying to pick by UID in script? Usually the normal thing to do is just pass an instance reference directly, so there is no need for UIDs. Are you passing UIDs between events and scripts or something?

    I would like to do it fully by Scripting if it's possible whichever is faster, when I say by UID I mean something similar as long as they work similar, for me the most important is Pick the object directly without looping through all the instances as Pirana explained, I'm new so I'm not sure which name they call it on js but something that works the same as when we use the UID, it doesn't have to be necessary UID if you say there is a better alternative but if you be kind to show us an example of the better way that your describing will be awesome

    Also, an important point here is that they will be stored some were like a dictionary or something like that so you can just (get or reference) the instances whenever you need to directly, does this makes more sense?

    maybe I can try to explain it better

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)