Help With Walk Scripts

So im making a game but for now im testing my skills can someone tell me what i did wrong here tho or just tell me how to make a walking script

//Scripted Variable Section
var Walking = pc.createScript('walking');
var MoveRight = new pc.Vec3(5,0,0);
//Regular Variable Section
var ypos;
var xpos;
var zpos;
var speed = 10;
//Function Usage
updatepos();
gotopos();
//Function Making
function updatePos(){
      setTimeout(updatePos,100);
console.log("X:" + xpos + "Y:" + ypos + "Z:" + zpos + ";" + date + time);
time();
}
function keybindz(){
setTimeout(keybindz,1);
var onKeyDownE = function key1(e){
if(e.key === pc.KEY_LEFT){
xpos = xpos - speed;
}else{
if(e.key === pc.KEY_RIGHT){
xpos = xpos + speed;
}else{
if(e.key === pc.KEY_UP){
ypos = ypos + speed;
}else{
if(e.key === pc.KEY_DOWN){
ypos = ypos - speed;
}
}
}
}

e.event.preventDefault();
}
app.keyboard.on("keydown", onKeyDownE, this);
}
function gotopos(){
setTimeout(gotopos,40);
vec.x = xpos;
vec.y = ypos;
vec.z = zpos;
}
function time(){
//Todays Date
var dt = new Date();
var date = dt.toLocaleDateString();
//Live Time
var dt2 = new Date();
var time = dt2.toLocaleTimeString();
}
//Scripts
// initialize code called once per entity
Walking.prototype.initialize = function() { 
};
// update code called every frame (40 milisec)
Walking.prototype.update = function(dt) {
};

Hi @RagDev,

There is a number of things going wrong with your code:

  1. Your code lives outside any script method (e.g. initialize or update) meaning it will execute way before this entity (and the scene) are ready.

  2. You don’t really execute any transform method that will affect the entity’s position, so visually even if your code is corrected it won’t render any change.

Check this manual page to get started with how scripting works in PlayCanvas:
https://developer.playcanvas.com/en/user-manual/scripting/

And here is a first person movement tutorial: First Person Movement | Learn PlayCanvas