Checking if condition on Long type for velocity template - velocity

Long type from java is not working with velocity if condition
I am using velocity engine for email with Java where one of the variables type is Long.
While trying if condition on that variable it never succeeds.
Tried following ways but none was helpful,
#if($customTypeList.LongTypeId == 1)
#if($customTypeList.LongTypeId == '1')
#if($customTypeList.LongTypeId == "1")
It should go inside the if condition as variables value is 1.
I have validated that with sysout and even by printing in template.

Actually got the answer after number of trials...
Posting to help others.
#if($customTypeList.longTypeId.intValue() == 1)

Related

arduino: loop until int gets value assigned to it

I am trying to get a value from serial input. The rest of the programm behaves different if the value changes. This value gest assigned once in the ```void setup()``` function.
My goal is to let the program run an infinite loop or something similar until a value (type int) is recived, and only then resume the flow.
I know about ```Serial.parseInt()``` and tried to implement it ``` while (variable == null) variable = Serial.parseInt() ``` but I got an error that 'null' was not declared in this scope.
Any suggestions?
Oke, i was kinda dumb.
There is an easy way, simply check
while (!variable)
variable = Serial.parseInt()
This worked for me and should work for you as well

defining a variable to set length of an array is failing but assert and print works

def count = * print response.teams[0].teamMembers.length throws below error
com.jayway.jsonpath.PathNotFoundException: Expected to find an object
with property ['length'] in path $['teams'][0]['teamMembers'] but
found 'net.minidev.json.JSONArray'.
This is not a json object
according to the JsonProvider:
'com.jayway.jsonpath.spi.json.JsonSmartJsonProvider'.
print response.teams[0].teamMembers.length and
assert response.teams[0].teamMembers.length == 9
are working just fine.
Any help here is much appreciated.
Yes, Karate assumes the right-hand-side as Json-Path (which is fine for 90% of the cases). Use parentheses to force JavaScript evaluation when needed.
Try this:
def count = (response.teams[0].teamMembers.length)
For a detailed explanation, please refer to this section in the documentation: Karate Expressions

Evaluating Variables in Load Script

Is there any reason that this syntax shouldn't work in Qlikview load script??
Let v_myNumber = year(today());
Let v_myString = '2017-08';
If left($(v_myString),4) = text($(v_myNumber)) Then
'do something
Else
'do something else
End If;
I've tried both ways where I convert variable string to number and evaluate against the number variable directly and this way. They won't evaluate to equivalence when they should..
Left function is expecting a string as is getting something else as a parameter. As you are currently doing, the function will be called as Left(2017-08, 4) which is unhandle by QlikView.
If you use Left('$(v_myString)',4), it will evaluate as Left('2017-08', 4) as work as expected. Just adding quotes around the variable it should work.
Although QlikView calls them variables, they should really be seen as "stuff to replaced (at sometimes evaluated) at runtime", which is slightly different from a standard "variable" behaviour.
Dollar sign expansion is a big subject, but in short:
if you are setting a variable - no need for $().
if you are using a variable - you can use $(). depends on its context.
if you are using a variable that needs to be evaluated - you have to use $().
for example in a load script: let var1 = 'if(a=1,1,2)' - here later on the script you will probably want to use this variable as $(var1) so it will be evaluated on the fly...
I hope its a little more clear now. variable can be used in many ways at even can take parameters!
for example:
var2 = $1*$2
and then you can use like this: $(var2(2,3)) which will yield 6
For further exploration of this, I would suggest reading this

validating user input to text only and integer only

