Can't find the objects in array that are clearly states - discord.js

So i am trying to make a periodic table bot (Don't question i got bored), so I turned my spreadsheet of the info into a csv then used this to convert it to a json. My main code for my command is here and this is my json file. It won't work, before it was saying how element.find is not a function now it can't find the things in my array.
if(!element.find(i => i.Symbol === args) || !element.find(i => i["Atomic Number"] == args)){
message.channel.send("Please use the command like this ``?pt (element symbol or atomic number)``")
return
}
also it keeps sending the "Please use the command like this.." command when ever i try and call a number or symbol that should be in the array.

The problem is in your if statement. You're checking whether the array element does not contain an item with property Symbol being args OR property Atomic Number being args. Since no periodic element has the same value for both the Symbol and Atomic Number, the condition will always return false for at least one of the two statements.
The fix is quite simple, just change the || to &&. This way the if statement will check whether the array does not contain an item with Symbol being args AND does not contain an item with Atomic Number being args. If either one of the two returns true, the code in the if statement won't be called

Related

Eiffel separate object into ensure statement

Is there a way to have a separate object to be checked as ensure with the separate obj as l_obj statement?
I guess having a boolean function should work.
Any reason for that I don't understand?
set_position (a_pos: like position)
do
position := a_pos
separate status_keeper as l_status_keeper_sep do
l_status_keeper_sep.set_position (position)
end
ensure
position = a_pos
separate status_keeper as l_status_keeper_sep do -- the compiler doesn't agree with separate keyword here
l_status_keeper_sep.position = a_pos
end
end
At the moment there is no "separate expression" similar to "separate instruction". And, as you mention, separate instructions are not allowed in the context where only a boolean expression is expected, in postconditions in particular.
Even if there were such a construct, it would not work. The separate object could change its state between two subsequent separate instructions. For example, the following code is wrong:
separate foo as x do
x.put (something) -- Set `foo.item` to `something`.
end
separate foo as x do
check
item_is_known: x.item = something
end
end
The check instruction could easily lead to assertion violation in the following execution scenario:
The first separate instruction is executed.
Some other processor makes a call to foo.put.
The check instruction compares something to the value set in step 2.
If the code has to ensure some property of a separate object, it should be enclosed in a routine body, and the separate object should be passed as an argument:
set_position (value: like position; keeper: like status_keeper)
do
position := value
keeper.set_position (value)
ensure
position = value
keeper.position = value
end
Separate instructions were invented only to avoid writing single-line wrappers just to make a call on a separate object. Anything else is better using the original SCOOP approach with full-fledged features with separate arguments.

How do I select whether the routine continues based on the participant's response?

I want to create an experiment in PsychoPy Builder that conditionally shows a second routine to participants based on their keyboard response.
In the task, I have a loop that first goes through a routine where participants have three options to respond ('left','right','down') and only if they select 'left', regardless of the correct answer, should they see a second routine that asks a follow-up question to respond to. The loop should then restart with routine 1 each time.
I've tried using bits of code in the "begin experiment" section as such:
if response.key=='left':
continueRoutine=True
elif response.key!='left':
continueRoutine=False
But here I get an error saying response.key is not defined.
Assuming your keyboard component is actually called response, the attribute you are looking for is called response.keys. It is pluralised as it returns a list rather than a single value. This is because it is capable of storing multiple keypresses. Even if you only specify a single response, it will still be returned as a list containing just that single response (e.g. ['left'] rather than 'left'). So you either need to extract just one element from that list (e.g. response.keys[0]) and test against that, or use a construction like if 'left' in response.keys to check inside the list.
Secondly, you don't need to have a check that assigns True to continueRoutine, as it defaults to being True at the beginning of a routine. So it is only setting it to False that results in any action. So you could simply do something like this:
if not 'left' in response.keys:
continueRoutine = False
Lastly, for PsychoPy-specific questions, you might get better support via the dedicated forum at https://discourse.psychopy.org as it allows for more to-and-fro discussion than the single question/answer structure here at SO.

Check if Json Array contains objects in Logic App

I am trying this out but I cant seem to get it to work.
In a Condition connector I'm doing this:
#contains(json(body('ParseCustomerDeltaXML')).newMembers[0], 'Member')
but i cant get it to work.
If it contains members it says true.
But if not i get an error:
InvalidTemplate. Unable to process template language expressions for action 'Condition' at line '1' and column '2706': 'The template language expression 'equals(json(body('ParseCustomerDeltaXML')).newMembers[0], null)' cannot be evaluated because array index '0' cannot be selected from empty array. Please see https://aka.ms/logicexpressions for usage details.'.
As indicated by the error message, the array you are trying to reference the first item of is empty. You want to make use of the safe dereference operator .?
Suppose newMembers is an empty array. Then newMembers[0] would fail, but newMembers?[0] would succeed (and return null).
In the specific scenario you are describing, you may need to use a nested condition as well (i.e. first check if newMembers is non-empty, and then check for membership).
To check for emptiness you can use the #empty() expression.
In my example I should check is element empty before fetching street data from element.
This works:
if(empty(body('Parse_JSON')?['results'][0]['addresses']), '', body('Parse_JSON')?['results'][0]['addresses'][0]['street'])
and this works too:
if(contains(['addresses'], ['addresses']?[0]), 'Do something', 'Or do this thing')
Hope that will help someone.

MATLAB: Matrix Index is out of range for deletion

I have this function where I use an array as a FIFO queue (i.e., put elements in it and process them using a first-in first-served approach). In particular, I call this array a MsgQueue as it holds messages.
The MsgQueue is used when a new msg is sent (event), which triggers the execution of the handleMsgSent() method, which I show next
function handleMsgSent(this, msg)
this.MsgQueue = [this.MsgQueue msg];
while(numel(this.MsgQueue) > 0)
m = this.MsgQueue(1);
this.MsgQueue = this.MsgQueue(2:end); % <----- OPTION A
% DO WHATEVER WITH THE MESSAGE
%this.MsgQueue(1) = []; % <------ OPTION B
end
end
As you can see I have marked the code with OPTION A and OPTION B comment. So, the point is option B ends up with the "Matrix Index is out of range for deletion" error while option A works (apparently) perfectly fine, with no errors.
Can anyone help me to understand the difference? Well, I understand that option A is not deleting anything but just "discarding" the first element of the array but, why does option B fails in deleting if there is at least one element in MsgQueue?
For an empty array, end is 0. If you check the documentation for the colon operator, for start>end it returns an empty array. Thus, the first option deletes noting in some cases while the second option always indexes the second element.
After debugging my code I seem to have realised of the reason. In my code there is a comment:
% DO WHATEVER WITH THE MESSAGE
The problem was that at this point I was invoking another method that triggered new messages to be sent and thus entering the handleMsgSent() method again. Thus, when I modify the MsgQueue before that I have no problems but when I do it afterwards I get into trouble.

Visual Foxpro Array [] or ( )

In a Visual Foxpro application one of the users get an error (the rest doesn't). And i believe its because arrays are used in the form of arr(number) instead of arr[number] . Does anyone know what causes this strange behavior at a single user?
Thanks!
Foxpro does not differentiate between the two. This is actually documented in both the DIMENSION and DECLARE commands' remarks.
In fact, the documentation doesn't strictly follow one way or another. The DIMENSION and DECLARE commands define the syntax with parenthesis ().
DIMENSION ArrayName1(nRows1 [, nColumns1]) [AS cType]
[, ArrayName2(nRows2 [, nColumns2])] ...
But the example provided in the Arrays section of the documentation uses brackets [].
DIMENSION ArrayName[5,2]
ArrayName[1,2] = 966789
Either use of array references is valid as long as its properly balanced as () or []. The problem is probably upstream where the array is getting declared or prepared. I've had to debug historically strange instances like this where one user was going about a process in a totally different way than others, and the business work flow... Anyhow, because of some "bypassed" process, the array wasn't getting created and thus forced a failure.
Does it always crash at the same location in the process?
I would strongly encourage some error trapping in the process for this "one" user. Worse comes to worse, I would put something in the area of the code something like...
if atc( "PersonsLoginName", sys(0)) > 0
TurnOnMyCustomDebugging() && for this special scenario trapping
endif
Additionally, I don't know what you have for error trapping routines, but I'd get a dump of memory at the time of the error and the full call stack that got the user to that point. If you need help on that, let me know too.
I didn't understand why this question was "bumped" from 2010. Maybe because it is kind of "VFP basics" and need details?
Answers are already good. [] and () could be used. It is primarily a preference.
VFP actually doesn't even care if the name denotes and array. It might be a function accepting one or two integer parameters (1..N). However, if there is an array in scope then it takes precedence.
Example:
Dimension Dummy[10]
? Dummy[5] && prints .F. - array members are not initialized
Dummy[2] = 6 && sets array member
? Dummy[2] && prints 6
Release Dummy && array variable released
? Dummy[5] && prints 10 - procedure is called
* Dummy[2] = 6 && error - variable does not exists
? Dummy[2] && prints 4 - procedure is called
Procedure Dummy(tnDim1)
Return m.tnDim1 * 2
endproc
It wouldn't matter if you used [] or () for an array or function (or procedure - in VFP procedure and function also has no difference, both accept parameters and return result).
As per the OP question, a single user wouldn't have a different result just because [] or () used.

Resources