Guidelines—Asking Questions

Summary (TL;DR)

Ask complete questions to get better answers!

  • Be specific. For example: I want to load an image. I tried using createImg() , and I expected the image to be on canvas, but what happened instead was the image showing up below the canvas.
  • Isolate your problem and work in small steps. Share only the code directly related to your problem if it is part of a bigger project, and if something isn’t working, try the smallest code that could do the thing you want.
  • Can we run your code to see the same thing as you?
  • Share what you tried. When you researched your problem, what did you find? What happened when you debugged your code?

This guide is meant to offer suggestions that will help you ask questions. Keep in mind that the developers of Processing, and the people answering questions here, are all doing this for free in their spare time. The best way to get better help: make it easier to answer your question!

Here are some tips to help make your question easier to answer:

Is your question specific?

It’s very hard to answer general “how do I do this” type questions. It’s much easier to answer specific “I tried X, expected Y, but got Z instead” type questions.

For example, a question like “How do I draw a garden?” is a pretty broad question. There are a bunch of different ways to approach it, and how you approach it depends on a lot of things that haven’t been decided yet: what do you want the garden to look like? What code have you written so far? What exactly are you confused about?

Compare that to a question like “I’m trying to draw a flower out of circles using the ellipse() function. I thought this code would draw 4 red circles with an orange circle on top of them, but the circles are being drawn on top of each other in the wrong order. Here’s the code I’m using so far…” This question is much easier to help with, because it’s a specific question about a specific piece of code.

Does your title give a good summary of your problem?

The title of your post should give a good summary of your problem or question. A good title will make it easier for other members of the community to understand your question and you will get more helpful answers as a result.

Make sure your title is easy to understand and related to the topic of your question. If you are not sure what your issue is, that’s ok. Take your best guess. Notice how “Problem with transparent background color” contains a lot more information than “What’s going on with my sketch? Please help.”

This also makes the forum better for everyone, since someone with the same problem as you will have an easier time finding an answer in the future using the search function.

Is your problem isolated?

It’s good to include code in your question, but you should only include the code that’s directly related to your problem. It can be very helpful to create a new blank sketch and only add as much code as is required to show the problem.

In our example of somebody asking about the flower in their garden scene, consider this code:

import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;
import ddf.minim.signals.*;
import ddf.minim.spi.*;
import ddf.minim.ugens.*;

PImage background;

Minim minim;
AudioPlayer song;

