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
#1 Old 24th Jun 2020 at 11:07 PM
Default I really need help with making interactions!!!
Hey guys, So I am really stuck right now. I need help with interactions, when I try to create an interaction with pure script modding; I always get errors. I have followed many tutorials and it hasn't worked yet; so I would be glad if someone were to help me with this.
Advertisement
Space Pony
#2 Old 25th Jun 2020 at 5:09 AM
Quote: Originally posted by SimShady19
Hey guys, So I am really stuck right now. I need help with interactions, when I try to create an interaction with pure script modding; I always get errors. I have followed many tutorials and it hasn't worked yet; so I would be glad if someone were to help me with this.


We're happy to help, but you're going to need to give a bit more detail.

What are the errors you're getting, and what is the code that you think is causing those errors?

"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
Test Subject
Original Poster
#3 Old 26th Jun 2020 at 10:11 PM
Quote: Originally posted by gamefreak130
We're happy to help, but you're going to need to give a bit more detail.

What are the errors you're getting, and what is the code that you think is causing those errors?


Thank you so much for responding!, The issue is when I put what I wanted my Interaction to be named it sends and an error. I do not know what exactly I am doing wrong but I will show you.


using System;
using System.Collections.Generic;
using System.Text;
using Sims3.Gameplay;
using Sims3.Gameplay.Actors;
using Sims3.Gameplay.Autonomy;
using Sims3.Gameplay.EventSystem;
using Sims3.Gameplay.Interactions;
using Sims3.Gameplay.Utilities;
using Sims3.SimIFace;
using Sims3.UI;

namespace SimShady19.Royalgreeting.Common //Use your own unique namespace here
{
public class DemoClass
{
[Tunable]
protected static bool kInstantiator = false;
private static EventListener sSimInstantiatedListener = null;
//private static EventListener sSimAgedUpListener = null; //Optional age transition listener

static DemoClass()
{
World.OnWorldLoadFinishedEventHandler += new EventHandler(OnWorldLoadFinishedHandler);
}

public static void OnWorldLoadFinishedHandler(object sender, System.EventArgs e)
{
try
{
foreach (Sim sim in Sims3.Gameplay.Queries.GetObjects<Sim>())
{
if (sim != null)
{
AddInteractions(sim);
}
}
}
catch (Exception exception)
{
Exception(exception);
}
sSimInstantiatedListener = EventTracker.AddListener(EventTypeId.kSimInstantiated, new ProcessEventDelegate(OnSimInstantiated));
//sSimAgedUpListener = EventTracker.AddListener(EventTypeId.kSimAgeTransition, new ProcessEventDelegate(OnSimInstantiated));
}

protected static ListenerAction OnSimInstantiated(Event e)
{
try
{
Sim sim = e.TargetObject as Sim;
if (sim != null)
{
AddInteractions(sim);
}
}
catch (Exception exception)
{
Exception(exception);
}
return ListenerAction.Keep;
}

public static void AddInteractions(Sim sim)
{
//if (sim.SimDescription.TeenOrAbove) //Optional conditions for adding interaction
//{
foreach (InteractionObjectPair pair in sim.Interactions)
{
if (pair.InteractionDefinition.GetType() == Royalgreeting.Singleton.GetType())
{
return;
}
}
sim.AddInteraction(Royalgreeting.Singleton);
//}
}

public static bool Exception(Exception exception)
{
try
{
return ((IScriptErrorWindow)AppDomain.CurrentDomain.GetData("ScriptErrorWindow")).DisplayScriptError(null, exception);
}
catch
{
WriteLog(exception);
return true;
}
}
public static bool WriteLog(Exception exception)
{
try
{
new ScriptError(null, exception, 0).WriteMiniScriptError();
return true;
}
catch
{
return false;
}
}

private sealed class ShowNotification : ImmediateInteraction<Sim, Sim>
{
public static readonly InteractionDefinition Singleton = new Definition();
protected override bool Run()
{
base.Actor.ShowTNSIfSelectable("Royal greeting", StyledNotification.NotificationStyle.kSimTalking);
return true;
StyledNotification.Show(new StyledNotification.Format(base.Actor.Name + " has clicked on " + base.Target.Name,
StyledNotification.NotificationStyle.kGameMessagePositive));
return true;
}
[DoesntRequireTuning]
private sealed class Definition : ImmediateInteractionDefinition<Sim, Sim, ShowNotification>
{
protected override string GetInteractionName(Sim actor, Sim target, InteractionObjectPair interaction)
{
return "Royal greeting";
}
protected override bool Test(Sim actor, Sim target, bool isAutonomous, ref GreyedOutTooltipCallback greyedOutTooltipCallback)
{
return true;
//return (actor.SimDescription.Age == target.SimDescription.Age); //Optional test for visibility of interaction
return true; //comment out or delete if using test
}
//public override string[] GetPath(bool bPath) //Optional path for interaction
//{
// return new string[] { "MyStuff Options..." };
//}
}
}
}
}
Senior Moderator
staff: senior moderator
#4 Old 26th Jun 2020 at 11:26 PM
Hey there,
I think what the problem is, is that you are trying to add an interaction called Royalgreeting, but the name of your interaction (the name of the class) is called ShowNotification.
You're going to want to change that to Royalgreeting (or RoyalGreeting if you want it to be neater, but don't forget to add the capital G when you do the AddInteraction).
You will also have to change the name of the interaction in the InteractionDefinition where it says:
Code:
private sealed class Definition : ImmediateInteractionDefinition<Sim, Sim, ShowNotification> 

