unexpected token: void error relating to global variable or setup or agent

edited February 2014 in Questions about Code

I have an "unexpected token: void" error relating to

void controlUI() {
 controlP5 = new ControlP5(this);
  // Group menu items
  ControlGroup ui = controlP5.addGroup("Settings", 785, 10, 215);

...etc.

also highlights

class Agent {
...
**}**

and

**World world;**

I'm modifying Gum's http://www.openprocessing.org/sketch/11045

I think the error came up after commenting out

//  float dist2(PVector v1, PVector v2) {
//    return ((v1.x - v2.x)*(v1.x - v2.x) + (v1.y - v2.y)*(v1.y - v2.y) + (v1.z - v2.z)*(v1.z - v2.z));
//  }
//  
//  float mag2(PVector v) {
//    return (v.x*v.x + v.y*v.y + v.z*v.z);
//  }

Which I tried because dist2 and mag2 refer to avoiding objects which I've removed and evading predators which I've changed.

I'm guessing the question's not clear enough, sorry!

Answers

  • Answer ✓

    We cannot help you unless you give the full code... In general, you get this error when you accidentally delete a closing brace, for example. Perhaps your void controlUI() declaration ends in a function definition, which is illegal.

    Reformat your code (using Ctrl+T), it might help in finding the error.

  • Hi Phil

    the reason I didn't copy-paste the full code is that it's huge.

    I've uploaded the folder of files to google drive now - https://drive.google.com/folderview?id=0B7bVmmZ44sQ6SGZCck1yMmh6MVE&usp=sharing I think the sharing settings will be ok.

    I'm going to try backtracking to a version that worked and then replace the changes one by one til I identify the problem. I don't really know Java syntax and I don't have time to learn methodically at this stage, so it's trial n error and cumulative saving different versions.

    I have reformatted a few times.

    Thanks!

    Kester

  • Even a missing semi-colon can make Java compiler to shout unrelated errors far below where the actual error is! [..]

  • Yep, I searched the forums before asking and have checked over and over for a missing semi-colon, so I don't think it's just that.

    I think the last thing I did before it threw a hissy-fit was comment-out some code at the end of the file:

    // float dist2(PVector v1, PVector v2) { // return ((v1.x - v2.x)(v1.x - v2.x) + (v1.y - v2.y)(v1.y - v2.y) + (v1.z - v2.z)(v1.z - v2.z)); // } //
    // float mag2(PVector v) { // return (v.x
    v.x + v.yv.y + v.zv.z); // } //}

    But I thought from the complete brackets that this bit was stand-alone and wouldn't screw up the code above. Also I'm not really clear what this section is doing - I think it's something to do with evade and avoid functions which I've commented-out because I don't need them at this stage.

  • I've sort of fixed it for now by backtracking and commenting out the Info render code. I don't know why Info render gives me errors, but it's not my priority right now.

    Experimental manipulations (supposed to be finished today, lolz!) then data capture methods (supposed to be finished and written up by end of March, owch!) then graphics (don't really need finishing til my final presentation).

Sign In or Register to comment.