Processing JS Hit Box Not Working - processing.js

I am trying to make a hit box that causes a program restart when triggered.
Here is the code I am using:
if(snakey.position.x < mos.position.x + 20 && snakey.position.y > mos.position.y - 20 || snakey.position.x > mos.position.x - 20 && snakey.position.y < mos.position.y + 20){
Program.restart();
}
The problem is that instead of triggering the program restart when the hit box is entered it seems to be triggering randomly or at least very erratically. I have checked this several times and am getting no error messages so the syntax is fine.
Me and a friend have also both gone over the logic several times to make sure that the conditions can actually be met. We have found no problems, but it is still not activating the program restart at the right time or even at a consistent time I will link the full program bellow if anyone can tell me why it is acting so strange I would appreciate it.
https://www.khanacademy.org/computer-programming/spin-off-of-project-computational-creatures/5001415574814720

you need to wrap the conditions in brackets properly
if((snakey.position.x < mos.position.x + 20 && snakey.position.y > mos.position.y - 20) || (snakey.position.x > mos.position.x - 20 && snakey.position.y < mos.position.y + 20))

Related

How to utilize the batch function with multiple inputs to receive one agent from each input to meet the batch?

I have 8 inputs that I would like to combine to one agent using the batch block. All the inputs have the same flow rate (1 per minute) and I would like them all to deliver one and only one agent to the batch so all inputs deliver one agent for the batch to be complete.
I have tried to use a delay and queue to manually restrict flow but that has not worked. I got an error saying cannot restrict flow but I have the inputs set "agents that cant exist are destroyed".
I also looked into trying to use a function but have not come across one that makes sense in my problem. Any help would be appreciated!
In a very primitive way you can build the following model:
You will define the HOLD block as follows:
The function will check that each queue has at least one agent ready and then release agents from each HOLD block:
if (queue.size() > 0 &&
queue1.size() > 0 &&
queue2.size() > 0 &&
queue3.size() > 0 &&
queue4.size() > 0 &&
queue5.size() > 0 &&
queue6.size() > 0 &&
queue7.size() > 0 )
{
hold.unblock();
hold1.unblock();
hold2.unblock();
hold3.unblock();
hold4.unblock();
hold5.unblock();
hold6.unblock();
hold7.unblock();
}
Every time an agent arrives you call the function() under the onAtExit event of your sources.

Run "apoc.periodic.commit" inside "apoc.periodic.repeat"