You will need to change it to:
Code:
private sealed class Definition : ImmediateInteractionDefinition<Sim, Sim, RoyalGreeting> 

The GetInteractionName() function is just for the string that appears in game when you click on the object/sim. Whereas the name of the interaction's class is what the code recognises when you want to do AddInteraction(SomeInteraction.singleton)
I know your code is just in the early stages for testing, but I just want to point out in your Run() function, you have a ShowNotification method after "return true" which won't show up, so you want to delete that first return true; command to have everything execute.

Finally, when posting code here, it's helpful to use the [ code] [ /code] tags (but without spaces :p) to make it easier to read, as you can see in this post, and figure out the problem.
Hope this helps!
Test Subject
Original Poster
#5 Old 28th Jun 2020 at 7:12 AM
Quote: Originally posted by zoe22
Hey there,
I think what the problem is, is that you are trying to add an interaction called Royalgreeting, but the name of your interaction (the name of the class) is called ShowNotification.
You're going to want to change that to Royalgreeting (or RoyalGreeting if you want it to be neater, but don't forget to add the capital G when you do the AddInteraction).
You will also have to change the name of the interaction in the InteractionDefinition where it says:
Code:
private sealed class Definition : ImmediateInteractionDefinition<Sim, Sim, ShowNotification> 

You will need to change it to:
Code:
private sealed class Definition : ImmediateInteractionDefinition<Sim, Sim, RoyalGreeting> 

The GetInteractionName() function is just for the string that appears in game when you click on the object/sim. Whereas the name of the interaction's class is what the code recognises when you want to do AddInteraction(SomeInteraction.singleton)
I know your code is just in the early stages for testing, but I just want to point out in your Run() function, you have a ShowNotification method after "return true" which won't show up, so you want to delete that first return true; command to have everything execute.

Finally, when posting code here, it's helpful to use the [ code] [ /code] tags (but without spaces :p) to make it easier to read, as you can see in this post, and figure out the problem.
Hope this helps!


Thank you! it actually helped,but can anyone help me because;my interaction is not showing up in game.
Virtual gardener
staff: administrator
#6 Old 28th Jun 2020 at 9:43 AM Last edited by Lyralei : 28th Jun 2020 at 9:55 AM.
[Tunable]
protected static bool kInstantiator = false;Have you done the Instantiator XML thingy? It's described right here:

https://modthesims.info/wiki.php?ti...ripting_Modding
(See Writing The XML File and the Building The Package)

If you're sure that works, then there's always "printing" the heck out of the code :p So this is what I usually do, I make a function like:

Code:
         public static void print(string text)
        {
            SimpleMessageDialog.Show("Lyralei's Sewing Table:", text);
        } 
And then in your Run() function and even in the AddInteractions() and OnSimInstantiated() functions, you just add something like:
Code:
print("Debug text here!"); 
Make sure it's all different 'print texts' because else you have a super hard time figuring out at which line it's crashing. So you could even go as far as "Line: 2" and then the next print being "Line: 3". Debugging is your friend in need! 
Test Subject
Original Poster
#7 Old 1st Jul 2020 at 1:06 AM
Quote: Originally posted by Lyralei
[Tunable]
protected static bool kInstantiator = false;Have you done the Instantiator XML thingy? It's described right here:

https://modthesims.info/wiki.php?ti...ripting_Modding
(See Writing The XML File and the Building The Package)

If you're sure that works, then there's always "printing" the heck out of the code :p So this is what I usually do, I make a function like:

Code:
         public static void print(string text)
        {
            SimpleMessageDialog.Show("Lyralei's Sewing Table:", text);
        } 
