if && statement help needed Newbie - arduino

I am trying to do this but can't seem to get it to work. Can someone please help
if (tft.fillScreen == (BLACK) &&((p.x > 163 && p.x < 200)&& (p.y > 295 && p.y < 314)))
{
tft.print("bingo")
}
I'm getting
invalid use of member function (did you forget the '()' ?)
I keep changing them around but i cant seem to get it right
Just to add, black is defined at the top of the code
#define BLACK 0x0000

Each statement that you are evaluating should be set apart with parenthesis. It helps make your code more readable and easier to understand.
I.E.
if ((tft.fillScreen == (BLACK)) && ((p.x > 163) && (p.x < 200))&& ((p.y > 295) && (p.y < 314)))
This will check that "tft.fillScreen == (BLACK)" is true, that p.x is between 163 and 200 and that p.y is between 295 and 314. If any one of these three conditions is not true than the entire statement evaluates to false.

Sorry but...
What is tft? Is it coming from a library? Which one?
What is fillScreen? I think that it is a function to fill the screen, not a variable saying what is the background color
You missed the ; at the end of tft.print("bingo")
Now, if point 2 is right (so fillScreen is a function):
This explains the error, since you are calling a function as if it was a variable. What are you trying to get? The last color you set as background? If so, probably you will need to save it in a variable.
If point 2 is wrong, then tell us what tft is..

Related

Finding peaks and valleys in each column, I'm not understanding this problem

So, to be clear, I don't need help solving this problem, as I know I have the knowledge to do it. The problem is, my English is not good enough to understand technical language, so I don't know exactly what I'm supposed to do.
I've the following excel file:
And I need to find the ''peaks and valleys'' of each column, and graph them.
I know how to use Matplotlib to graph, what I don't understand is what the problem reffers to with ''peaks and valleys''.
The result should be looking something like this:
So I'm guessing what ''peaks and valleys'' mean is the lowest and highest value of each column? If this is the case, the high value in Open column would be 24.6875, and the low would be 20.375?
By peaks and valleys it means maxima and minima so find either where the derivative of your function is equal to zero (and curvature != 0) or else where the data reaches a high (low) point then goes down (up) again
Function to count Valleys in Javascript
function countingValleys(n, s) {
let valleyCounter = 0;
let cLevel = 0;
let prevLevel =0;
for (let i =0; i<s.length; i++){
prevLevel = cLevel;
if(s[i] === "U"){
cLevel++;
}else{
cLevel--;
}
if(prevLevel === 0 && cLevel <0){
valleyCounter++;
}
}
return valleyCounter;
}

query where at least one of two fields falls into date range (

I've got a query that runs on a view that contains two modifiedBy dates. I need to return all records where either of these dates falls into a specified range.
From everything I've researched it seems I need something like this:
qbdsCustTableAddressView
.addRange(fieldNum(TCMCustTableAddressView, CustTableModified))
.value(
strFmt("(%1>='%2' AND %1<='%3') || (%4>='%2' AND %4<='%3')",
fieldstr(TCMCustTableAddressView, CustTableModified),
DateTimeUtil::toStr(contract.parmFromDateTime()),
DateTimeUtil::toStr(contract.parmToDateTime()),
fieldstr(TCMCustTableAddressView, EBillModified),
0
)
);
when I compare the resulting query to what is produced by:
qbdsCustTableAddressView
.addRange(fieldNum(TCMCustTableAddressView, CustTableModified))
.value(strFmt("%1..%2", contract.parmFromDateTime(), contract.parmtoDateTime()));
Then the above looks correct by I'm getting a non-specific "Syntax error near 22"
You have a few issues with the parenthesis, single quotation marks and using AND instead of &&.
This should work:
qbdsCustTableAddressView
.addRange(fieldNum(TCMCustTableAddressView, CustTableModified))
.value(
strFmt("(((%1 >= %2) && (%1 <= %3)) || ((%4 >= %2) && (%4 <= %3)))",
fieldstr(TCMCustTableAddressView, CustTableModified),
DateTimeUtil::toStr(contract.parmFromDateTime()),
DateTimeUtil::toStr(contract.parmToDateTime()),
fieldstr(TCMCustTableAddressView, EBillModified),
0
)
);
Try this:
qbdsCustTableAddressView
.addRange(fieldNum(TCMCustTableAddressView, CustTableModified))
.value(SysQuery::range(contract.parmFromDateTime(), contract.parmtoDateTime()));
The difference being SysQuery::range(<from>, <to>)
I don't see an obvious problem, but perhaps that might flush it out for you.

Using audio_play_sound() in a if statement GameMaker

I am trying to use the command:
audio_play_sound()
I am trying to insert it into this piece of code, so that when the player jumps, a sound plays.
if (key_jump) && (jumps > 0)
{
jumps -=1;
vsp = -jumpspeed;
}
Code that causes problem:
if (key_jump) && (jumps > 0)
{
jumps -=1;
vsp = -jumpspeed;
audio_play_sound(snd_jump)
}
Simply inserting the line into the if statement does not work, and gives the error WRONG NUMBER OF ARGUMENTS IN FUNCTION. This is rather confusing, perhaps I am using the wrong command? Thanks in advance
The problem is stated in the error, you're providing the wrong number of arguments to the audo_play_sound function.
from the docs
audio_play_sound(index, priority, loop);
As the person above states your answer is audio_play_sound(snd_jump, 1, false).

Compare each member of a vector with its number

The problem might be simple, but I cant solve it:
I got numeric vector, i need to compare its maximum/2 with each member except its maximum and if all these comparisons are FALSE , a=a+1.
I got these:
comp=c(6.674971, 11.208241, 18.296459, 5.165752, 123.000000)
a=0
if (max(comp)/2<comp[comp < max(comp)]){
a=a+1
}
a
Thank you in advance.
The condition is true if :
sum(2*comp > max(comp)) ==1
In this case , I would write it like this without using ìf:
a <- (sum(2*comp > max(comp)) ==1) + 1
I don't know if you want to add 1 every time you find a item bigger than max/2, which is what I am showing you. In case you want all to be false, add this line at the end.
if (a>0)
a=1;
I think this will work, haven't compiled it because here I don't have R compiler, but this is the idea:
comp=c(6.674971, 11.208241, 18.296459, 5.165752, 123.000000)
a=0
temp=comp/max(comp)
for (n in 1:length(comp))
{ if ((temp(i)>max(comp)/2)&&(temp(i)!1))
a=a+1
}
Hope it helps.

how to separate two array?

I'm creating a music to show notes on Treble and Bass but came to think the staffArray and staffArray2 is true for a given situation.
Such as staffArray and staffArray2 has a value of "1","1","1","1" and "2",2",2",2",2",2"...
When one of the function will identify if the i=0 is 1 then draw note:
if(staffArray[i] == "1" && typeArray[i]=="half" && stemArray[i]=="down") {
drawHalfDown(child,"-","-"); //child is the sprite name
}
Now will draw a note on a staff 2, the above staffArray is still valid and cause the note on staff 2 to be error, how do I rectify these array?
I'm not sure I understand all of what you are trying to do, but your error is probably caused by a typo in your if-clause: The single & is a bitwise, not a logical boolean operator and evaluates to a very different result. If you're interested, you can find out about bitwise AND here.
Your code should be:
if(staffArray[i] == "1" && typeArray[i]=="half" && stemArray[i]=="down") {
drawHalfDown(child,"-","-");
}

Resources