Discord
Login
Community
DARK THEME

Player no move

I have been experiencing an annoying problem. Whenever I call player.x or anything related to the player in global, it stops moving. Example:

//script1
player = object
x=0
y=0
end
if keyboard.LEFT 
then
player.x -= 1 
end

//script2
print(player.x)

It stops moving, but ONLY because I called him in another script

Is the player movement code in the update() function?

Yes, update. But when i call he in other script, he stop work

You can :

  1. or write keyboard condition inside draw() or update() function in main script
  2. or write function with input condition in player script and call that function in update() in main script

you can also use keyboard.press function

No bro, that's a example, not a code. This happens with quick Engine too, the screen stay black or player dont move

The error started when I tried use DX and DY, but this happens in my various games, but in ALL when i call a global var or a function

But all code I see, every call a global var from player, but dont have bug

but when I delete 1 character and put him back, the screen stay normal, but not move

Without full code it's hard to understand. Check your objects. Maybe you trying to move object that don't exist. You can try to use print function with objects for seek a problem.

main:

init = function()
initCamera()
initPlayer()
end

update = function()
  updateCamera()
updatePlayer()
end

draw = function()
  
drawPlayer()
end

player:

initPlayer = function() 
  player = object end 
  player.x = 0
  player.vx=0
  player.vy=0
  player.y=0 
  player.dirY=-1
  player.name="player/front_idle"

end
/*
unutil
    init = function()
      cam = new Camera(player_x, player_y)
      cam.smoothing = Camera.smoother.smooth(2.5)
    end
    
    update = function()
      Camera.update()
      
      cam.moveTo(player_x, player_y)
    end
    
    draw = function()
      screen.clear()
      
      cam.withDraw(function() 
        cam.drawMap(my_map, 0, 0, 600, 600)
        cam.drawSprite("player", player_x, player_y)
      end)
    end
*/
updatePlayer =function()
  movePlayer()
end

movePlayer = function()
  if keyboard.LEFT then
    if player.dirY == -1 then
    player.name="player/front_run"  
    else
    player.name="player/back_run"
    end
  player.vx = -1
  elsif keyboard.RIGHT then
    if player.dirY == -1 then
    player.name="player/front_run"  
    else
    player.name="player/back_run"
    end
  player.vx=1
  else
    if player.dirY == -1 then
    player.name="player/front_idle"
    else
      player.name="player/back_idle"
      end
  player.vx=0
  end
  
  if keyboard.UP then
  player.vy = 1
  player.dirY = 1
  player.name="player/back_run"
  elsif keyboard.DOWN then
  player.vy = -1
  player.dirY = -1
  player.name="player/front_run"
  else
  player.vy=0
  end
  
  player.y +=player.vy
  player.x +=player.vx
  clamp(player.x, -100, 100)
  end



drawPlayer = function()
  screen.clear("rgb(32, 32, 32)")
  screen.drawMap("map",-camera.x ,-camera.y, 1100,1000)
  screen.drawSprite(player.name, player.x - camera.x, player.y - camera.y, 30, 30)
  
  end
  
  

camera:

camera=object end
initCamera=function()
  camera.x=0
  camera.y=0
end
updateCamera=function()
  camera.x = player.x
  camera.y = player.y
  
  camera.x = clamp(camera.x, -334, 334)
camera.y = clamp(camera.y, -200, 200)
end

all code

But he works when I take out and put in a character specifily in parantheses in updatePlayer() or updateCamera()

probably is a microstudio bug

When I have this problem, I usually switch from keyboard.RIGHT to keyboard.RIGHT == 1 IDK, it always worked for me.

Post a reply

Progress

Status

Preview
Cancel
Post
Validate your e-mail address to participate in the community