In Unity know which button is clicked [closed] - unity3d

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I have two buttons create and join. Both button's on click event I move to next scene, but in next scene I have two scripts networkmanager and networkclient.
Now if I press create button I want to call only networkmanger not networkclient. So how can I disable the networkclient script and join I want to disabled networkmanger?
How can I know which button is been pressed?

public void OnPress(){
string name = this.gameObject.name;
switch(name){
case "Create":break;
case "Join":break;
}
}
You can read the name of the object the script is attached to.
If this is not suitable for any given reason (both scripts are on same object), you can pass a parameter to the method.
public void OnPress(string name){
switch(name){
case "Create":break;
case "Join":break;
}
}
then you give the name in the inspector.
The final way is to use two different methods for each button.

Related

How to show Alert when I encountered API request error in SwiftUI via ViewModel? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
Below is the NewsViewModel. What property should I add in this viewModel to trigger an Alert in its corresponding View? Thanks in advance.
I would create an enum type for this. In your view model, I might add something like:
enum Error {
case noNetwork
case noNewsFound
case missingImages
var alert: Alert {
switch self {
// Build SwiftUI.Alert instances for each error case
}
}
}
I then would add this property to your view model:
#Published var error: Error?
Lastly, in your view, I would add this:
// Your view here
.alert(item: $viewModel.error) { error in
error.alert // This returns the computed Alert you added to your Error type
}
Then in your view model, you just set the error property to the appropriate error, and your view will show the alert.

How to fix button clicked not updating but others do [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I'm making a math game. Every time I click a button a new question should appear with different results to choose from.
However every time I click the button which I think is the result it doesn't update the text but the others do.
See github: https://github.com/Combii/BrainTrainerSwift
Use UIButton.setTitle(, for:) method. I suggest you to change code in ViewController.swift:
func setNumbers(numberDic: Dictionary<String, Int>) {
let btns = [bt1, bt2, bt3, bt4]
UIView.performWithoutAnimation {
for (position, number) in numberDic {
btns[(Int(position) ?? 0) - 1]?.setTitle(String(number), for: .normal)
}
}
}

How do I update this variable with data [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
New programmer here! I'm working with a network request and below is a snippet of my code. After I complete the network request I want to store a value from the request into a variable. However, when the variable is called outside of the if let statement it is NOT updated. Essentially, the print statement inside the if let statement prints the value I'm looking for, but the print statement outside of the if let statement prints the default value I set for that variable. The variable is global. I need to use that updated variable elsewhere in my code, any ideas?
if let data = data {
self.nameLabel.text = data.name
person = data.name
print(person)
}
print(person)
First of all you didn't showed complete code so I am guessing you need main queue to update your UILabel first as shown in below code:
DispatchQueue.main.async {
self.nameLabel.text = data.name
}
next thing is if you want to access the value somewhere else once your request completes and UILabel updated then you can get the value from it this way:
let value = self.nameLabel.text!
And if you want to access the value once request complete then you can use closure and HERE you can check example of it.

how to use signals and slots in blackberry cascades [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
how to read data from QML page using signals
how to wite received data in another QML page using signals
i excatly expect qtsignals and slots concepts. please anybody tell how to read and wrote data from qml page.
Try the following syntax and get sample from github
1.HPP FILE
Q_PROPERTY(QString companyname READ companyname WRITE setcompanyname NOTIFY companynameChanged)
void companynameChanged();
void setcompanyname(const QString &company);
QString companyname() const;
QString m_company;
2.CPP FILE
void ApplicationUI::setcompanyname(const QString &company)
{
if (m_company == company)
return;
m_company = company;
emit companynameChanged();
}
QString ApplicationUI::companyname() const
{
return m_company;
}
------------------- Get sample full code from here (CLICK HERE)-----------

Unable to set member variable [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Very strange issue.
I have the following code:
NSDictionary* notificationUserInfo = [pNotification userInfo];
NSManagedObject* newShoppingFilter = [notificationUserInfo valueForKey:#"shoppingListFilter"];
self.shoppingListFilter = newShoppingFilter;
NSLog(#"%# tapped", [newShoppingFilter valueForKey:#"name"]);
For some reason the self.shoppingListFilter = newShoppingFilter is not setting the variable.
I assume that this is some issue with not initializing the self.shoppingListFilter variable in some way but I cannot figure this out. The NSLog shows the right output, newShoppingFilter is not null but self.shoppingListFilter is.
Any help is appreciated.
I bet newShoppingFilter is nil. Most likely, there is no key "shoppingListFilter" in the notification user info dictionary.
Set a breakpoint at the line that assigns a value to self.shoppingListFilter and check the value of newShoppingFilter. Also display the entire contents of notificationUserInfo.
Post the code that creates the user info dictionary and passes it into the notification that you are posting. That would help track down the problem.