i have searched for a simple, non complicated answer on how to ensure that the user is asked again if they enter anything other than text for 1 and an integer for 2.
when entering these input variables, however i have only found complicated solutions that my teacher wont acccept.
is it possible if anyone can provide me with simple solutions on how to validate these variables. so far all i know how to validate is to use "while not in" functions, which only works for specific options. I am new to python, so please explain in a simple manner. thanks! :)
1-studentname=input("what is your name?:")
2-print("what is 10+10?:")
3-studentanswer=int(input("insert answer:"))
You can use a while loop with if , else in it
while(true):
t = int(input());
if t == 1:
# do whatever --> break at the end
else if t == 2:
# do whatever ---> break at the end
else:
continue
You can use the .isalpha and .isdigit method.
For example,
studentname=input("what's your name) ?
studentname.isalpha()
That checks whether the string consists of alphabetic characters only.
Both .isalpha and .isdigit return boolean, so you can use an if condition then.

calling script_execute with a variable

I'm using GameMaker:Studio Pro and trying to execute a script stored in a variable as below:
script = close_dialog;
script_execute(script);
It doesn't work. It's obviously looking for a script named "script". Anyone know how I can accomplish this?
This question's quite old now, but in case anyone else ends up here via google (as I did), here's something I found that worked quite well and avoids the need for any extra data structures as reference:
scriptToCall = asset_get_index(scr_scriptName);
script_execute(scriptToCall);
The first line here creates the variable scriptToCall and then assigns to it Game Maker's internal ID number for the script you want to call. This allows script_execute to correctly find the script from the ID, which doesn't work if you try to pass it a string containing the script name.
I'm using this to define which scripts should be called in a particular situation from an included txt file, hence the need to convert a string into an addressable script ID!
You seem to have some confusion over how Game Maker works, so I will try to address this before I get around to the actual question.
GML is a rather simple-minded beast, it only knows two data types: strings and numbers. Everything else (objects, sprites, scripts, data structures, instances and so on) is represented with a number in your GML code.
For example, you might have an object called "Player" which has all kinds of fancy events, but to the code Player is just a constant number which you can (e.g.) print out with show_message(string(Player));
Now, the function script_execute(script) takes as argument the ID of the script that should be executed. That ID is just a normal number. script_execute will find the script with that ID in some internal table and then run the script.
In other words, instead of calling script_execute(close_dialog) you could just as well call script_execute(14) if you happened to know that the ID of close_dialog is 14 (although that is bad practice, since it make the code difficult to understand and brittle against ID changes).
Now it should be obvious that assigning the numeric value of close_dialog to a variable first and then calling script_execute on that variable is perfectly OK. In the end, script_execute only cares about the number that is passed, not about the name of the variable that this number comes from.
If you are thinking ahead a bit, you might wonder whether you need script_execute at all then, or if you could instead just do this:
script = close_dialog;
script();
In my opinion, it would be perfectly fine to allow this in the language, but it does not work - the function call operator actually does care about the name of the thing you try to call.
Now with that background out of the way, on to your actual question. If close_dialog is actually a script, your suggested code will work fine. If it is an extension function (or a built-in function -- I don't own Studio so what do I know) then it does not actually have an ID, and you can't call it with script_execute. In fact, you can't even assign close_dialog to a variable then because it does not have any value in GML -- all you can do with it then is call it. To work around this though, you could create a script (say, close_dialog_script which only calls close_dialog, which you can then use just as above.
Edit: Since it does not seem to work anyway, check whether you have a different resource by the name of close_dialog (perhaps a button sprite). This kind of conflict could mean that close_dialog gives you the ID of the sprite, not of the script, while calling the script directly would still work.
After much discussion on the forums, I ended up going with this method.
I wrote a script called script_id()
var sid;
sid = 6; //6 = scriptnotfound script :)
switch (argument0) {
case "load_room":
sid = 0;
break;
case "show_dialog":
sid = 1;
break;
case "close_dialog":
sid = 3;
break;
case "scrExample":
sid = 4;
break;
}
return sid;
So now I can call script_execute(script_id("close_dialog"));
I hate it, but it's better than keeping a spreadsheet... in my opinion.
There's also another way, with execute_string();
Should look like this:
execute_string(string(scriptName) + "();");