I would like to run every x second script that uses apoc.periodic.commit. The natural way for me would be to put it inside apoc.periodic.repeat.
But: If I do something like this:
CALL apoc.periodic.repeat(
"test",
"
CALL apoc.periodic.commit(
'
CREATE (a:TEST)
WITH a LIMIT 1
RETURN 0;
'
)
",
1
);
the Neo4j start executing it,... but never finish (It doesn't insert Node TEST). And if I stop the periodic and registrate a new one (one without apoc.periodic.commit, that I know works), the new one doesn't run either... I need to restart the Neo4j to work again.
Any suggestion on where I am doing wrong?

How do I wait for an element to disappear in Cypress?

I'd like to preface this by saying that I really tried looking here and anywhere else for an answer but without a succes.
Here is the problem:
I'm trying to automate a test for a web application that is loading a bigger amount of data and therefore has to be loading for a while. I have to wait for the page to load to do the next step and I'm trying to figure how to wait for the loading gif to be complete so that my tests can continue. The gif is a basic spinning thingy.
I would like to avoid using implicit wait time (cy.wait()) that is really only the last resort if noone is able to solve this.
What I found o far are these two functions:
cy.waitFor - this seems to be used mostly in situations, where you are waiting for an element to apper - I've tried this in different scenarios and works perfcetly but I havent been able to apply it here.
cy.waitUntil - this seems to be the thing I'm looking for but there is one huge problem. This function seems to have a timeout and I haven't been able to change it any other way than by changing timeouts globally for all the functions. If I set the global timeout to some longer period (minute +), then it works exactly how I would want it to work but obviously I dont really want to have such a long timeout for everything.
The way I see it, there are two possible solutions to this problem>
to change/turn off the timeout for the waitUntil function.
2)Or to somehow make it work with waitFor, because there seems to be no implicit timeout there and it just kind of waits forever for something to happen.
here is the code snippet of the situation:
cy.get('#load-data-button').click() // this clicks the button that stars the loading proces
cy.waitUntil(() => cy.get('body > div > my-app > billing > div > div > div.text-center > img').should('not.be.visible',) ) // this is the function that waits until the loading gif is invisible
I would be eternaly grateful for a solution, because unfortunatelly no one at my company is really a Cypress expert so they are not able to help.
Could you try something like:
cy.get([loading-spinner-identifier]).should("not.be.visible", { timeout: 60000 });
cy.get([an element that should now be visible]).should("be.visible");
It's a bit rough and ready, but I've used it when waiting for spinners to finish up. This waits a minute to see the spinner isn't there and then checks to see that something I'm expecting is there. I'd had varying success with this, but it has helped in some situations.
You can indeed use cy.waitUntil(). As you can see in the documentation of that package (https://www.npmjs.com/package/cypress-wait-until#arguments), the timeout that the function has is just the default (5000 ms) of an argument you can change it. You can even change how often cypress checks the condition you want, so if you do something like:
cy.waitUntil(() => cy.get('body > div > my-app > billing > div > div > div.text-center > img').should('not.be.visible'), {
errorMsg: 'The loading time was too long even for this crazy thing!',
timeout: 300000,
interval: 5000
});
...it will try for 300 seconds (5 minutes) each 5 seconds (just an example with very long timeout).
Also, maybe you can consider to wait until some element is visible after that loading spinner, instead of checking if it dissapeared. If you want to specifically test it, is fine, but if some element appears or becomes interactable after the loading, it could happen that is still not in the state you want, for a fraction of a second, after the spinner is not visible. If that is the case, I would avoid the checking of the spinner dissapearing in first place, unless it adds value to your test, and I would just wait for that element to be in the state you want (for example wait until some input is not disabled, element is visible, text appeared somewhere...).
Add positive and negative assertion to make sure loading spinner is visible.
Default Time is 4s for assert statement.
You can increase defaultTime to wait for assertion to validate by adding configuration in cypress.json
{
...
"defaultCommandTimeout": 4000,
...
}
const waitForSpinner = () => {
// First, make sure the loading indicator shows up (positive assertion)
cy.get('[data-qa="qa-waiting-spinner"]').should('be.visible')
// Then Assert it goes away (negative assertion)
cy.get('[data-qa="qa-waiting-spinner"]').should('not.be.visible')
}

Is there any way in calabash- android to run a single step in a scenario for multiple times

I want to run a single step in the my scenarios for multiple times. My scenario consists of connect and disconnect steps.
I have used the while loop to do a work around for it,but was helpless, as the test fails with 'Ambiguous match of "I tap on disconnect button":'. This may be reason as the test executes the same line "I tap on disconnect button" or "I tap on connect" multiple,which Gerkhin may not support as the language is repeating while the loop is running.
Here are the steps:
Then I select the item from the list
Then I tap on disconnect button
Then I tap on connect to reconnect
I want second two steps to be executes 10 times when the run the scenarios.
Can someone help on this.
You can make it like this
Then I restart connection
step def:
$i = 0
$num = 10
while $i < $num do
#YOUR CODE HERE
#DISCONNECT
sleep(3)
#CONNECT
puts("Inside the loop i = #$i" )
$i +=1
end
It should work if you use only one element of UI and you dont change it, on the other hand to help you in future if you have problem with multiply different elements in calabash-android use Table calabash-android construction.
Could you not just make the step definition
Then I reconnect 5 times
Step def
Then /^I reconnect (.*) times$/ do |repetitions|
repetition.times do
... your code here
end
end

cocoa-applescript: running handler or command every few seconds

In normal applescript, the script is executed down the page, and so any code in loops for every 5 seconds will only run while the loop is running - there is no way to have a single function run every few second regardless of what the script is currently doing or where it is in the script (that I know of). In cocoa-applescript, however, is there a way to run a handler every 5 seconds, at all times, no matter what it is currently doing? Here is what it should be doing in my cocoa-applescript app:
on checkInternetStrength()
do shell script "/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I | grep 'agrCtlRSSI:'" -- this being the script which returns the line containing the signal strength
set SignalStrength to result
set RSSIcount to (count of characters in SignalStrength)
set SignalStrength to ((characters 18 thru RSSIcount of SignalStrength) as string) as integer -- this to turn SignalStrength into just the number and not the whole output line
set SignalStrength to (100 + SignalStrength) as integer
set SignalBar's setIntValue_(SignalStrength) -- SignalBar being the Level Indicator described below
end checkInternetStrength
Summed up, it runs the airport command to check internet connection, turns this into a number from 1 to 100 and uses this on an NSLevelIndicator (100 maximum) to show current signal strength graphically. Now, there is no point having this run once or when you hit a button - that is an option, but it would be nice if it updated itself every, say, 5 seconds with the realtime value. So is there any way to have a process which runs every 5 seconds to do this, while still enabling full functionality of the rest of the script and interface - i.e. as a background process? Comment if you need more extracts from the script.
Example
In Unity-C# scripting, the 'void Update() {code}' will run the code within it every frame while doing everything else simultaneously, so a cocoa-applescript version of this might be an answer, if anyone knows.
I Dont believe this is possible but what I had a similar problem before, what i do, I have an external applescript applicaion that is hidden the repeats the commands, the only problem is, it wont send it back to the app, you'll have to make the external applescript app do it, like
display notification, etc..., in the applescript apps "Info.plist" you can add this:
<key>LSUIElement</key>
<string>1</string>
To make the app run invisibly, but sorry i dont think you can run a handler in the app its self