I am learning objective-c when this thing come and bother me.
I tried to make a program that will return which PDF should be shown when the user input specific things.
My code looks like this
filePath = (userChooseA) ? #"firstFilePath" : #"secondFilePath";
By right if User choose A, the file path will be firstFilePath and vice versa.
However, when I purposely input the non existent file for firstFilePath, the system will directly show secondFilePath regardless user's choice.
My Question is,
why is this happening and how to prevent it?
Thank You,
Regards
That's because this statement is equivalent to:
if(userChooseA)
{
filePath = #"firstFilePath";
}else{
filePath = #"secondFilePath";
}
I assume userChooseA is a BOOL set somewhere else in your code when comparing paths, and it's false if the user chooses B or any other path.
Which means that unless the user chooses A, the file path will be B.
If you want to do something else if neither A or B are chosen, you could write (again assuming UserChooseA and userChooseB are Bool set somewhere else in your code):
int fileSelection = 3;
If (userChooseA) fileSelection = 0;
If (userChooseB) fileSelection = 1;
switch (fileSelection) {
case 0:
filePath = #"firstFilePath";
break;
case 1:
filePath = #"secondFilePath";
break;
default:
... do something else...
break;
}
if this is off base, as suggested in the comments we need to see more code about what type userChooseA is and how it gets set.
Related
I have been looking for a solution everywhere on the internet but nowhere I can see a single script which lets me read the name of a variable as a string in Godot 3.1
What I want to do:
Save path names as variables.
Compare the name of the path variable as a string to the value of another string and print the path value.
Eg -
var Apple = "mypath/folder/apple.png"
var myArray = ["Apple", "Pear"]
Function that compares the Variable name as String to the String -
if (myArray[myposition] == **the required function that outputs variable name as String**(Apple) :
print (Apple) #this prints out the path.
Thanks in advance!
I think your approach here might be a little oversimplified for what you're trying to accomplish. It basically seems to work out to if (array[apple]) == apple then apple, which doesn't really solve a programmatic problem. More complexity seems required.
First, you might have a function to return all of your icon names, something like this.
func get_avatar_names():
var avatar_names = []
var folder_path = "res://my/path"
var avatar_dir = Directory.new()
avatar_dir.open(folder_path)
avatar_dir.list_dir_begin(true, true)
while true:
var avatar_file = avatar_dir.get_next()
if avatar_file == "":
break
else:
var avatar_name = avatar_file.trim_suffix(".png")
avatar_names.append(avatar_name)
return avatar_names
Then something like this back in the main function, where you have your list of names you care about at the moment, and for each name, check the list of avatar names, and if you have a match, reconstruct the path and do other work:
var some_names = ["Jim","Apple","Sally"]
var avatar_names = get_avatar_names()
for name in some_names:
if avatar_names.has(name):
var img_path = "res://my/path/" + name + ".png"
# load images, additional work, etc...
That's the approach I would take here, hope this makes sense and helps.
I think the current answer is best for the approach you desire, but the performance is pretty bad with string comparisons.
I would suggest adding an enumeration for efficient comparisons. unfortunately Godot does enums differently then this, it seems like your position is an int so we can define a dictionary like this to search for the index and print it out with the int value.
var fruits = {0:"Apple",1:"Pear"}
func myfunc():
var myposition = 0
if fruits.has(myposition):
print(fruits[myposition])
output: Apple
If your position was string based then an enum could be used with slightly less typing and different considerations.
reference: https://docs.godotengine.org/en/latest/tutorials/scripting/gdscript/gdscript_basics.html#enums
Can't you just use the str() function to convert any data type to stirng?
var = str(var)
I am using Ncalc to evaluate the presence of some string values
if (#Xval = 'Z','T','F')
this works well when #xval is inputted as a parameter as a single value(#Xval = 'Z'). That will return a true evaluation. I am now looking to evaluate the same formula when #Xval may be say 'Z','H' in other words Xval contains those 2 values and Im trying to find if 'Z' is among them.
The same goes for if (in (#Xval,'Z','H','M'),'T','F') where Im looking for the value of Xval in a group of options (Z,H,M).
Can I do this via custom functions? If so how? Any other ideas?
Thank you
You can try
Expression e = new Expression("if (iscontians("ZHM",#Xval),'T','F')", EvaluateOptions.IgnoreCase);
e.EvaluateFunction += evalFunction;
Write a custom function
private void evalFunction(string name, FunctionArgs args)
{
switch (name.ToUpper())
{
case "ISCONTAINS":
if (args.Parameters.Length < 2)
throw new ArgumentException("isContains() takes at least 2 arguments");
args.Result = args.Parameters[0].Evaluate().ToString().Contains(args.Parameters[1].Evaluate().ToString());
break;
default:
break;
}
}
I am modifying the SalesConfirmDP class and trying to add the CustVendExternalItem.ExternalItemTxt field into a new field I have created.
I have tried a couple of things but I do not think my syntax was correct i.e I declare the CustVendExternalItem table in the class declaration. But then when I try to insert CustVendExternalItem.ExternalItemTxt into my new field, it does not populate, I guess there must be a method which I need to include?
If anyone has any suggestion it would be highly appreciated.
Thank you in advance.
private void setSalesConfirmDetailsTmp(NoYes _confirmTransOrTaxTrans)
{
DocuRefSearch docuRefSearch;
// Body
salesConfirmTmp.JournalRecId = custConfirmJour.RecId;
if(_confirmTransOrTaxTrans == NoYes::Yes)
{
if (printLineHeader)
{
salesConfirmTmp.LineHeader = custConfirmTrans.LineHeader;
}
else
{
salesConfirmTmp.LineHeader = '';
}
salesConfirmTmp.ItemId = this.itemId();
salesConfirmTmp.Name = custConfirmTrans.Name;
salesConfirmTmp.Qty = custConfirmTrans.Qty;
salesConfirmTmp.SalesUnitTxt = custConfirmTrans.salesUnitTxt();
salesConfirmTmp.SalesPrice = custConfirmTrans.SalesPrice;
salesConfirmTmp.DlvDate = custConfirmTrans.DlvDate;
salesConfirmTmp.DiscPercent = custConfirmTrans.DiscPercent;
salesConfirmTmp.DiscAmount = custConfirmTrans.DiscAmount;
salesConfirmTmp.LineAmount = custConfirmTrans.LineAmount;
salesConfirmTmp.CurrencyCode = custConfirmJour.CurrencyCode;
salesConfirmTmp.PrintCode = custConfirmTrans.TaxWriteCode;
if (pdsCWEnabled)
{
salesConfirmTmp.PdsCWUnitId = custConfirmTrans.pdsCWUnitId();
salesConfirmTmp.PdsCWQty = custConfirmTrans.PdsCWQty;
}
**salesConfirmTmp.ExternalItemText = CustVendExternalItem.ExternalItemTxt;**
if ((custFormletterDocument.DocuOnConfirm == DocuOnFormular::Line)
|| (custFormletterDocument.DocuOnConfirm == DocuOnFormular::All))
{
docuRefSearch = DocuRefSearch::newTypeIdAndRestriction(custConfirmTrans,
custFormletterDocument.DocuTypeConfirm,
DocuRestriction::External);
salesConfirmTmp.Notes = Docu::concatDocuRefNotes(docuRefSearch);
}
salesConfirmTmp.InventDimPrint = this.printDimHistory();
Well, AX cannot guess which record you need, there is a helper class CustVendExternalItemDescription to deal with it:
boolean found;
str externalItemId;
...
[found, externalItemId, salesConfirmTmp.ExternalItemText] = CustVendExternalItemDescription::findExternalItemDescription(
ModuleCustVend::Cust,
custConfirmTrans.ItemId,
custConfirmTrans.inventDim(),
custConfirmJour.OrderAccount,
CustTable::find(custConfirmJour.OrderAccount).CustItemGroupId);
The findExternalItemDescription method returns more information than you need here, but you have to define variables to store it anyway.
Well, the steps to solve this problem are fairly easy and i will try to give you a step by step approach how to solve this problem.
1) Are you initialising CustVendExternalItem properly? Make a record of the same and initialise it as Jan has shown above, then debug your code and see if the value is being initialised in your DP class.
2)If your value is being initialised correctly, but it is not showing up in the report design there can be multiple issues such as:
Overlapping of text boxes.
Insufficient space for the given field
Some report parameter/property not being set correctly which causes
your value not to show up on the report.
Check these one by one and you should end up arriving towards a solution
In Scalding, suppose you have a TypedPipe[Long] or ValuePipe[Long]. How would you go about checking whether they are empty in the most elegant/efficient way?
Currently testing the following:
val isTPEmpty: Boolean = typePipe.equals(TypedPipe.empty)
val isVPEmpty: Boolean = valuePipe.equals(EmptyValue)
Or, to make it more generic:
def isTypedPipeEmpty[A](typedPipe: TypedPipe[A]): Boolean = {
val emptyTP: TypedPipe[A] = TypedPipe.empty
typedPipe.equals(emptyTP)
}
UPDATE: this doesn't work (will return false for an empty TypedPipe). Appreciate any inputs.
After speaking to several people on this, there is no straight solution simply because a TypedPipe is distributed, and checking whether it is empty is "expensive", therefore one should avoid this as much as possible.
If you absolutely have no choice, what worked for me was something "ugly" as creating a temporary empty TypedPipe, then calling mapWithValue on my ValuePipe, and if it is empty do X, otherwise do Y. Something like:
TypedPipe.from(List()).mapWithValue(valuePipe) { case (temp, valuePipe) => if (valuePipe.isEmpty) doX else doY }
But again, cumbersome.
I'm trying to write a basic DST converter. I have a segmented control with 3 choices, their titles (surprisingly) are Distance, Speed and Time. I have 2 input text fields and a calculate button, as well as 2 labels for each text field with the type of measurement required and it's units. Making a selection on the segmented control should update the view accordingly. The variables have all been declared as IBOutlets, #property, #synthesize, and the code sits in an IBAction method, which is connected to the segmented control. The following code does not work, am I missing something completely obvious? (NSLog shows the correct title)
NSString *choice;
choice = [dstChoiceSegmentedControl titleForSegmentAtIndex: dstChoiceSegmentedControl.selectedSegmentIndex];
NSLog(#"Choice |%#|", choice);
if (choice == #"Distance") {
firstLabel.text = #"Speed:";
firstUnitsLabel.text = #"kts";
secondLabel.text = #"Time:";
secondUnitsLabel.text = #"hrs";
answerUnitsLabel.text = #"nm";
} else if (choice == #"Speed") {
firstLabel.text = #"Distance:";
firstUnitsLabel.text = #"nm";
secondLabel.text = #"Time:";
secondUnitsLabel.text = #"hrs";
answerUnitsLabel.text = #"kts";
} else if (choice == #"Time") {
firstLabel.text = #"Distance:";
firstUnitsLabel.text = #"nm";
secondLabel.text = #"Speed:";
secondUnitsLabel.text = #"kts";
answerUnitsLabel.text = #"hrs";
}
Thanks for your help (and I hope it's not some silly error that is staring me right in the face)!
You cannot compare strings this way. You need to do:
[choice isEqualToString:#"Distance"];
But if I were you, I'd check for the indicies instead.
edit: To explain it further: what you're doing with choice == #"Distance" is comparing a pointer with a string, which will not work. You need to call the string objects comparing method as shown above.