[solved]Clone collision on only the last clone

[Solution: in the like unused to detect collision and turn off a variable I used an else statement to have it activate without collision. But the else statement was activating regardless. So I just moved that activation before collision detection and it works fine now]

.I’m working on a grid movement system, and I want to be able to have a lot of walls to be able to make a map.

The collision for the wall works well and so does the movement.

I’m able to clone the wall and apply collision to it, as well as place it.
However when I attempt to do so again, it paces the wall but it doesn’t have collision.
I assume it has to do with the “w” variable but I’m not sure why it only applies to the most recent, and not all of them.

To see the collision detectors while running, press shift.My Project (8).wick.zip (12.3 KB)

The cube in the top left is the parent that I am cloning.
The black dots are the collision detectors.

Simple WASD controls.
Diagonals work.

1 Like

I’m seriously reconsidering what I thought was bad-looking code. Your player clip’s scripts might be actually just assembly.

First, I strongly advise against using global variables (when you don’t put project., this., let , const, or var before the variable declaration), if re-use the same global variable, you’re going to have a race condition which will cause weird bugs.

Second, don’t shorten your names into X86 registers. LDA, LUA, RDA. When you wrote this code, only you and the universe knew it, now not even the universe knows it anymore. Instead, just actually name the variables. velocity instead of v, deltaTime instead of dt, you’re not doing math, just name it simply.

Third, in EcmaScript/JavaScript, the single ampersand operator (&) is Binary AND . For the actual, Logical AND, use the double ampersand operator (&&). Same for OR.

Forth. The double equals operator (==) does some casting to simplify for beginners. This means ("3" == 3) === true. For most occasions, the triple equals/identity equals operator (===) is better.

Fifth. Code lines are separated by the semicolon (;), while using the comma (,) operator is technically right, it’s meant to be used in for loops.

for(var i = 0, var j = 0; i < groups.length, j < groups[i].length; i++, j++)
{
  var clips = groups[i];
  var clip  = clips[j];
}

Sixth. You’re supposed to put a line-break (enter key) at the start and end of a block ({ /*code*/ })

function squared(x) { // using the C-style
  return x * x;
}

function cubed(y) // using the Enterprise Java / C# / PHP style
{
  return x * x * x;
}

/* the way you're doing it */
function makeSquare(size, x, y){return {size, x, y}}
function isSquare(sqr) {return typeof sqr=='object'&typeof sqr.x=='number'&typeof sqr.y=='number'&typeof sqr.size=='number'}

Yo, mb for not getting to this sooner. But fixed it. The else part was just still activating for some reason. I just removed that and put the variable set behind it so collision would override if it was detected.
I get that I don’t format stuff too well but this is just easier for me.
Idk.
My brain notices what’s going on better.

Well if it works for you, then it’s ok. I just advise to follow the things I said with binary vs. logical OR/AND in JS. While True (1) and False (0) work with binary OR/AND, this is not correct. And also the triple equals, you’re going to mad doing certain things with double equals, since it bends everything to one type before actually checking. Like ([] == false) === true.