View Single Post
  #3  
Old 08-08-2011, 09:16 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Quote:
Originally Posted by Emera View Post
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;
  }
} 
__________________
Quote:
Reply With Quote