Welcome to our brand new Clickteam Community Hub! We hope you will enjoy using the new features, which we will be further expanding in the coming months.

A few features including Passport are unavailable initially whilst we monitor stability of the new platform, we hope to bring these online very soon. Small issues will crop up following the import from our old system, including some message formatting, translation accuracy and other things.

Thank you for your patience whilst we've worked on this and we look forward to more exciting community developments soon!

Clickteam.
  • Quick question to the memory buffs:

    Which is better for optimum performance:

    A)
    Counter = 1, set maximum heath to 100

    Counter = 2, set maximum health to 150
    etc, etc

    or

    B)
    Counter = 1, set maximum heath to 100
    Limit condition (once every time it happens)

    Counter = 2, set maximum health to 100
    Limit condition (once every time it happens)
    etc, etc


    Obviously (A) will keep on firing as an event whereas (B) will fire once for each when it happens then stop checking.

    So, what is better:
    shorter code overall, but let MMF constantly test the event at runtime; or
    longer code overall, but reduce what MMF is checking each cycle.


    This is just a small scale example btw -I just generally want to start coding more efficiently - have there been any particularly good memory optimisation threads on the forums recently that spring to mind?

    IndieDB Page: Please login to see this link.
    Development Blog: Please login to see this link.

  • The general rule to efficiency is to do as little as possible, as few times as possible. In your case, setting the maximum health to the same thing every frame is not only pointlessly ineffectient, but it's also unclear as to why. Rather that the "when this, do that" you have repetitve checks which isn't as logical, and logic, in coding, is everything.
    I would change the actual events where Counter is changed to 1 or 2, rather than check it as a response. What you're doing appears to be:
    On A, set counter to x. On counter is x, set max health to y.
    rather than:
    On A, set counter to x, and set max health to y.
    or even:
    On A, set max health to y.
    (A being the original events where you change Counter)


    You could also look into use of global values, as counters are a lot more memory and not so easy to keep track of. There's only one global value no matter what you have on the frame, but you can have several copies of a counter which will conflict with each other.

    Darkwire Software Lead Programmer (C++ & C#)
    Please login to see this link. | Please login to see this link. | Please login to see this link. | Please login to see this link.

  • Doing one action when event loops still reads and tests the conditions, so you'd only be saving resources for the actions. If you must always do a check for the amount of maximum health, it's probably best to just do:

    Always = set max health to 100+(CounterValue*50)

    You can also have it be this way with renamed global values, as Phi suggests:

    Always = set max health to InitialHealth+(HealthUpgrade*HealthMultiplier)

    InitialHealth = 100
    HealthUpgrade = Your counter value - 1, 2, 3, etc.
    HealthMultiplier = How much health is added per upgrade.

    For this kind of thing, probably almost no resources are wasted anyway. But since they pile up eventually, it's good you're trying to optimise it from the start.

    Please login to see this link. - Metroidvania RPG (Win/OSX/linux & PS4/Vita/Wii U)

  • A small detail I want to mention is that lot of people mistakenly think that an action is always heavier than a condition. You can often end up in a scenario where the conditions that checks if the action should be performed are heavier than just performing the action on every frame.

    Setting the maximum health is so light that you don't have to worry about it. In cases where it's heavy, you should benchmark the different options.

  • Thanks for the responses, the example was just an example rather than a specific problem I'm having - my main qualm was whether shorter code or reduced checks each cycle was better (which Niffy touched on in his response) so I can generally code a touch more efficiently.

    Phi - I'll have a look through my code as I think I may have done some doubling up on things actually - naturally it makes sense to just set the max value of the counter when the event triggers to change the counter (which shows the current max health level) rather than set one thing to do another thing!

    Alonso - the increments are not linear, and don't increase perfectly with a calculation (my OCD won't allow max health to be something like 745, I'd have to set that to 750 lol) so I can't use an algorithm to sort out the max value.

    IndieDB Page: Please login to see this link.
    Development Blog: Please login to see this link.

  • Well, I offered that solution judging by what you asked for. There's no way I can predict details you haven't yet mentioned (: You can include sine functions in the max health formula if you want to have variations between each interval. You can pretty much get any result you want with the appropriate expression. Also, I find it much more advantageous and efficient to do this kind of thing in one action instead of using several events. What is OCD in this context, by the way?

    Please login to see this link. - Metroidvania RPG (Win/OSX/linux & PS4/Vita/Wii U)

  • Yeah, I'm sure there would be a way of using maths to sort it out, and that would certainly increase performance.4

    OCD being obsessive compulsive disorder, it was a joke (sort of...) I don't like un-rounded numbers or things that are out of line - that sort of thing.

    IndieDB Page: Please login to see this link.
    Development Blog: Please login to see this link.

  • I think it's a lot about balancing it right. When it comes to tasks that are very CPU friendly, I always go for the solution which results in the cleanest and most understandable events even if it turns out to be slightly heavier. When it really matters, I benchmark a few solutions by running a fastloop that carries out the same operation tons of times per frame and check what framerate I get.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!