Quote:
Originally Posted by Emera
I am no expert, but I am almost completely sure you need a timer set there.
|
Only if you need the loop to continue. If you don't understand what it does, you probably shouldn't give advice on it.
I've restyled your code to the same standard nearly everyone else follows on these forums and placed comments above the lines that may have been causing problems.
PHP Code:
//#CLIENTSIDE
function onCreated() {
// You need to use 'this.' otherwise the variable is global
// and may conflict with future scripts.
this.canmove = 1;
// GS2-Equivalent of disabledefmovement;
// Mixing GS2 and GS1 is bad.
disabledefmovement();
}
function onKeyPressed(temp.code, temp.key, temp.scan) {
// You need to use two ='s to do a comparison
// When you use one = it is an assignment. I.e: Assigning 1 to canmove
// The comparison checks if this.canmove equals 1.
if (this.canmove == 1) {
// The code below is fine
if (keydown(3)) {
player.x +=0.3;
player.dir = 3;
setani("walk", NULL);
setTimer(0.3);
} else if (keydown(1)) {
player.x -=0.3;
player.dir = 1;
setani("walk", NULL);
setTimer(0.3);
}
}
}
function onTimeout() {
setani("idle", NULL);
}
You can use onwall(x,y) and onwall2(x,y,width,height) to check for walls. I.e:
PHP Code:
//#CLIENTSIDE
function onCreated() {
movePlayer();
}
function movePlayer() {
temp.new_x = player.x + 0.3;
temp.new_y = player.y;
if (!onwall(temp.new_x, temp.new_y)) {
player.x = temp.new_x;
player.y = temp.new_y;
}
}