Replies: 68 (Who?), Viewed: 1554 times.
Page 1 of 3
Lab Assistant
Original Poster
#1 Old 20th Oct 2020 at 3:07 AM
Default More Problems With Coding - This time, VS errors CS0119 and CS0103
So, anyways, I'm still working on my mod to make canes usable for young adults or higher. Still, I'm trying to get the cane posture to actually appear, but VS keeps giving me errors when I try to create a replacement for the a method that I think is responsible for populating the cane postures. Here's the code for the original method:

Code:
public static void PopCanePostureIfNecessary()
            {
                if (Simulator.CheckYieldingContext(shouldThrowException: false))
                {
                    Cane.HoldingCanePosture holdingCanePosture = Posture as Cane.HoldingCanePosture;
                    if (holdingCanePosture != null && !holdingCanePosture.IsExiting)
                    {
                        PopPosture();
                    }
                }
            }


And here's my edited method:

Code:
public static void PopCanePostureIfNecessary()
            {
                if (Simulator.CheckYieldingContext(shouldThrowException: false))
                {
                    CyrusCane.NewHoldingCanePosture holdingCanePosture = Posture as CyrusCane.NewHoldingCanePosture;
                    if (holdingCanePosture != null && !holdingCanePosture.IsExiting)
                    {
                        PopPosture();
                    }
                }
            }


When trying to write both, I get the same errors:

CS0119 C# "Posture" is a type, which is not valid in the given context

CS0103 C# The name "PopPosture" does not exist in the current context

What could I do to fix these errors?
Here's the complete code, for reference:

Advertisement
Scholar
#2 Old 20th Oct 2020 at 7:18 PM
Maybe the game thinks you are talking about something different when you say posture in the 2nd part? Try to specify more clearly what Posture means by stating what it belongs to.

Like Sims3.....Posture.

If you like my mods. Consider supporting me on Patreon

Follow me on
Twitter
Instagram
Lab Assistant
Original Poster
#3 Old 20th Oct 2020 at 9:06 PM
@PuddingFace ,

When I try to do this, I get the following errors:

CS0120 C# An object reference is required for the non-static field, method, or property "Sim.Posture"

CS0120 C# An object reference is required for the non-static field, method, or property "Sim.PopPosture()"
Scholar
#4 Old 21st Oct 2020 at 8:23 AM
No I meant more like Sims3.Gameplay.ActorSystems.Posture instead of just Posture. Sometimes there are multiple classes, variables, functions with the same name. So you need to specify which one you are talking about.

That's what I feel is the problem in your code.

If you like my mods. Consider supporting me on Patreon

Follow me on
Twitter
Instagram
Lab Assistant
Original Poster
#5 Old 21st Oct 2020 at 7:09 PM
@PuddingFace , that's exactly what I did.

Code:
public static void PopCanePostureIfNecessary()
            {
                if (Simulator.CheckYieldingContext(shouldThrowException: false))
                {
                    CyrusCane.NewHoldingCanePosture holdingCanePosture = Sims3.Gameplay.Actors.Sim.Posture as CyrusCane.NewHoldingCanePosture;
                    if (holdingCanePosture != null && !holdingCanePosture.IsExiting)
                    {
                        Sims3.Gameplay.Actors.Sim.PopPosture();
                    }
                }
            }
Field Researcher
#6 Old 21st Oct 2020 at 8:58 PM Last edited by gamefreak130 : 21st Oct 2020 at 9:15 PM.
When VS says "an object reference is required for non-static field," it means exactly what it says. Static fields, methods, etc. are shared across all instances of a class; for example, Sims3.Gameplay.Actors.Sim.sNumberOfActors represents the number of Sim objects currently in existence, and as such the value is associated with the Sim class itself, rather than any given Sim object.

On the other hand, Posture and PopPosture() are non-static members of Sim. This means that each Sim object has their own posture, and as such you must refer to a specific Sim object's Posture or SetPosture() method.

