I’m making a generator for rooms, and it takes in 3 arguments - number of rooms, min size, and max size of the rooms generated. The code works fine when I try to hard code it:
function setup() {
createCanvas(1280, 512);
//randomly creates x rooms of different sizes
generator = new Room_map(5, 10, 15);
//draw these rooms
generator.draw();
}
But when I try to take in user input using this example here examples | p5.js, the above error shows up in the console.
Any help is apprieciated. Thanks in advance!
Here is my code for taking in user input:
function setup() {
createCanvas(1024, 512);
input_no_of_rooms = createInput(); //no of rooms
input_no_of_rooms.position(1100, 50);
input_min_size = createInput(); //min size
input_min_size.position(1100, 90);
input_max_size = createInput(); //max size
input_max_size.position(1100, 130);
button = createButton('Generate');
button.position(1100, 155);
//when button is pressed, call gen function with the above inputs
button.mousePressed(gen(input_no_of_rooms.value(),
input_min_size.value(),
input_max_size.value()));
}
function gen(no, min, max)
{
if (no > 0 && min > 0 && max > 0)
{
console.log("generating"); //does not show up in log after pressing button
//randomly creates x rooms of different sizes
var generation = new Room_map(no, min, max);
//draw these rooms
generation.draw();
}
}