2
respostas

[Dúvida] image() was expecting Number for the second parameter, received an empty variable instead ???

//Car
let xCars = [900, 550, 200]
let yCars = [155, 405, 235]
let carsSpeed = [7,10,7]

function ShowCar(){
  image(carImage, xCars[0], yCars[0], 62, 40)
  image(carImage2, xCars[1], yCars[1], 62, 40)
  image(carImage3, xCars[2], yCars[2], 62, 40)
}

function MoveCar(){
  xCars -= carsSpeed[0]
  xCars -= carsSpeed[1]
  xCars -= carsSpeed[2]
  if(xCars[0] < -100)
    xCars[0] = 900
  if(xCars[1] < -100)
    xCars[1] = 900
  if(xCars[2] < -100)
    xCars[2] = 900

}

Quando executo, aparece a seguinte mensagem "p5.js says: [Car1.js, line 7] image() was expecting Number for the second parameter, received an empty variable instead. If not intentional, this is often a problem with scope."

Não sei onde está o erro. Se puderem me ajudar eu agradeço.

2 respostas

Amigo esse o codigo completo? por que eu não consigo ver nada de errado por enquanto

Esse é o código completo

sketch.js

function setup() {
  createCanvas(800, 600);
}

function draw() {
  background(roadImage)
  ShowCar()
  ShowActor()
  MoveCar()
  ActorMove() 
}

Images1.js

let roadImage
let actorImage
let carImage
let carImage2
let carImage3

function preload(){
  roadImage = loadImage("Images/road.png")
  actorImage = loadImage("Images/actor-1.png")
  carImage = loadImage("Images/car-1.png")
  carImage2 = loadImage("Images/car-2.png")
  carImage3 = loadImage("Images/car-3.png")
}

Car1.js

//Car
let xCars = [900, 550, 200]
let yCars = [155, 405, 235]
let carsSpeed = [7,10,7]

function ShowCar(){
  image(carImage, xCars[0], yCars[0], 62, 40)
  image(carImage2, xCars[1], yCars[1], 62, 40)
  image(carImage3, xCars[2], yCars[2], 62, 40)
}

function MoveCar(){
  xCars -= carsSpeed[0]
  xCars -= carsSpeed[1]
  xCars -= carsSpeed[2]
  if(xCars[0] < -100)
    xCars[0] = 900
  if(xCars[1] < -100)
    xCars[1] = 900
  if(xCars[2] < -100)
    xCars[2] = 900

}

Actor1.js

let xActor = 100
let yActor = 555
let iP;
function ShowActor(){
   image(actorImage, xActor, yActor, 35, 35)
}

function ActorMove(){
  if (keyIsDown(UP_ARROW))
    yActor -= 4
  if(keyIsDown(DOWN_ARROW))
    yActor += 4
  if(keyIsDown(RIGHT_ARROW))
    xActor += 4
  if(keyIsDown(LEFT_ARROW))
    xActor -= 4
}