- Home /
Edit each Parameter Class on Function
Hey, I am trying to make it so that 1 is added to "Row" each time the function "ConvertParamsToClass" is called, but I don't know how to do that. Can someone help me?
//Variables:
public List<KillFeedInfo> KFI = new List<KillFeedInfo>();
private void ConvertParamsToClass(string Killer, string Gun, string Killed)
{
int Row = 0;
Debug.Log ("Converting Params To Class");
KillFeedInfo k = new KillFeedInfo(Killer, Gun, Killed, Row);
KFI.Add(k);
foreach (KillFeedInfo k in KFI)
{
k.Row ++;
}
Debug.Log ("Added k");
}
}
[System.Serializable]
public class KillFeedInfo
{
public int Row;
public string Killer;
public string Gun;
public string Killed;
public KillFeedInfo(string K, string G, string V, int R)
{
Killer = K;
Gun = G;
Killed = V;
Row = R;
}
}
Answer by meat5000 · Oct 20, 2013 at 02:00 PM
Create your function inside your class. It should then be able to access the variable and you won't need to declare it again within the function.
Alternatively, change it from void function and add a return statement. Maybe return 1 and add that each time.
Could you show an example? Because I am not really sure how to make a function in a class...I tried this but it doesnt work apparently.
public AddRow()
{
Row ++;
}
Class
{
class variables //class wide scope
function
{
function variables //only has scope within function
//can access class variables here
}
another function
{
function variables //can't access variables of first function
//can access class variables here
}
}
How would this be applied in this example? Also: functions in this case are supposed to be voids...? Because I am using C#
Its just pseudocode to show you how to structure your class and functions.
Basically, the structure I show you is the simplest way to share variables between functions allowing you to modify them without having to pass any arguments at all.
Yes, I tried applying it but for some reason it doesn't work. I have no idea how to add the function from this example, maybe I could if you would show me some context.
Your answer
![](https://koobas.hobune.stream/wayback/20220613120304im_/https://answers.unity.com/themes/thub/images/avi.jpg)