And then in your Run() function and even in the AddInteractions() and OnSimInstantiated() functions, you just add something like:
Code:
print("Debug text here!"); 
Make sure it's all different 'print texts' because else you have a super hard time figuring out at which line it's crashing. So you could even go as far as "Line: 2" and then the next print being "Line: 3". Debugging is your friend in need! 

Thanks I hope this works ,But I think my Xml file is the issue. I do not know how to fully write one.
Virtual gardener
staff: administrator
#8 Old 1st Jul 2020 at 9:36 AM
Have you checked out this tutorial? (See "witing the XML" and "Building the package" : https://www.modthesims.info/wiki.ph...ripting_Modding  )

This bit is extra important for you:

Quote:
Open a text editor and paste the following:

Code:
<?xml version="1.0" encoding="utf-8"?>
<base>
  <Current_Tuning>
    <kInstantiator value="True" />
  </Current_Tuning>
</base>


Of course you have noticed the kInstantiator variable from the code. Save the file. You can close the text editor now as you won't need it again.
And:

Quote:
Now on to the tuning XML (in your package):
  • Click on Resource -> Add... once more
  • Choose _XML 0x0333406C for Type.
  • Enter 0 for the Group.
  • Here the Instance value is important, so get the Name right. It must be the namespace plus class name of the class where the tunable variable is located. In the case of this tutorial that's TwoBTech.Pausinator.
  • With the _XML resource selected, choose Resource->Import->From file... and this time import the XML text file you created. S3PE will show the content of the XML resource in its preview window. Make sure that the content begins with an angle bracket and not with some unintelligible characters. That is a common error.
Test Subject
Original Poster
#9 Old 3rd Jul 2020 at 8:11 PM
Quote: Originally posted by Lyralei
Have you checked out this tutorial? (See "witing the XML" and "Building the package" : https://www.modthesims.info/wiki.ph...ripting_Modding  )

This bit is extra important for you:

And:

I really do not know if I did it correctly. If someone knows please correct me.
Screenshots
Virtual gardener
staff: administrator
#10 Old 4th Jul 2020 at 7:16 PM
Quote: Originally posted by SimShady19
I really do not know if I did it correctly. If someone knows please correct me.
Hi there!

That should do the trick!
Test Subject
Original Poster
#11 Old 9th Jul 2020 at 3:47 AM
Quote: Originally posted by Lyralei
Hi there!

That should do the trick!

the interaction does not show up when I press on a sim, or maybe i'm doing it the wrong way.
Virtual gardener
staff: administrator
#12 Old 9th Jul 2020 at 9:09 AM
Quote: Originally posted by SimShady19
the interaction does not show up when I press on a sim, or maybe i'm doing it the wrong way.
Then it sounds like an issue with the code. The thing I've learned when starting out is that The sims 3 (probably since we're developing on a released build) doesn't actually say what's wrong with the code. it just... ignores it if it's throwing errors, etc. So for that, I usually get Nraas ErrorTrap, which is a script modder's tool made in heaven :p

Would you be able to post the package here? From there it's a bit easier to read the code and see if the linkage with Instantiator went well
Test Subject
Original Poster
#13 Old 10th Jul 2020 at 7:39 PM
Quote: Originally posted by Lyralei
Then it sounds like an issue with the code. The thing I've learned when starting out is that The sims 3 (probably since we're developing on a released build) doesn't actually say what's wrong with the code. it just... ignores it if it's throwing errors, etc. So for that, I usually get Nraas ErrorTrap, which is a script modder's tool made in heaven :p

Would you be able to post the package here? From there it's a bit easier to read the code and see if the linkage with Instantiator went well

Well maybe you can find out what is the issue with the file,it would help a lot.
Attached files:
File Type: rar  SimShady19_Royalgreeting.rar (3.8 KB, 5 downloads)
Virtual gardener
staff: administrator
#14 Old 12th Jul 2020 at 11:43 AM
Oh you know! I totally forgot about this myself, but you're missing a really crucial thing I think. 

In the 'assemblyInfo' (under properties, should be in the same list where you also add the references). You need to add the following:

Code:
using Sims3.SimIFace; 
And:

Code:
 [assembly: Tunable] 
The assembly: Tunable is super important here. Else the code will be seen as 'non tunable', so the game simply ignores the code.
Test Subject
Original Poster
#15 Old 16th Jul 2020 at 9:26 PM
Quote: Originally posted by Lyralei
Oh you know! I totally forgot about this myself, but you're missing a really crucial thing I think. 

In the 'assemblyInfo' (under properties, should be in the same list where you also add the references). You need to add the following:

Code:
using Sims3.SimIFace; 
And:

Code:
 [assembly: Tunable] 