void setup() {
  background = loadImage("background.png");
  minim = new Minim(this);
  song = minim.loadFile("song.mp3");;

void mousePressed() {
  // 100 lines of code for adding a butterfly

void draw() {

  // 100 lines of code for drawing grass

  fill(255, 128, 0);
  ellipse(100, 100, 100, 100);

  fill(255, 0, 0);
  ellipse(50, 50, 100, 100);
  ellipse(150, 50, 100, 100);
  ellipse(50, 150, 100, 100);
  ellipse(150, 150, 100, 100);

  // 100 lines of code for drawing clouds

This code has a few problems.

  • It loads the Minim library, which is not related to the problem.
  • This code will not run for anybody else, because they don’t have the song.mp3 file.
  • It uses a background image that’s not related to the problem.
  • This code will not run for anybody else, because they don’t have the background.png file.
  • It contains a mousePressed() function that’s not related to the problem.
  • It contains hundreds of lines of code for drawing grass and clouds.

All of these make it harder to understand the actual problem. Compare that code to this code:

size(200, 200);

fill(255, 128, 0);
ellipse(100, 100, 100, 100);

fill(255, 0, 0);
ellipse(50, 50, 100, 100);
ellipse(150, 50, 100, 100);
ellipse(50, 150, 100, 100);
ellipse(150, 150, 100, 100);

This is a full Processing sketch that contains only the code that’s directly related to the problem. This is much easier to debug and talk about.

Note that if you post extra code, you might be asked to narrow your problem down to a Minimum, Complete, Verifiable Example. This just means that you should try to isolate your code into a smaller example. Eliminate dependencies on libraries and external files, and get rid of any code that isn’t part of what you’re asking about.

You’ll often solve your own problem in the process of coming up with a simpler example that demonstrates the same behavior!

Are you working in small steps?

It’s always better to write code a few lines at a time and to test those lines as you go. Don’t try to write everything all at once, and don’t wait until you think you’re done to test your code out!

Break your problem down into smaller steps and take those steps on one at a time.

This will help you isolate your problem—if you’re working in small steps, you should know exactly which step you’re asking about. Then you can create a simple example program that just shows that one step.

Think about somebody who wrote a sketch that draws a whole garden scene. They’ve written hundreds of lines of code, but haven’t tried running it at all. When they finally do run it, nothing looks right and they get a NullPointerException in their code. It’s going to be very hard to help with this, because they don’t have just one problem.

Compare that to somebody who has been working in small steps. They’ve isolated their flower-drawing code into a single function that runs without needing any other functions. They’ve been testing as they’ve written the code, so they know the problem is in the drawFlower() function. This problem is much easier to solve.

Can we run your code to see the same thing as you?

When you’re putting together your example, double-check that other people can copy and paste your code to see the exact same thing as you. This means eliminating dependencies on external files and libraries.

Consider creating an example using CodePen or the P5.js editor so people can visit a URL to run your code.

You can use these CodePen templates:

Remember: the easier you make it for people to help you, the more help you’ll get!

What happened when you debugged your code?

Debugging is a huge part of programming. As you write code, you should constantly be reading though it line by line and testing that it’s working how you expected. Test your code as often as possible- try running your program every time you write a line of code and double-checking that the line of code is doing what you thought it would.

If your code is behaving differently from what you expected, the first thing you should do is read through your code line by line. Use a piece of paper to record the values of variables and to trace through the code. Then compare that to what actually happens- use println() or console.log() statements to figure out exactly what the code is doing. Try to pinpoint exactly where the execution of the code differed from what you expected it to do.

If you aren’t sure how to debug your code, here is a more general guide on debugging. If you’re running in a browser, make sure you check the JavaScript console for errors. If you’re getting an error message, try googling the error message. Chances are other people have had the same problem before!

What has your research told you?

A lot of programming is not actually typing code: it’s reading documentation, trying out examples, looking through references, googling, and consulting sites like Stack Overflow.

Make sure to include the research you’ve done.

For example, consider this post:

This code doesn’t work, and I don’t know why.

Compare that to this post:

This code draws the red petals over top of the orange center. I’ve tried googling “Processing draw order of shapes” and found this which talks about the PShape class, but I just want to draw basic circles. How do I draw the red petals underneath the orange center?

This question shows a lot more research and asks more specific questions that other people can help with.

Is your post formatted?

Proper formatting can make your post easier to read, which makes it easier for us to help you. Here are a few things to keep in mind:

  • Use punctuation.
  • Use multiple paragraphs. A wall of text is hard to read, so break it up with newlines.
  • Avoid using abbreviations like “u” instead of “you”.

Don’t forget to format your code! To format your code, highlight it and press the code button (it looks like </>) in the editor. (1)

Note: In some cases the </> button may not appear immediately. In this case you will find the option under the gear icon (the last button to the right on the editor’s header bar).

This will surround your code with three tickmarks:

// code goes here

These three tick marks will preserve your code’s indentation and add syntax highlighting, which makes your code much easier to read.

Are you posting anywhere else?

If you’re posting to multiple sites, please link between the crossposts so we can see what help you’ve already received. A simple message like “By the way, I’m also posting this on Stack Overflow. Here is a link to that post…” is enough.

Share your solution!

If you find the solution yourself, please take the time to reply to your own message and share the steps you used to solve the problem. This could help someone else in the future with the same issue. There is nothing worse than finding a thread that addresses your exact question only to realize that the original poster replied with “nevermind I found the solution” and nothing else.


2 posts were split to a new topic: Text covered by an image