tarek2's Recent Forum Activity

  • 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()

    Awesome Thank you very much piranha305 all your examples have been incredibly helpful )))

  • Hi

    I couldn't see the code that you use to use the dictionary on scripting

    -Add key

    -Set key

    -Get key

    etc...

    Also, do we add the Dictionary as normal from the editor as we do for events or it works different and you have to create it by scripting?

    Tagged:

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

  • Thanks a lot chunchun really helpful

    DFORMS No worries mate, thanks for responding

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

  • Try Construct 3

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

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

  • 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

  • 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

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

  • 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

    Ho cool no worries, Thanks for the update

    Lots of good info today hope I can learn some Js quick

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

    Awesome!! Thanks so much for your help and for Commenting the whole process really helpful, I really appreciate it, I'm gonna play with it see how far I can go ))

    (not sure if using the event system to pick has any optimizations as opposed to iterating over all the obejcts)

    I see, good question I was looking for that Answer too lol, I hope Ashley can give us some hints, I was looking for how to Pick by UID because I thought that would be the most optimized method like when we pick with the Events & UID but it looks like with JS is all a bit different, there is a lot to learn jeje, will be nice to see some BenchMarks of at least the Picking which one is faster ) and different benchmarks also anything related to (JS Vs Events) I'm surprised no one has done it yet as it's been quite a while since the Scripting has been released

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

    Ho Woow Thanks very much that is gonna be really helpful :)

    Any chance that you know how to pick by UID?

    They have it here but it doesn't say how to use it

    https://www.construct.net/en/make-games/manuals/construct-3/scripting/scripting-reference/object-interfaces/iinstance

tarek2's avatar

tarek2

Early Adopter

Member since 26 Jan, 2016

Twitter
tarek2 has 12 followers

Trophy Case

  • 8-Year Club
  • Forum Contributor Made 100 posts in the forums
  • Forum Patron Made 500 posts in the forums
  • Forum Hero Made 1,000 posts in the forums
  • Regular Visitor Visited Construct.net 7 days in a row
  • RTFM Read the fabulous manual
  • x5
    Great Comment One of your comments gets 3 upvotes
  • Email Verified

Progress

15/44
How to earn trophies