TL;DR You need to pass in the Sim whose posture you're trying to get, then set, like so:

Code:
public static void PopCanePostureIfNecessary(Sim sim)
{
    if (Simulator.CheckYieldingContext(shouldThrowException: false))
    {
        CyrusCane.NewHoldingCanePosture holdingCanePosture = sim?.Posture as CyrusCane.NewHoldingCanePosture;
        if (holdingCanePosture != null && !holdingCanePosture.IsExiting)
        {
            sim.PopPosture();
        }
    }
}

"The Internet is the first thing that humanity has built that humanity doesn't understand, the largest experiment in anarchy that we have ever had." - Eric Schmidt

If you enjoy the mods I put out, consider supporting me on patreon: www.patreon.com/Gamefreak130
Scholar
#7 Old 21st Oct 2020 at 11:00 PM Last edited by PuddingFace : 23rd Oct 2020 at 4:30 PM.
Yea what Gamefreak said. I thought there was some other problem because the error in the first was different. And I had a similar problem so replied accordingly.

When a class has static members
Code:
Class Example{

Static int a=6;

int b=3;
}

Class Example2{
Example.a=4; // is correct

Example.b=2; // error.

Example objectexample= new Example();

objectexample.b=2// is correct

objectexample.a=1// error.

If you like my mods. Consider supporting me on Patreon

Follow me on
Twitter
Instagram
Lab Assistant
Original Poster
#8 Old 25th Oct 2020 at 8:54 PM
@gamefreak130 and @PuddingFace

I still can't do it, trying to specify the object as a Actor, or even a Sim, as gamefreak did. What I'm doing wrong? I put the object before the non-static field specified, like in the example.
Scholar
#9 Old 25th Oct 2020 at 10:20 PM
What error are you getting now?

If you like my mods. Consider supporting me on Patreon

Follow me on
Twitter
Instagram
Lab Assistant
Original Poster
#10 Old 26th Oct 2020 at 11:49 PM
@PuddingFace ,

Nevermind, I've changed the approach to substituing the interactions, and it seems to have worked to solve this problem. But it I still can't get the code to make both the posture and the walkstyles from the canes to appear. Here's the new code:



In a nutshell, I preserved the original object and used a Instantiator class (not seem in this part of the code, because it is in another class) to replace the interactions with my versions. I really don't know what exactly is going wrong - By what I know, it SHOULD be working.
Scholar
#11 Old 28th Oct 2020 at 2:21 PM
@CyrusBanefort So what's happening in the game? Is there any change from the default behavior. Any error message from Nraas error trap? Is there no change at all?

If you like my mods. Consider supporting me on Patreon

Follow me on
Twitter
Instagram
Lab Assistant
Original Poster
#12 Old 28th Oct 2020 at 6:08 PM
Quote:
Originally Posted by PuddingFace
@CyrusBanefort So what's happening in the game? Is there any change from the default behavior. Any error message from Nraas error trap? Is there no change at all?


@Battery

Basically, the thing that happens is that the cane appears in the sim's hand, but it does not play any of the animations, and when I try to make the sim stop using the cane, the prop cane doesn't disappear.
Scholar
#13 Old 29th Oct 2020 at 2:02 PM
So the Sim just walks normally? and when they're done walking the cane just gets stuck in their hand?

If you like my mods. Consider supporting me on Patreon

Follow me on
Twitter
Instagram
Lab Assistant
Original Poster
#14 Old 29th Oct 2020 at 5:49 PM
Quote:
Originally Posted by PuddingFace
So the Sim just walks normally? and when they're done walking the cane just gets stuck in their hand?


@PuddingFace

Exactly.
Field Researcher
#15 Old 29th Oct 2020 at 8:23 PM
Hmm i would suggest creating an new interaction and testing each part of the functionality you need an if every single part works on its own put it all together.

So you might want to start with an interaction that changes just the walkstyle and then the posture and so on
Lab Assistant
Original Poster
#16 Old 29th Oct 2020 at 8:42 PM
@Battery ,

And how could I do this?
Scholar
#17 Old 29th Oct 2020 at 8:51 PM
This is how I was requesting different walk/run styles in my mods.
Code:
Sim actor=new Sim();
actor.RequestWalkStyle(WalkStyle.VampireRun);
 
//Maybe you can try
actor.RequestWalkStyle(WalkStyle.ElderCaneWalk);

or
actor.RequestWalkStyle(WalkStyle.ElderCaneRun);



If you like my mods. Consider supporting me on Patreon

Follow me on
Twitter
Instagram
Field Researcher
#18 Old 29th Oct 2020 at 8:56 PM
Quote:
Originally Posted by CyrusBanefort
@Battery ,

And how could I do this?


PuddingFace has a good code snippet to try you can use it in conjunction with an immediate interaction you can read about this in this Tutorial
Lab Assistant
Original Poster
#19 Old 29th Oct 2020 at 11:33 PM
@Battery and @PuddingFace

I don't know if trying that is the good way to maje the mod work. If I make a "Frankenstein" of code, I will not manage to have the cane code to function exactly as the original cane. Any chance that this is happening because I'm using the unprotected dlls?

EDIT: Also, why do I get errors when trying to simply put the code of the cane in Visual Studio?
Scholar
#20 Old 29th Oct 2020 at 11:59 PM
Unprotected DLLs make some things that are private public but also some other things that were public before became private. If you were trying to use something that was privated in the unprotected DLLs then you will get errors.

If you like my mods. Consider supporting me on Patreon

Follow me on
Twitter
Instagram
Lab Assistant
Original Poster
#21 Old 30th Oct 2020 at 12:36 AM
I'm not getting errors with my code, to be exact. That thing about getting errors is when I try to simply plop down the complete code of the cane in VS and make the necessary edits.
Virtual gardener
staff: administrator
#22 Old 30th Oct 2020 at 1:58 PM
Quote:
Originally Posted by CyrusBanefort
I'm not getting errors with my code, to be exact. That thing about getting errors is when I try to simply plop down the complete code of the cane in VS and make the necessary edits.
So it's the game that returns the errors? Would you be able to share an image of that if that's the game?  That way it's easier to figure out if maybe it's just a null reference or whatever
Lab Assistant
Original Poster
#23 Old 30th Oct 2020 at 4:14 PM Last edited by CyrusBanefort : 30th Oct 2020 at 9:40 PM.
Quote:
Originally Posted by Lyralei
So it's the game that returns the errors? Would you be able to share an image of that if that's the game?  That way it's easier to figure out if maybe it's just a null reference or whatever


@Lyralei ,

No, not the game. The errors come from Visual Studio - I just find it strange because it is the exactly same code as the original one. Again, it's not the code I posted earlier that gives me errors, but the original cane code.

EDIT: Here are the errors that SharpDevelop gives me when I try to throw the cane code into it, not Visual Studio, as Battery requested. (It's in portuguese, as I don't know how to change the language of the errors window of SD, but I think a quick trip to Google Translate can solve things)

Screenshots
Field Researcher
#24 Old 30th Oct 2020 at 9:52 PM
^^ Well i did not request it in SD but it seems youre missing some "end of Instruction" ;

also it looks your scope seems a bit of did you make sure you set your { and } right ?

As for the "frankensteined code" while you disagree there i am still of the opinion that testing each step one by one might be your best chance instead of trying to fix the whole code at once.

if you get a lot of errors could you upload the Solution aswell this (at least for me) makes it easier to fix pure coding errors and reupload it
Lab Assistant
Original Poster
#25 Old 30th Oct 2020 at 10:12 PM
@Battery ,

I can try to do what you recommended. Let's see what comes from it.
Anyways, the code that is in that print is just the one from the cane. The original one, from the game dlls. I tried to used Jetbrains Rider as an alternate IDE to VS, to see if that was the problem, and got the following errors:



Again, that's the code from the original cane.
Screenshots
Page 1 of 3
Back to top