Discord
Login
Community
DARK THEME

code not working???

I'm new to micro script so i tried to write some code.

I cant tell why this isn't working

    init = function()
            y = 25
            flyY = 40
            flyX = 40
            fly_ai()
    end

    update = function()
            if keyboard.LEFT then 
                    x = x - 2 
            end
            if keyboard.RIGHT then 
                    x = x + 2 
            end
            if keyboard.UP then 
                    y = y + 1 
            end
            print(y)
    end

    if flyX > x then
            while flyX ~= x do
                    flyX = flyX - 10
            end
    end

    if flyX < x then
            while flyX ~= x do
                    flyX = flyX + 10
            end
    end

    draw = function()
            screen.fillRect(0, 0, 400, 400, "rgb(140,198,440)")
            screen.drawSprite("guy", x, y, 30)
            screen.drawMap("map2", 0, 0, 300, 200)
            screen.drawSprite("fly_guy", flyY, flyX, 20)
    end

also is there a way to detect collision between the ground and a sprite or a sprite and a sprite. How do I make the player a object and do I neet to?

init = function() 
  x = 0
  y = 25 
  flyY = 40 
  flyX = 40 
//  fly_ai() 
end

update = function() 
  if keyboard.LEFT then 
    x = x-2 
  end 
  if keyboard.RIGHT then 
    x = x+2 
  end 
  if keyboard.UP then 
    y = y+1 
  end 
  print(y) 

  if flyX > x then 
    while flyX >= x 
      flyX -= 10 
    end 
  end 
  if flyX < x then 
    while flyX <= x 
      flyX += 10 
    end 
  end
end

draw = function() 
  screen.fillRect(0,0,400,400,"rgb(140,198,440)") 
  screen.drawSprite("guy",x,y,30) 
  screen.drawMap("map2", 0, 0, 300, 200 ) 
  screen.drawSprite("fly_guy",flyX,flyy,20) 
end

you will execute this code forever!!! if the flvX value is different from a multiple of an integer * 10

    while flyX != x 
      flyX += 10 
    end 

search in the Explore section under the tag AABB collision.

https://microstudio.dev/i/HomineLudens/aabb/

https://microstudio.dev/i/microstudio/collisions/

it is supposed to move the Fly toward the player

I was trying to make a simple enemy ai. It would be better if it was in a function. I'm also still confused on the collision

this is the link for the Game. https://microstudio.io/TedCodes/funyes/DP96HFF3/

update = function() 
  if keyboard.LEFT then 
    x = x-2 
  end 
  if keyboard.RIGHT then 
    x = x+2 
  end 
  if keyboard.UP then 
    y = y+1 
  end 
  print(y) 
  fly_ai()
end

fly_ai = function()
  if flyX > x then 
    while flyX >= x 
      flyX -= 10 
    end 
  end 
  if flyX < x then 
    while flyX <= x 
      flyX += 10 
    end 
  end
end

It works but how could i add delay?

here is the link, https://microstudio.dev/i/TedCodes/funyes/

could i use this for collision? https://microstudio.dev/documentation/98895/ do i need to import it? the code for the game doesn't work anymore. idk why though

Post a reply

Progress

Status

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