The assembly: Tunable is super important here. Else the code will be seen as 'non tunable', so the game simply ignores the code.


I have implemented those things in but something is wrong because the pie menu just wont show up i'm just lost at this point.
Space Pony
#16 Old 16th Jul 2020 at 10:57 PM Last edited by gamefreak130 : 17th Jul 2020 at 12:25 AM.
Quote: Originally posted by SimShady19
I have implemented those things in but something is wrong because the pie menu just wont show up i'm just lost at this point.


The name of the XML resource in your package must be "[namespace].[class]" Where namespace and class are the location of your tunable instantiator.

In this case, your tuning variable is SimShady19.Royalgreeting.Common.DemoClass.kInstantiator, so your corresponding XML must therefore be named "SimShady19.Royalgreeting.Common.DemoClass". Change the name (and re-hash the instance value) accordingly, and your interaction should be injected properly.

As an aside, I have a couple of notes regarding the code itself:
  1. Your sSimInstantiatedListener member is unnecessary. Simply stating EventTracker.AddListener() is enough to create the listener, and it will be safely dumped upon exiting to the main menu or quitting the game. The only reason you would need to store the resulting EventListener somewhere is if you needed to stop it while still in-game.
  2. I see an empty internal class named "Singleton" in your assembly that can be safely removed.

None of these will prevent the interaction from running, nor is your code bad because of them. I just think style and readability is important

"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
Test Subject
Original Poster
#17 Old 22nd Jul 2020 at 8:44 PM
Quote: Originally posted by gamefreak130
The name of the XML resource in your package must be "[namespace].[class]" Where namespace and class are the location of your tunable instantiator.

In this case, your tuning variable is SimShady19.Royalgreeting.Common.DemoClass.kInstantiator, so your corresponding XML must therefore be named "SimShady19.Royalgreeting.Common.DemoClass". Change the name (and re-hash the instance value) accordingly, and your interaction should be injected properly.

As an aside, I have a couple of notes regarding the code itself:
  1. Your sSimInstantiatedListener member is unnecessary. Simply stating EventTracker.AddListener() is enough to create the listener, and it will be safely dumped upon exiting to the main menu or quitting the game. The only reason you would need to store the resulting EventListener somewhere is if you needed to stop it while still in-game.
  2. I see an empty internal class named "Singleton" in your assembly that can be safely removed.

None of these will prevent the interaction from running, nor is your code bad because of them. I just think style and readability is important

After days of trying to figure out what can I do, I have been trying to make a interaction with the pie but the tutorials are really confusing. Maybe I need an example to look at and probably i'll just understand it.
Senior Moderator
staff: senior moderator
#18 Old 23rd Jul 2020 at 1:48 PM
Once you fixed the  xml name, did the interaction show up at all?
Virtual gardener
staff: administrator
#19 Old 23rd Jul 2020 at 2:35 PM
Quote: Originally posted by SimShady19
After days of trying to figure out what can I do, I have been trying to make a interaction with the pie but the tutorials are really confusing. Maybe I need an example to look at and probably i'll just understand it.
I take it it's for a sim right? 

So when I was trying to figure out why the code didn't work a while ago, I made my own C# project. I've included all the explanation right in there, so do make sure to check the comments inside the .cs code  I've also tested it in game, but do make sure to really learn from it. Coding can be hard, especially when you start out, so I hope I've explained it well without it sounding like a foreign language, like some of these C# tutorials are like :p

Just download the ZIP, include it in the same folder where all your other C# projects are (No idea which program you're using, so sorry for the vagueness!) and just read through it  I simplified it as well, so that should really help compared to the bigger code that Cmar provided in her tutorial, so it feels less advanced. 
Attached files:
File Type: zip  SimShadyProject.zip (20.6 KB, 5 downloads)
Test Subject
Original Poster
#20 Old 25th Jul 2020 at 8:09 PM
Quote: Originally posted by Lyralei
I take it it's for a sim right? 

So when I was trying to figure out why the code didn't work a while ago, I made my own C# project. I've included all the explanation right in there, so do make sure to check the comments inside the .cs code  I've also tested it in game, but do make sure to really learn from it. Coding can be hard, especially when you start out, so I hope I've explained it well without it sounding like a foreign language, like some of these C# tutorials are like :p

Just download the ZIP, include it in the same folder where all your other C# projects are (No idea which program you're using, so sorry for the vagueness!) and just read through it  I simplified it as well, so that should really help compared to the bigger code that Cmar provided in her tutorial, so it feels less advanced. 

Thank you so much for your help I actually understood what was going on; But may I ask when you put the interaction in game where did it show up in interactions. Because I put it in and I wasn't sure where exactly it was.
Back to top