Hi there! You are currently browsing as a guest. Why not create an account? Then you get less ads, can thank creators, post feedback, keep a list of your favourites, and more!
Test Subject
Original Poster
#26 Old 29th Nov 2020 at 5:08 AM
Quote: Originally posted by Lyralei
I think you're correct here Lizcandor! So seconding this!

Because when you're using foreach loops, you need to use the variable you used to define the class  (in your case 'sim') With a foreach loop you can't actually access the public class of what variable you're casting too, because the variable is the only way for the foreach loop to say 'this single sim we're going to add this buff to'. As foreach loops obviously loop through all the sims it can find inside an array or object.

Right now you're basically doing this:

Code:
foreach (int number in numbers) { 
        return  int;
}

So let's assume 'int' is the 'Sim' class here for a second. int is simply a type (or object in the case of the 'Sim' class), and types of course don't hold any information rather than "Hey i'm a number! Not a string or anything else". The 'number' var on the other hand is what *actually* holds the information. It knows which number it is. Therefore we *actually* want to do this instead:

Code:
foreach (int number in numbers) { 
        return  number;
}
Remember as well, the variable is the only thing that can call functions! You can't ever do 'Sim.AddElement();'. It always has to be accessed through a variable. Which can be done through loops as demonstrated above, but also 'Sim sim = new Sim();' where we would use 'sim' as our way to access the functions that the Sim class has for us. Although I'd choose parameters over the whole 'new' stuff in the case of sims. Or, of course, when we use interactions, 'sim' or 'actor' is already defined. Confused yet? :p It's all about instantiating objects, which is something to get used to when you're starting out with C#...

If you're used to javascript, then I know this whole 'defining' the whole 'int' and 'string' and whatever is super weird. It's pretty rare at least that you need to define or check a type of something. And the whole Object stuff just doesn't exist (unless we're talking somewhat more advanced JS stuff) I had to get used to it as well :p 

(Also see: https://www.geeksforgeeks.org/c-sharp-foreach-loop/ )


Basically, I don't have to define it? I would just have to make a class or just instantiate it.
Advertisement
Virtual gardener
staff: administrator
#27 Old 29th Nov 2020 at 12:07 PM
Quote: Originally posted by SimShady19
Basically, I don't have to define it? I would just have to make a class or just instantiate it.
In your case I even think just using 'sim' should do the trick  Especially since the game already got you the entire list of sims for you  or at least, that's what 'getObjects<Sim>() does
Test Subject
Original Poster
#28 Old 9th Dec 2020 at 3:10 AM
Quote: Originally posted by Lyralei
In your case I even think just using 'sim' should do the trick  Especially since the game already got you the entire list of sims for you  or at least, that's what 'getObjects<Sim>() does


Super sorry I took so long, I have been trying to figure what the issue is by looking at other people's mod. Though I just don't know, Should I upload Vs project file so someone could get to the bottom of it? or is that too much to ask of anyone?.
Page 2 of 2
Back to top