Rpg

im creating an rpg game and im making it so if you hit the water or the house or anything else it will stop you but im having real difficulty and it is probobaly not that hard so do you think you could help me with this…

the script is

onClipEvent (load) {
speed = 5;
speed2 = 5
speed3 = 5;
speed4 = 5;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)) {
_root.level1._x -= speed2;
}
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.DOWN)) {
_root.level1._y -= speed3;
}
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT)) {
_root.level1._x += speed4;
}
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.UP)) {
_root.level1._y += speed;
}
}
onClipEvent (enterFrame) {
if (this, hitTest(_level0.level1.sign)or(_level0.level1.water)) {
speed = 0;
} else {
speed = 5;
}

}

and there is an attachment if you can download it

:slight_smile:

Don’t have Flash MX 2004 but i can see two things that your doing wrong and one style misstake :slight_smile:
ok the syntax of hittest is wrong you had a , in stand of a . and you have to call the hittest function for every object you have to test. so this dosn’t work

this.hitTest(_root.level1.sign) or (_root.level1.water)) 
//but this will
this.hitTest(_root.level1.sign) or this.hitTest(_root.level1.water)

the style misstake will not make the AS crash but it does make it a mess…you have like 5 onClipEvent (enterFrame) ! while one is more then enough. :slight_smile:


onClipEvent (load) {
	speed = 5;
	speed2 = 5;
	speed3 = 5;
	speed4 = 5;
}
onClipEvent (enterFrame) {
	if (Key.isDown(Key.RIGHT)) {
		_root.level1._x -= speed2;
	}
	if (Key.isDown(Key.DOWN)) {
		_root.level1._y -= speed3;
	}
	if (Key.isDown(Key.LEFT)) {
		_root.level1._x += speed4;
	}
	if (Key.isDown(Key.UP)) {
		_root.level1._y += speed;
	}
	if (this.hitTest(_root.level1.sign) or this.hitTest(_root.level1.water)) {
		speed = 0;
	} else {
		speed = 5;
	}
}

And don’t forget that the ActionScript Dictionary is you friend so use it :wink: