Skip to content

[p5.js 2.0+ Bug Report]: p5.Vector.x set doesn't work on 1D vector #8924

@sidwellr

Description

@sidwellr

Most appropriate sub-area of p5.js?

  • Accessibility
  • Color
  • Core/Environment/Rendering
  • Data
  • DOM
  • Events
  • Image
  • IO
  • Math
  • Typography
  • Utilities
  • WebGL
  • WebGPU
  • p5.strands
  • Build process
  • Unit testing
  • Internationalization
  • Friendly errors
  • Other (specify if possible)

p5.js version

2.3.0

Web browser and version

Brave 1.90.122

Operating system

Linux Mint 22.1

Steps to reproduce this

Steps:

  1. Create a 1D vector
  2. Set v.x to change the "x" value
  3. Show that setting v.x didn't work

Snippet:

function setup() {
  let v = createVector(1);
  v.x = 2;
  
  // This should print "vector[2]", but prints "vector[1]"
  print(v.toString());
}

Problem

The code contains a comparison if (this.values.length > 1); it doesn't work because the length is 1. The comparison should be if (this.values.length > 0).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions