Javascript Help Thread

What Wick Editor Version are you using?
1.9

Describe the Problem
Im getting errors while writing this.
var pp = arrowX + 20 ;

What have you tried so far?
Google and javascript guides.

btw pp is the name of the variable. dont ask why lol.

maybe you declared pp as var before or maybe arrowX is not defined

Could you please post your project to help you better?

If you haven’t defined “arrowX”, its a syntax error. A arrow X position? Instead of

arrowX

Use

arrow.x

If this doesn’t help, well I don’t have a solution.

1 Like

you may need to use [clip].pp depending on the situation. [clip] is the name of the clip that owns pp, it might be “this”. same goes for arrowX. if you got confused thinking that mouseX = mouse.x, etc, mouseX is its own variable that gets the mouse’s x value. unless there is a variable called arrowX, you need to use arrow.x.

arrowX and pp1-1-2021_2-36-40PM.wick (1.9 KB)
Does this help?

There’s nothing wrong with the syntax of that line, so it’s not a syntax error. Probably arrowX is not defined. That would result in a ReferenceError. This could be because you wrote arrowX = 3 in a different script and tried using it. If that is the case, instead you should write this.arrowX = 3 and replace that line with var pp = this.arrowX + 20; (the number of spaces before the semicolon doesn’t matter). Or arrow could be an object with two properties x and y representing a point in space, and if that is the case you should write arrow.x.

If there is still a problem you should give us the rest of the code so we can know more about what is going on.

im pretty sure it is arrowX. I think i need to replace it with arrow.X

I have no idea if anyone will see this post, but i need yet another favor.
I want to put multiple items on this hit detection. Putting a comma on it dose not work. If anyone knows how to do this please send help my way!

I want both block1 and block2 to be added to the this.hits

if (this.hits(block1,block2))

Here’s how to do it:

if(this.hitTest(block1) && this.hitTest(block2) ){
// Put some code here
}

The “&&” is like an “and,” replacing it with “||” will make it an “or” statement.
Let me know if this is what you needed

it dosenot seem to be working… i dont know why.

This is my simple gravity script. it is kinda trash but it works and i came up with it in like 20 seconds so yeah.

basicaly the blocks are just rectangle clips named block1 and block2.
i want it so that when it collides it dose not go down. but when it is not touching them it falls down on the y axis.

here is what i wrote
if(this.hitTest(block1)) {
this.y = this.y;
} else {
this.y += 5;
}

hmmm… try this:

if(!this.hitTest(block1)&& !this.hitTest(block2)) {
this.y+= 5;
}

This checks if block one and two isn’t hit by the object, and if it returns true, the object falls down

1 Like

thank you. i never approached it like this. im still very new at javascript. there is not a lot of documentation on javascript for wick. if you look up anything it seems always to be with web development.

2 Likes

well that’s because javascript is the web development language

1 Like

I think this works…:

if (this.hits(block1) {
if (this.hits(block2) {
// Code
}
}

What it’s supposed to do it’s that if it hits block1, it checks if it’s also hitting block2, if it is, then it does something.

Edit: Also, if you want more than 2, you could make this:

if (this.hits(block1) {
if (this.hits(block2) {
if (this.hits(block3) {
if (this.hits(block4) {
// Code
}
}
}
}

do you know how to make it so that when i press w, it makes you go up 10 pixels up.
right now i cant do that. i wrote it so that it goes ahead and when you hold down w, it goes up 10 px. but you can infinity go up. how can i make it a sooth animation that only goes up a certain amount?

Nevermind.

yes. i dont know any other way to do it