tarek2's Recent Forum Activity

  • Hi,

    I have been trying for many hours how to do a dictionary.ForEach and consol.log the values

    I followed the examples that they show on the Manual

    I tried many things for example:

    const Map = dictionary.getDataMap();

    Map.forEach(callback[,]);

    console.log(Map.foreach());

    Etc....

    Thank you

  • 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

  • Try Construct 3

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

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

  • 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

  • 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

  • Hi tarek, sorry for not replying yesterday. I was swamped... Alright, so I went back and had a look at what I came up with. I ended up using the event-sheet and a 2D array.

    Edit 1:

    Patrol 0 is moving left and patrol 1 is moving right.

    Edit 2:

    I only use the scripting when I can't get something to work with the event-sheet. Which is not often.

    Let me know if you have any additional questions.

    Ho no worries thanks very much)

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

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

  • 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

  • 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 see Thanks Ashley

    I wasn't sure what to do sorry

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