Discord
Login
Community
DARK THEME

i have a gun script but it doesn't work

i made a gun script bur for some reason, it only draws my player and doesn't fire, sprite3 is the bullet and sprite is the player, i cannot see any errors in my script though.

this is my script:

init = function() Wsize = 35 Lsize = 35 dir = 0 firing = 0 end

update = function() walk() screen.fillRect(0,0,700,700,"rgb(0,255,255)") screen.drawSprite("sprite4"0,0,200,200) if not move.x == goal.x or move.y == goal.y then screen.drawSprite("sprite3",move.x,move.y,10,10) end screen.drawSprite("sprite",player.x,player.y,Wsize,Lsize) end

draw = function() end

walk = function() if keyboard.A then player.x -= 1 end if keyboard.D then player.x += 1 end if keyboard.S then player.y -= 1 end if keyboard.W then player.y += 1 end end pew = function() if mouse.Release then if firing == 0 then firing = 1 goal.x = mouse.x goal.y = mouse.y if not move.x == goal.x or move.y == goal.y then

    if goal.x >= 0 then
      move.x += 1
    elsif goal.x < 0 then
      move.x -= 1
    end
    
    if goal.y >= 0 then
      move.y += 1
    elsif goal.y < 0 then
      move.y -= 1
    end
  
  end
  
  if check == 0 then
    check = 1
    pos.x = player.x
    pos.y = player.y
    screen.drawSprite("sprite3",pos.x,pos.y,10,10)
  end
  

end end end

Call the firing code ( pew() )

init = function()
  check = 0
  Wsize = 35 
  Lsize = 35 
  dir = 0 
  firing = 0 
  move = object x = 0 y = 0 end
  goal = object x = 0 y = 0 end
  player = object x = 50 y =50 end
  pos = object x = 0 y = 0 end
end

update = function()
  walk() 
  pew()
end

draw = function() 
  screen.fillRect(0,0,700,700,"rgb(0,255,255)") 
  screen.drawSprite("sprite4"0,0,200,200) 
  if not move.x == goal.x or move.y == goal.y then
    screen.drawSprite("sprite3",move.x,move.y,10,10) 
  end 
  screen.drawSprite("sprite",player.x,player.y,Wsize,Lsize)
end

walk = function() 
  if keyboard.A then player.x -= 1 end 
  if keyboard.D then player.x += 1 end 
  if keyboard.S then player.y -= 1 end 
  if keyboard.W then player.y += 1 end 
end 


pew = function() 
  if mouse.release then 
    if firing == 0 then 
      firing = 1 
      goal.x = mouse.x 
      goal.y = mouse.y 
      if not move.x == goal.x or move.y == goal.y then
        if goal.x >= 0 then
          move.x += 1
        elsif goal.x < 0 then
          move.x -= 1
        end
        if goal.y >= 0 then
          move.y += 1
        elsif goal.y < 0 then
          move.y -= 1
        end
      end
      if check == 0 then
        check = 1
        pos.x = player.x
        pos.y = player.y
        screen.drawSprite("sprite3",pos.x,pos.y,10,10)
      end
    end
  end
end

That didn’t work, but thx

I don’t know how to revert it to my old script

Restoring the script to its original form can be done in two ways.

  • Recreate the thinking process you went through when creating the code for the first time, but remember that the code must contain errors that you cannot understand.
  • Second method - copy the code from the first post in this thread.

Ok, but I still have problems with my gun script! I don’t know what do to

Make the project public and provide a link to the project.

It didn’t work :c

Post a reply

Progress

Status

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