User Tag List

Results 1 to 3 of 3

Thread: Nested Foreach loops and Physics Engine

  1. #1
    Clicker Fusion 2.5 (Steam)

    Join Date
    Jul 2014
    Posts
    92
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Nested Foreach loops and Physics Engine

    I am having trouble with For-Each scope with nest for each loops. I do the following:

    For each Group.Vehicle
    "Movecar"

    On each group.vehicle, loop name "Movecar"
    +State = 1
    - Set X vehicle postition to = value at CarArray(vehicle.alterablevalueA (ID), 2,1)
    - Set Y vehicle postition to = value at CarArray(vehicle.alterablevalueA (ID), 3,1)

    On each group.vehicle, loop name "Movecar"
    +State = 7
    - apply impulse 100 angle 0
    - set RGB coefficent to red

    Outside of all these loops I have a normal collision event
    Player collides with group.vehicles
    -set vehicle state = 7

    What I want to happen: When in state 1 set the position of each vehicle is positioned to what is indicated in the array [works fine].
    What I also want to happen: When a player collides with a vehicle that vehicle changes state and should stop setting its position to what is shown in the array. Instead an impluse is applied to that object and it flies away freely using the physics engine. Also I change the car's RGB cofficent to red.

    What actually happens: When not collided everything works as it should. When the player collides with the vehicle the vehicle it collides with turns red (as it should). However, the impluse does not apply until I collide with every vehicle created. All vehicles get stuck in their last position before the collision happened until I collide into all of them.

    Basically it traps their position to the array even though it shouldn't. Physics will not apply until I collide with all objects. It doesn't seem to be a scoping problem as only the car that gets hit turns red. Anyone have any clue on what is going wrong?

    Note: If I remove event setting position when it's in state 1 it applies the impulse properly. So I know the problem is related with the setting a position.Source events.jpg

  2. #2
    Clicker Fusion 2.5 (Steam)

    Join Date
    Jul 2014
    Posts
    92
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    NEW Discovery:

    I am losing object scope in my for each loop after the fastloop it executes.

    Example:

    Event:
    On each vehicle, loop name "moveCar"
    + State = 7
    => activate group "testmove"
    => startloop "testmove" (this is a fastloop
    => deactivate group "testmove"
    => vehicle set rgb coeifficent to 100

    Result: all vehicles turn red

    Now if we change the order of the what happens in the event (i.e. put the scoped activity before the fastloop)

    Event:
    On each vehicle, loop name "moveCar"
    + State = 7
    => vehicle set rgb coeifficent to 100
    => activate group "testmove"
    => startloop "testmove" (this is a fastloop)
    => deactivate group "testmove"


    Result: Only the vehicle with a state = 7 changes red (as it should as scope is retained)

    Can someone explain how foreach loops and fastloops are interacting here? I just don't understand it.

  3. #3
    Clicker Fusion 2.5 (Steam)

    Join Date
    Jul 2014
    Posts
    92
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Solved by myself.

    Lesson for others: fastloops actions in foreach loop events will remove object scope for all actions after the fast loop call.

    Solution: make another event right after to update position so you get your scope back.

    I.e. On each car - call fastloop cal new coordinates
    - turn on flag to update position

    On each car and flag to update is 1 then.
    - car position x equals newposition

Similar Threads

  1. Nested ForEach loops?
    By King_Cool in forum Multimedia Fusion 2 - Technical Support
    Replies: 4
    Last Post: 10th March 2017, 05:05 PM
  2. Nested Foreach loops
    By Pixelthief in forum Fusion 2.5
    Replies: 6
    Last Post: 8th June 2014, 05:52 AM
  3. homing torpedos & nested loops
    By Shabadage in forum Multimedia Fusion 2 - Technical Support
    Replies: 5
    Last Post: 25th January 2010, 03:23 PM
  4. Nested loops and get loopindex
    By Shadoku in forum Multimedia Fusion 2 - Technical Support
    Replies: 2
    Last Post: 27th September 2007, 04:13 PM
  5. nested loops
    By westray in forum Multimedia Fusion 2 - Technical Support
    Replies: 7
    Last Post: 14th December 2006, 04:00 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •