Welcome to
Mod The Sims
Online: 1439
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: 68 (Who?), Viewed: 1736 times.
Search this Thread
Old 20th Oct 2020, 3:07 AM DefaultMore Problems With Coding - This time, VS errors CS0119 and CS0103 #1
CyrusBanefort
Original Poster

Lab Assistant

Join Date: Jun 2017
Posts: 130
Thanks: 116 in 2 Posts
4 Achievements


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:

Old 20th Oct 2020, 7:18 PM #2
PuddingFace
Scholar

Join Date: Aug 2014
Posts: 1,065
Thanks: 1565 in 30 Posts
9 Achievements


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
Old 20th Oct 2020, 9:06 PM #3
CyrusBanefort
Original Poster

Lab Assistant

Join Date: Jun 2017
Posts: 130
Thanks: 116 in 2 Posts
4 Achievements


@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()"
Old 21st Oct 2020, 8:23 AM #4
PuddingFace
Scholar

Join Date: Aug 2014
Posts: 1,065
Thanks: 1565 in 30 Posts
9 Achievements


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
Old 21st Oct 2020, 7:09 PM #5
CyrusBanefort
Original Poster

Lab Assistant

Join Date: Jun 2017
Posts: 130
Thanks: 116 in 2 Posts
4 Achievements


@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();
                    }
                }
            }
Old 21st Oct 2020, 8:58 PM #6
gamefreak130
Field Researcher

Join Date: Apr 2013
Posts: 269
Thanks: 2645 in 18 Posts
17 Achievements


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
Last edited by gamefreak130 : 21st Oct 2020 at 9:15 PM.
Old 21st Oct 2020, 11:00 PM #7
PuddingFace
Scholar

Join Date: Aug 2014
Posts: 1,065
Thanks: 1565 in 30 Posts
9 Achievements


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
Last edited by PuddingFace : 23rd Oct 2020 at 4:30 PM.
Old 25th Oct 2020, 8:54 PM #8
CyrusBanefort
Original Poster

Lab Assistant

Join Date: Jun 2017
Posts: 130
Thanks: 116 in 2 Posts
4 Achievements


@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.
Old 25th Oct 2020, 10:20 PM #9
PuddingFace
Scholar

Join Date: Aug 2014
Posts: 1,065
Thanks: 1565 in 30 Posts
9 Achievements


What error are you getting now?

If you like my mods. Consider supporting me on Patreon

Follow me on
Twitter
Instagram
Old 26th Oct 2020, 11:49 PM #10
CyrusBanefort
Original Poster

Lab Assistant

Join Date: Jun 2017
Posts: 130
Thanks: 116 in 2 Posts
4 Achievements


@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.
Old 28th Oct 2020, 2:21 PM #11
PuddingFace
Scholar

Join Date: Aug 2014
Posts: 1,065
Thanks: 1565 in 30 Posts
9 Achievements


@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
Old 28th Oct 2020, 6:08 PM #12
CyrusBanefort
Original Poster

Lab Assistant

Join Date: Jun 2017
Posts: 130
Thanks: 116 in 2 Posts
4 Achievements


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.
Old 29th Oct 2020, 2:02 PM #13
PuddingFace
Scholar

Join Date: Aug 2014
Posts: 1,065
Thanks: 1565 in 30 Posts
9 Achievements


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
Old 29th Oct 2020, 5:49 PM #14
CyrusBanefort
Original Poster

Lab Assistant

Join Date: Jun 2017
Posts: 130
Thanks: 116 in 2 Posts
4 Achievements


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.
Old 29th Oct 2020, 8:23 PM #15
Battery
Field Researcher

Join Date: Dec 2008
Posts: 385
Thanks: 827 in 5 Posts
8 Achievements


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
Old 29th Oct 2020, 8:42 PM #16
CyrusBanefort
Original Poster

Lab Assistant

Join Date: Jun 2017
Posts: 130
Thanks: 116 in 2 Posts
4 Achievements


@Battery ,

And how could I do this?
Old 29th Oct 2020, 8:51 PM #17
PuddingFace
Scholar

Join Date: Aug 2014
Posts: 1,065
Thanks: 1565 in 30 Posts
9 Achievements


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
Old 29th Oct 2020, 8:56 PM #18
Battery
Field Researcher

Join Date: Dec 2008
Posts: 385
Thanks: 827 in 5 Posts
8 Achievements


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
Old 29th Oct 2020, 11:33 PM #19
CyrusBanefort
Original Poster

Lab Assistant

Join Date: Jun 2017
Posts: 130
Thanks: 116 in 2 Posts
4 Achievements


@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?
Old 29th Oct 2020, 11:59 PM #20
PuddingFace
Scholar

Join Date: Aug 2014
Posts: 1,065
Thanks: 1565 in 30 Posts
9 Achievements


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
Old 30th Oct 2020, 12:36 AM #21
CyrusBanefort
Original Poster

Lab Assistant

Join Date: Jun 2017
Posts: 130
Thanks: 116 in 2 Posts
4 Achievements


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.
Old 30th Oct 2020, 1:58 PM #22
Lyralei
Virtual gardener



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


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
Old 30th Oct 2020, 4:14 PM #23
CyrusBanefort
Original Poster

Lab Assistant

Join Date: Jun 2017
Posts: 130
Thanks: 116 in 2 Posts
4 Achievements


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
Click image for larger version

Name:  thing.png
Views: 0
Size:  137.4 KB  
Last edited by CyrusBanefort : 30th Oct 2020 at 9:40 PM.
Old 30th Oct 2020, 9:52 PM #24
Battery
Field Researcher

Join Date: Dec 2008
Posts: 385
Thanks: 827 in 5 Posts
8 Achievements


^^ 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
Old 30th Oct 2020, 10:12 PM #25
CyrusBanefort
Original Poster

Lab Assistant

Join Date: Jun 2017
Posts: 130
Thanks: 116 in 2 Posts
4 Achievements


@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
Click image for larger version

Name:  thing2.png
Views: 0
Size:  19.6 KB  
Reply


Section jump:


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