if I’m stacking up a same instances with different ID, and once left is pressed, each of them goes one by one to the left with a little delay, how do I write it without repeat? Because it keeps falling so repeat only works at the moment when the instance was already given ID, newly created instance won’t react to the action.
I would make your stack a state machine:
- The “Ready” state would be the default state. It waits until you press left, then switches to the “Shooting” state.
- The “Shooting” state picks the object at the bottom of the list and adds a force to it, then goes to the “Waiting” state if the list is not empty, or back to the “Ready” state if the list is empty.
- The “Waiting” state resets a timer when you switch into the state. When 0.1s has elapsed on the timer, it switched to the “Shooting” state.
Sorry I mean move it one by one with 0.1s delay, like 1 moves first, then 2, then 3…
yeah
need more help, the difficult part is not changing the state but how to pass state from 1 to 2 to infinite without a repeat.
selecting the right instance is difficult.
I got stuck at this logic.
HELP.
The state machine I describe inherently does that.
It depends on how you modellized your stack. Assuming, since you are saying you gave each object a unique ID, that your stack is represented by an array of the objects IDs, and that you add objects to the stack by appending an object ID at the end of the array, you can use following logic for the “Shooting” state I previously described (pseudocode):
if State == "Shooting" {
if MyObject.ID == StackArray[0] {
AddForceOnXAxis(MyObject, -20)
}
RemoveChildAt(StackArray, 0)
if VariableChildCount(StackArray) == 0 {
SetVariable(State, "Ready")
}
if VariableChildCount(StackArray) != 0 {
SetVariable(State, "Waiting")
}
}
Thank you! Array variables gives me a new way to think about the logic! This has been the most useful answer of all.