Please add more templates and tutorials on scripting

2 favourites
From the Asset Store
Fruit Slicer Template & Quality fruit and slice graphics (c3p,png,illustrator files)
  • To make it more clear if I have 2000 Instances of one object and I need to make some changes to just one particular instance, do I have to loop throughout all the 2000 instances? is that how js works?

    Can I not just go directly to that one instance and make changes?

  • You can pass instances around directly, so you generally don't need UIDs. If you have already got an instance reference, you can just keep using it, there's no need to loop through all instances.

    I'm still making the same point: you need to think about scripting with a different approach.

    You can't save instances to storage though, so I guess you need UIDs for that. I'll look in to adding a scripting method to get an instance by its UID, but as I keep repeating, this isn't something you should need for general purpose code. I am sure there are pure JS engines out there that do not use anything like UIDs at all. You can go a long way without them in code.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You can pass instances around directly, so you generally don't need UIDs. If you have already got an instance reference, you can just keep using it, there's no need to loop through all instances.

    I'm still making the same point: you need to think about scripting with a different approach.

    You can't save instances to storage though, so I guess you need UIDs for that. I'll look in to adding a scripting method to get an instance by its UID, but as I keep repeating, this isn't something you should need for general purpose code. I am sure there are pure JS engines out there that do not use anything like UIDs at all. You can go a long way without them in code.

    Awesome!!! Thanks very much for adding it, that will be really helpful at least jus to work with Construct as we been doing till now, I fully understand now that normally they don't use UID in js and I should always look to try to learn how to work without UIDs as that is how they work on real programing as you try to advise me and I thank you for the advice and showing us the right way for js programing. I will keep it in mind as I would like to code in the right way, but for now they UID when you added, is gonna be really helpful as we got used to it so at least we can start experimenting with js with something that we are already familiar with to keep going then slowly learn how to properly code and hopefully in the future once we get more experience we can slowly get rid of the UIDs.

    Unfortunately, I cannot see now the difference as I'm very new but hopefully I will see what you mean in the future as I learn.

    I'm glad that we finally understand each other )))))

    Thanks a lot for your help and Time

  • One thing I'm curious how the construct engine works when you use the UID?

    I thought it was using some kind of storage and then you call directly the instance when you use the pick by UID without looping throughout all the instances, is it not that the same thing?

    Somehow you managed to do for the engine, shouldn't we can replicate that? probably you need a lot of experience to do that I guess

  • You can use Maps (same as used by the Dictionary object) for fast lookups without having to loop through whole arrays. Construct uses them for UID lookups, for example.

  • You can use Maps (same as used by the Dictionary object) for fast lookups without having to loop through whole arrays. Construct uses them for UID lookups, for example.

    Hoh thank you that sounds quite good, it sounds like will have even better performance if it's done directly through the "Map" instead of the UID but it must be very advance to set it up, probably not for beginners.

    Will it be possible in the future if anyone at Scirra has spare time to include a mini temple to show how the Map its implemented so we can learn the proper way? That will be Awesome ))

    If is not possible is ok

    Thanks for your Time

  • There's absolutely tons of information about JavaScript out there, it's really best to rely on what's already there instead of asking here. For example just click that link I sent you, and scroll down to "Examples". That should be exactly what you just asked for. It looks pretty straightforward, hopefully it's understandable even for a beginner.

  • There's absolutely tons of information about JavaScript out there, it's really best to rely on what's already there instead of asking here. For example just click that link I sent you, and scroll down to "Examples". That should be exactly what you just asked for. It looks pretty straightforward, hopefully it's understandable even for a beginner.

    Sure no problem, Thanks anyway

  • Here are a few basic examples of using Map.

    Map examples

  • Here are a few basic examples of using Map.

    Map examples

    Awesome Thank you very much sizcoz for taking the time and for adding many varieties of examples and plus commenting it, that's really grate.

    I'm sure is gonna be really helpful for other people also that just started learning js and stumble on this thread.

    I also will try adding to this thread if I learn one day ))

    We have already some really good examples on this thread so they can have a good start.

  • Also, I'm gonna leave this here so all the examples are together, its Thanks to Piranha305 he did it.

    How to use Dictionary with js

    More Info about Dictionary:

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

    Theard Link: https://www.construct.net/en/forum/construct-3/scripting-51/dictionary-apis-working-150936

  • Just adding another example of using arrays & events.

    Array examples

  • Just adding another example of using arrays & events.

    Array examples

    Awesome sizcoz really nice addition, Thank you

  • Here is one for how to Pick instances directly by UID with the new "getInstanceByUid" that Ashley added, Really handy Thank you for adding it.

    The best thing about the new Pick by UID is that you don't have to reference it first on the scripting with "const Variable = "

    C3P: https://www.dropbox.com/s/8x315bbnfex7etf/Pick%20by%20UID.c3p?dl=0

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