particleSystem.startSize vs particleSystem.main.startSize - c#

The current solution that works is
gameObject.GetComponent<ParticleSystem>().startSize = 1
but VStudio 2017 reports that startSize is obsolete and should be replaced with main.startSize. But when I do that, I get an error:
Cannon modify the return value of ParticleSystem.main because it is not a variable.
So how should I set the start size value?

ParticleSystem.main returns a struct, not a class. Struct's are value types, in that when you move them around their values are copied into a new object. You have to first store the returned value in a variable then modify it.
var main = particleSystem.main;
main.startSize = 1;

Related

How to check if a property was assigned with 'DateTime.Now' with reflection?

I need to compare two complex objects. My idea was to write a function that iterates over all properties of the object and the sub-objects and write a combination of the property name, the data type and the value in a string. The function returns the hash of this string.
So if the function returns the same hash for two objects the objects are equal. The function is fine. The problem is, that some properties are assigned with DateTime.Now.
tProduct.Timestamp = DataTime.Now;
tProduct.CreatedAt = DataTime.Now;
So if I call my function the string that is created slightly differs in those values.
Example:
//both objects are equal
var complexObject1 = Generate();
var complexObject2 = Generate();
var hash1 = GetHash(complexObject1); // uses string **xxx25.11.2021 15:11:51xxx** to hash
var hash2 = GetHash(complexObject2); // uses string **xxx25.11.2021 15:11:56xxx** to hash
I want to ignore those values in my function and I think I need reflection for this. The logic I want to implement is: If a property gets the value via DataTime.Now I will ignore it.
Firstly, the DateTime object is used for getting the current date and time from the computer.
So you don't have the possibility to compare the two values which is getting from the DateTime.Now
But you have the possibility in terms of speaking about the packages. In NuGet, we have numerous package to compare the values.
For eg you can use the ObjectComparer Package to compare the objects.By typing the below command in the Package Manager you can install the ObjectComparer.
Install-Package ObjectsComparer -Version 1.4.1

++i "does not exist in current context" when trying to increase variable in C#

Trying to control a variable in a script from another script in C# however when I reference it and try to get it to increase the value by one, I get the error of "The name i does not exist in current context."
Whole code unit would be
//Update enemy amount
GameObject theManager = GameObject.Find("EnemyManager");
AutomaticDifficultyManager managerScript = theManager.GetComponent<AutomaticDifficultyManager>();
AutomaticDifficultyManager.amountOfEnemies ++i;
This seems like such a simple fix yet for some reason it's not clicking why I can't get it to simply increase the variable by one count.
I assume you want to increase the value stored within amountOfEnemies?
The code for that would be ++managerScript.amountOfEnemies.
There is a difference between the ++ in front of a variable and after it. If you prepend the ++, essentially what happens is, the value gets increased first and is then used. If you postfix the ++, the value as is is used, and increased afterwards.
As an example:
int x = 0;
int newValue = ++x;
// newValue now has the value of 1 and x as well.
int nextTry = x++;
// nextTry is now still at 1 while x is at 2.

How to get Test variable through custom code in HP UFT - ApiTest

I want to set value to the Test Variable using Custom Code.
Can you tell me how to do it as i am not able to access the variable from code.
I need to access the User Variable URL in my custom code and set the value.
Please help me if you know how to do it using Custom Code.
Thanks,
Madhan
Based on your question:
1. Click on File menu and then Settings, it will open Properties pane.
2. Click on "+" to add user variable and give a name.
3. In your custom code, type below code:
string s = "https://www.google.com/";
this.Context.TestProfile.SetVariableValue("NameOfYourVariable",s);
To retrieve the value of given variable:
string ss = this.Context.TestProfile.GetVariableValue("NameOfYourVariable");
CodeActivity5.Report("Variable is : ", ss); //(This line will print your variable value)
answer provided here is valid when the need is to set string values. The "SetVariableValue" method takes two "String" type parameters. This limits the ability to set Int32 type variables. Obviously, C# throws an error when trying to set an integer value.
Now, an integer value is particularly useful while setting values for loop iterations. I am not sure whether this is a limitation of the tool or whether my lack of knowledge. So, to work around this, i used the output property of custom code activity. To do this, create a custom code activity and create an output property of the desired type, say Int. Now, assign a value to this output property using the line:
this.ActivityName.Output.property name = property value
This is available in UFT help and can be useful while trying to pass values other than string between different activities in a flow.

tracing specific variable in visual studio 2010

I want to watch specific variable in visual studio 2010.
For example,
string stringVar = "blablabla";
I want to know when this variable is created? when modified or when assigned something to it.
--
In my application, one of variable value changing abruptly and I can not figure out why and I dont want to debug whole code.
You could convert your variable into a property and set a breakpoint in the setter?
string _stringVar = "blablablba";
string stringVar {
get
{
return _stringVar;
}
set
{
_stringVar = value;
}
}
You could always swap it back after you solve your issue
How about a break point with condition specified to has changed
Choose Has changed if you want to break when the value of the
expression has changed.

Question about reference types

This is taken from Jon Skeet's excellent personal C# site (http://www.yoda.arachsys.com/csharp/):
StringBuilder first = new StringBuilder();
StringBuilder second = first;
first.Append ("hello");
first = null;
Console.WriteLine (second);
1) Changing the value of first will not change the value of second -
2) although while their values are still references to the same object, any changes made to the object through the first variable will be visible through the second variable.
This is taken from the same sentence. What is meant by changing the value? I assume the value of a variable (eg int x = 4, or 5, or 45, etc).
Does this mean if first points to another compatible object, it won't have an effect on two?
Everything on that page makes sense, I think it's just an issue with my interpretation of the English.
Thanks
first is a reference to an object of type StringBuilder. That is, first stores a value that can be used to refer to an object on the heap that is type of Stringuilder. second is another reference to an object of type StringBuilder and its value is initially set refer to the same object that first is referring to.
If you change the value of first what you are doing is changing what the referent is. That is, you are using first to refer to a different object. This does not impact second; its value is unaffected by changes to the value of first. (Remember: the value of first and second are references that initially have the same referent. But just like with
int x = 1;
int y = x;
x = 2;
does not change the value of y, changing the value of first does not change the value of second.
On the other hand, when first and second refer to the same object, any changes to that object will be visible through both first and second.
Think of it like this. Let's say I create a text file first.html whose contents are
Stack Overflow
and I issue the command copy first.html second.html. Then both pages can be used to refer to the same webpage; by following the link we arrive at the same referent. If changes are made to the Stack Overflow home page, then accessing the homepage through either first.html or second.html will allow me to see those changes. But if I then change the contents of first.html to be
<a href="http://www.thedailywtf.com>The Daily WTF</a>
then I can no longer use first.html to refer to the Stack Overflow homepage. Moreover, this change does not impact the value of second.html. It is still
<a href="http://stackoverflow.com>Stack Overflow</a>
Think of the contents of these files as the values of a reference type, and the ultimate desination as the referent object.
The difference between the value of the object itself and the contents of the object are not clear.
For example, it is possible to change the contents of second by calling methods on first, as in the call to Append in the example. However, setting the value of first to null does not set second to null.
You can see this easily by writing this code and stepping through it in a debugger.

Categories