How to execute a group of events ?

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.
  • Hello Clickers !

    I have a question concerning the logic of MMF. Using Fusion 2.5 at the moment, trying to build a simple html5 game.

    The scenario.

    I have a group of events that perform some operations on an object.

    Now I want the same operations performed on all the objects, that I've "grouped" using the same qualifier for each object.

    So, I guess the best way to achieve what I want, is using a loop on each object having that qualifier.

    As test, I've added a single event in the loop, that writes the name of the current object. That works flawlessy as expected.

    I know that I can copy all the events that should be performed on a single object in the loop, but there's a problem: these events could be repeated on a single object, until a certain condition is reached. That's why I need a sort of a function, that can be called recursively.
    I'm aware of the "While loop" extension, but sadly it does not work for a HTML5 project.

    In other terms, I wonder if Fusion 2.5 has something like grouping a collection of events in a "Function", that can be called in the program flow in a recursively (or while--loop) manner.

    What I'm trying to achieve, is an automatic placement of ships inside a quadrant (sinking ships game). Each ship should not overlap another, that's why the events could be repeated, until this condition is met. This process should be repeated for each ship.
    I have already coded the events for a single ship, and they work as expected. The ship is correctly positioned after a bunch of tries.
    Now I want use the same events for all the ships..

    I'm aware I can make a group of events, and that this group can be activated or deactivated. But this is something different of having a bunch of events as a function, and "call" it when needed.

    I hope you get wat I mean. Sorry if my description sounds complicated.

    Any help would be greatly appreciated :)

    Have a nice day,
    Sergio

  • Thank you nixbuongiorno, but I'm aware of each loop on qualifier.

    My question was different thought. I need to execute - in a loop on qualifier - a bunch of events more times, until a condition is met.

    I try to explain with pseudo code what I mean:

    for each object that belongs to the qualifier

          repeat
                                    position the current object on the quadrant at random coordinates
                    until the current object does not collide with all the other objects that belong to the same qualifier

    next

    I hope you understand what I mean. I need something to be repeated n-times, with n variable, and that all for each object.
    Note that the extension object"while-loop" would work, but it is not compatible with HTML5, which I want to use.

    [EDIT]
    I may get the result I need using the Special "set loop index" event, which should force the current value of the loop counter. That way I may achieve a sort of "repeat--until". I have to investigate..[/EDIT]

    [EDIT] setting the loop index to a constant, does not work at all. The loop continues through all the elements. [/EDIT]

  • If I understand correctly, what you want to do is run a fastloop inside a foreach loop

    Like foreach apple create 3 worms at a random position..
    If so, that's fairly simple, in the foreach loop you run the fastloop, and to check for that, you check both conditions in the same event, meaning both the fastloop and foreach checks loop are checked (the fastloop check must be at the top)

    Something like this:

    Code
    * Start of Frame
        Start loop for each one of Apple, loop name "Spawn.Worms"
        
    * On each one of Apple, loop name "Spawn.Worms"
        Special : Start loop "Spawn.Worms" 3 times
        
    * On loop "Spawn.Worms"
    + On each one of Apple, loop name "Spawn.Worms"
         New Objects : Create Worm at X=RRandom(X Left( "Apple" ), X Right( "Apple" )), Y=RRandom(Y Top( "Apple" ), Y Bottom( "Apple" )), Layer=Layer( "Apple" )

    The above would create 3 worms at random positions relative to the apple on start of frame

    Game/App developer, artist and a community contributor.
    You can support my work on: Please login to see this link.

  • Thanks, but how would you change your code, in order to re-position a worm if it has overlapped another one ? You need to repeat the action in the loop until a certain condition is met. Look at my pseudo code above.
    The nested loop are great, but does not provide a "repeat..until" clause.
    FYI There *is* a "while..loop" extension, but it is not compatible with HTML5, which I want to use.

    By the way, your code does not spawn worms, but apples ;)

  • While loops can be achieved by running a fastloop a minus amount of times (infinite loop) and stopping it when needed

    In terms of repeat until, you can technically do that with fastloops as well, just stop the loop (and maybe use break action if needed) when applicable

    So for example, let's say I want to increase a number until it's 33, then you can do something like this:

    Code
     * Start of Frame
        Special : Start loop "IncreaseMagicNumber" -1 times
        
    * On loop "IncreaseMagicNumber"
        + MagicNumber = 33
            Special : Stop loop "IncreaseMagicNumber"
             Special : Break
             
        + Always
            Special : Add 1 to MagicNumber

    Also, you might not realize, but actually there is an if else there too, basically the value comparison is the if, and the always even after it is the else, this is mainly possible thanks to the break action

    By the way, your code does not spawn worms, but apples ;)

    Sorry it went unnoticed, I edited it👍

    Game/App developer, artist and a community contributor.
    You can support my work on: Please login to see this link.

  • Progress so far:
    I've now a for each loop on all the objects (in my case, ships). This loop basically sets a flag (posiitoning) to true on the current ship, and then call a fast loop with -1 as time (also endless fastloop).

    Inside the fastloop I move every ship (condition: flag "positioning" = true ) at a random position, check if it overlaps another ship, and a collision mask, which is also moved together witn the ship, checks for boundaries.
    If no overlaps occurs ( ship vs ship and mask vs ship ), means that the ship is now on a "legal" position, and then the flag will be set to false, and the fastloop will be broken (with stop loop).

    Now. That works in HTML5 like a charme. BUT it does not work as expected as a Windows-Application.
    I'm pulling my hears out trying to understand why. If the logic is correct ( proven because it works as HTML5), then why on earth the same logic does not work as a Win-Application ???

    I have an idea about it, and therefore a question. Could be that fastloops use a graphic BackBuffer, and update the FrontBuffer ony at the very end ? That could explain why overlapping an object is ignored. Maybe inside a browser there's no use of the same BackBuffer trick.

    Any help would be greatly appreciated.

    Regards,
    Sergio

    P.S.
    I've provided some screenshot in order to give more infos, on what I'm trying to achieve. At least, it works fine on HTML5 :)

  • IIRC there is an old, unfixed bug with some values of angle and scale in fine collision mode in the Windows runtime, when you both rotate and stretch an object. Try unchecking the fine collision detection mode for the objects you rotate and scale (it seems they don't need it in your screenshots above).

  • IIRC there is an old, unfixed bug with some values of angle and scale in fine collision mode in the Windows runtime, when you both rotate and stretch an object. Try unchecking the fine collision detection mode for the objects you rotate and scale (it seems they don't need it in your screenshots above).

    Thank you for your answer.
    I've unchecked the fine collision detection mode for all the objects (ships and mask). Sadly it didn't help. I've also tested it using only two big ships, using the mask at its full size, without rotation and scale. It also didn't help.

  • what are you trying to achieve? is it battleships? trying to manually or randomly place ships? what are you doing - maybe you need to re-think your method

    Yes it is battleships. Manually place ships works. Randomly place works too, but only when the application runs as HTML5. The same logic does not work on Windows-Application.
    This puzzles me. If you read carefully my above posts,you'll see what I'm doing.

    It works flawlessy as HTML5, as already said. But I'm asking here why the same logic has a different behaviour when runs as Windows-Application.

    Yes I could re-think the method, but I'm reluctant in doing this, because simply put, the method I have coded works already. And it's quite simple and straitforward.

  • A side note.

    So far, the logic described above (see screenshot) works fine in HTML5.

    If I run the application as a Windows-Executable, it does not. But ! If I run the code as a windows-exe, using only one ship, it works too.

    Conclusion: the problem arises when two or more ships are involved in a loop. That enforces my suspects about a connection between for..each loops together with fastloops, and the graphics backbuffer. I'm not sure but I *think* that a for..each loop considers all the elements ( having the same qualifier ) in a parallel manner, that is, at the same moment and not one after another. And everything is so fast, that inside the backbuffer no overlapping event occurs. Perhaps each of these parallel threads uses its own backbuffer. That would explain why moving a ship on that single backbuffer produces no collision/overlaps, because that single backbuffer contains only that ship. Thus, at the end, when all the backbuffer are merged to the frontbuffer, the ships are all messed up, because they did not follow any placement criteria.

    Perhaps with HTML5, things work in a different manner, that is, there's only one backbuffer or perhaps only the frontbuffer will be used. When that is the case, it explains also why the overlapping tests work as expected.

    This is my "logically" explanation so far, in the attempt to find a plausible reason of this behaviour, which really puzzles me because it screws up the logic of a working code - remember: as HTML5 works with all ships together, and as Windows-app works too but only with a single ship moving against the other ships, which don't move. Again, this proves that the logic works also in a windows-application, at least with one ship at a time.

    [RANT]
    It is quite frustrating having the same code working flawlessy on a platform and not on another. That kills the "one code - more targets" concept in my opinion, and should be addressed.
    [/RANT]

  • That enforces my suspects about a relation betwee for..each loops - and fastloops - and the graphics backbuffer. I'm not sure but I *think* that a for..each loop fires all the elements ( having the same qualifier ) in a parallel manner, that is, at the same moment and not one after another. And everything is so fast, that inside the backbuffer no overlapping event occurs.

    No? events are read every frame from top to bottom, one after the other, rendering is one of the last things that happen..

    Fusion is a synchronous engine in most parts (extensions can utilize multithreading, but they are limited in what they can multithread, for example, an extension cannot run a Fusion event from another thread, if an extension tried to do that, the runtime would just crash)

    Fastloops are like repeated events, so repeating an event where you add lines to a list 4 times, is like running a fastloop 4 times where on the loop check you add a line to a list

    Kinda of the same thing with foreach loops, though, foreach loops do loop on the filtered objects by the event it ran in, one instance after the other at a time (the order goes from the last created filtered object to the first filtered object) nothing is done at the same time, on each object, it selects it, this is where the "On foreach loop" check is triggered

    The only "weird" thing about foreach loops that is considered asynchronous, as in running with a delay (but NOT multithreaded) by some, is that they run after all the actions of an event (the filtration of objects "storing object selection" is still done in the correct action order though) you can avoid that by running foreach loops in a different event, child events greatly help because they also store the selection of the parent event and you don't have to repeat the same event with the same conditions again

    But in case of fastloops, they run in the same exact action order, but that comes with a cost of losing object selection data, breaking the object selection of the event that ran it (for any actions after the fastloop call) and even affecting the action before it due to being so immediate, that actions like Set Flag of object to ON, would only apply to 1 filtered instance, then the others AFTER the fastloop finishes

    And by the way, foreach loops are not the only part of Fusion that has "delay" element to it, for example, the destroy object action only marks the object for deletion, but the object is only actually deleted after the end of the event, and the object count is even more delayed being updated the next app loop (frame)

    All in all, fastloops and foreach loops are single threaded, nothing happens in parallel or "so fast", each loop is ran one after the other in order until the loop is finished, for example, if a fastlooop or a foreach loop cought on an infinite routine, the next app loop would never happen, in fact, no other events would run until the loop is finished, that means the game would freeze in place until the loops are done

    [RANT]
    It is quite infuriating having the same code working flawlessy on a platform and not on another. That kills the "one code - more targets" concept in my opinion, and should be addressed.
    [/RANT]

    Each runtime has it's own ways of doing things, Fusion runtime is written foreach single platform and tries to unify what can be unified, for example, any new feature or a bug that is meant to be cross platform, has to be done manually foreach single runtime

    Of course, some stuff cannot be done for compatibility reasons, platform restrictions or simply being too much work to implement for one or more runtimes, hence why some features are windows only, or how the screen zoom objects is available on anything but Windows..etc

    This also leads to some stuff having differences between each runtime due to the reasons I said above, or not even working properly due to an oversight
    for example, on the iOS runtime, in the first few months I used it, I went on and reported over 10 different bugs that do not exist on other runtimes, some were not discovered for over a decade, like arrays not saving in unicode only on iOS runtime (it was fixed though, most of what I reported is now fixed)

    So as I said above, it's normal for stuff to behave differently on other runtimes, other examples would include how online file retrieve via path is possible on other runtime but not on windows (you instead have to download the file via an object like th download object)or how "Load frame\animation" actions of the active object is not yet implemented on runtimes other than windows..etc

    In case of the fine collisions issue with rotated and scaled objects that only happen on the windows runtime is an old, known issue as Yves said above

    Game/App developer, artist and a community contributor.
    You can support my work on: Please login to see this link.

  • Hey Linky,
    many many thanks for your detailed answer ! Those are important aspects of loops, fastloops and the Fusion engine, which I didn't be aware of.

    Anyway.

    I want only emphasize, that the logic I have wrote does work also as windows application, but only if I process one ship at a time.

    That means, we are not facing - IMHO - the "bug with rotated and scaled objects that only happen on the windows runtime". Because it wouldn't work in every case (single or multiple objects ).

    FYI I have tested it with rotated ans scaled objects, and without. And again, in both cases it does workas windows application, but only by processing a single ship.

    The problem arises when I try to perform the same logic using a for..each loop (which calls a fast loop - screenshot above ).

    That's why I'm quite convinced that this particular behaviour has nothing to do with the "known old issue with windows collision" stated above. IMHO.

    Question.
    Is there any way to slow down a fast loop ? I'm aware of the "slow loop" extension, but it works only with windows-applications and not with HTML5.

    Thanks for your kind attention,
    Sergio

  • I have an idea. Right now I randomly place each single ship on the board, then place the collision mask at the ship coordinates, in order to check for adiacent collisions.

    The idea is to let the ship there - or, better, move it outside the frame - and randomly place only the collision mask, scaled and rotated accordingly with the current ship.

    In this way only the mask is moved around the board, searching for a place, while the ships remains on the board. Once the mask has found a place which adhere to the collision rules, then the (outside moved) ship will put in place of the mask. And the same logic should be performed for every single ship.

    I'll try it. Maybe solves this issue. I really hope so ;)

Participate now!

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