Welcome to
Mod The Sims
Online: 1428
News:
Have an account? Sign in:
pass:
If you don't have an account, why not sign up now? It's free!
Other sites: SimsWiki
Reply  Replies: 27 (Who?), Viewed: 1291 times.
Search this Thread
Old 29th Nov 2020, 6:08 AM #26
SimShady19
Original Poster

Test Subject

Join Date: Jun 2020
Posts: 24


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.
Old 29th Nov 2020, 1:07 PM #27
Lyralei
Virtual gardener



Join Date: Dec 2013
Posts: 3,095
Thanks: 3443 in 22 Posts
24 Achievements


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
Old 9th Dec 2020, 4:10 AM #28
SimShady19
Original Poster

Test Subject

Join Date: Jun 2020
Posts: 24


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?.
Reply


Section jump:


Powered by MariaDB Some icons by http://dryicons.com.