Processing - "unexpected token: void" [closed] - processing

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I am using the below code to simulate "Purple Rain" (from The Coding Train on
YouTube).
Class Drop(){
float x = width/2;
float y = 0;
float yspeed = 1;
void fall(){
y = y + yspeed;
}
void show(){
stroke(138, 43, 226); //purple rain
line(x, y, x, y+10);
}
}
However, I am getting the error unexpected token: void on line 6:
void fall(){
I can't see any syntax errors - could someone suggest why I am getting this error?

You do have a syntax error. The Class keyword should be class with a lower-case c. You should also not have parenthesis after the class name.
Also, see my answer here. The Processing editor doesn't like when you only have a class definition without Processing functions like setup() and draw().
Side note: you might want to try approaching problems like this with a "what syntax error am I not seeing?" mentality instead of saying "I have no syntax errors" - the compiler doesn't lie, so saying you have no syntax mistakes comes off as a little bit presumptuous.

Related

Why I am getting SIGBART error in this code of diagonal traversal of Binary tree? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
I am getting SIGBART error in this code. I am trying to print diagonal traversal of a binary tree.
void digonalUtil(Node* root,int dVal,map<int,vector<int> > &mp){
if(root==NULL) return;
mp[dVal].push_back(root->data);
digonalUtil(root->left,dVal+1,mp);
digonalUtil(root->right,dVal,mp);
}
vector<int> diagonal(Node *root)
{
// your code here
vector<int> ans;
if(root==NULL) return ans;
map<int,vector<int> > mp;
digonalUtil(root,0,mp);
for(auto itr=mp.begin();itr!=mp.end();itr++){
for(auto ptr=itr->second.begin();ptr!=itr->second.end();itr++){
ans.push_back(*ptr);
}
}
return ans;
}
While a bit commenting out statements, I find that the error is in the line
mp[dVal].push_back(root->data);
But I am not getting why is this happening. I had earlier done same operation on map in other questions, there it worked fine.
Please help.
I got the answer, in the second for loop I was incrementing itr rather than ptr that was causing the error, it was just a silly mistake I can say.

How Do I Assign Values of 2 or more Fields in VBScript [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
Hi sorry for a basic question on VBScript but after scouring the internet. In a If statement I am trying to assign values to 2 fields but when I run this code which is part of an application it does not error neither does it work so I suspect I am doing wrong. Can anyone point me in the right direction as I am trying to assign values to CustomerInformation.CodeObject.Customer and. CustomerInformation.CodeObject.Carrier
Function CustomerInformation_OnLoad()
if (SystemVariables.CodeObject.Company = "D" or SystemVariables.CodeObject.Company = "T") and DispatchNoteDetails.CodeObject.Area = "UK" then
if CustomerInformation.CodeObject.Customer = "AAE02" then
CustomerInformation.CodeObject.Carrier = "Customer collects" and CustomerInformation.CodeObject.CarrierURN = "AA Driver"
end if
end if
End Function
Hi thanks all for the tips.
The code worked when changing to the following:
Function CustomerInformation_OnLoad()
if (SystemVariables.CodeObject.Company = "D" or SystemVariables.CodeObject.Company = "T")then
if CustomerInformation.CodeObject.Customer = "AAE02" then
CustomerInformation.CodeObject.Carrier = "Customer collects"
CustomerInformation.CodeObject.CarrierURN = "AA Driver"
end if
end if
End Function
Thanks again for the tips.

For loop inside if/else inside while. Proper syntax [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
Why doesn't this work? I'm getting unexpected keyword_end.
while(!k && DATA[q])
if DATA[q] == 'aa' && DATA[p] == 'aa'
pl = DATA[r]
for i in 0..pl
PACK[i] = DATA[i+4]
end
k+=1 #end while
else
q++
p++
r++
end
end
You are getting error because ++ does not work in Ruby.
Ruby has no pre/post increment/decrement operator. For instance, x++
or x-- will fail to parse. More importantly, ++x or --x will do
nothing! In fact, they behave as multiple unary prefix operators: -x
== ---x == -----x == ...... To increment a number, simply write x += 1.
source (which indeed are the words of Ruby's author himself.)
You should replace them as follows:
q+=1
p+=1
r+=1

Is it humanly possible to fix indent size issues w/o access to a syntax tree? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
Asked another way, if I showed you this masked code file, using only your human brain, is it possible to fix the indentation issues, even if you know it should be 2-space indentation?
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
x
x
xxxxxxxxxxxxxxxxxxxxxxxxxxx
I have my own ideas, but I don't want to bias the answer. The actual source code and language will be revealed after I get a good batch of answers. Feel free to post your fix as a code block below.
This test assumes the following:
You have no idea the language in which this code is written.
All you know is how many spaces or tabs lead up to the first character of each line. In this case, there are no tabs (just spaces).
You know what the indent size should be. In this case, 2 spaces.
Note: If it's possible with your human brain, it should also be possible with code, right?
Bonus Points (optional): How would you break-down the logic to tackle this problem?
EDIT: Here's the source code, from which these exes were created:
function greet(firstName, lastName) {
var firstName = prompt('What is your first name?');
var lastName = prompt('Last name?');
var fullName = firstName + ' ' + lastName;
for (var i = 0; i < 10; i++) {
console.log('Hello,', fullName + '!');
}
}
greet(firstName, lastName);
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
x
x
xxxxxxxxxxxxxxxxxxxxxxxxxxx

How do YOU handle bad parameters in functions? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
Let's say you have some function that has one int parameter that can be good or bad. Let's say that it's bad when it's less than 5. And if it's bad you should get out of function. I think you already made up that function in your mind. Now tell me which of these functions is what you would've written.
1.
void abc(int a)
{
if (a < 5) return;
//...
}
2.
void abc(int a)
{
if (a >= 5)
{
//...
}
}
This may sound like a really stupid question. But I often have hard time deciding between these two lol.
I prefer the first way:
if a < 5
// return error or throw exception
To me it looks like some kind of "guard". Also you should handle this "bad" variable somehow (return error, throw exception) and it will be harder to follow if this is in some else block somewhere in the function.

Resources