how to separate two array? - apache-flex

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,"-","-");
}

Related

Length Zero in r

Greetings I am getting an error of
Error in if (nrow(pair) == 0) { :argument is of length zero
I have checked the other answers but do not seem to work on a variable like mine. Please check code below, please assist if you can.
pair<-NULL
if(exists("p.doa.ym")) pair <- rbind(pair, p.doa.ym[,1:2])
if(exists("p.doa.yd")) pair <- rbind(pair, p.doa.yd[,1:2])
if(nrow(pair) == 0) {
print("THERE ARE NO MATCHES FOR TODAY. STOP HERE")
quit()
}
Since you set pair=NULL and then it might happen that pair stays null if those two if statements are not true, you either need to check if pair is null first, or you could set pair to an empty data frame, or something else.
One option:
if (!is.null(pair)) {
if (nrow(pair)==0) {
# your code
}
}
Another option:
pair=data.frame()
# your code

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).

if && statement help needed Newbie

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..

Drools rule to check a collection with compound value restriction

I want to check if a collection contains not three elements. In java I would do
!(collection.contains("s1") && collection.contains("s2") && collection.contains("s3"))
How can I do this with drools? I searched for two hours and tried anything but can't find a solution for this "simple" problem. I found the "Compound Value Restriction" which is what I exactly need, but it does not work for collections and the "contains" operator.
I would appreciate your answers.
Nathanael
This does what the Java code does:
Collection( this not contains "s1" ||
this not contains "s2" ||
this not contains "s3")
I think, You can take rule dialect "java".
Following sample can help you.
global java.util.ArrayList responseList
rule "checkCollectionRule"
dialect "java"
salience -1
when
eval(ifContains(responseList, val1, val2.....))
then
responseList.add(new Boolean("true"));
end
function Boolean ifContains(List responseList, String val1, String val2,....) {
return (responseList.contains("s1") && responseList.contains("s2") && responseList.contains("s3"));
}
Hope this help.
Thanks.

Resources